summaryrefslogtreecommitdiff
path: root/src/libsystemd-network/sd-dhcp-server.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-08-14 01:26:55 +0200
committerTom Gundersen <teg@jklm.no>2014-08-14 01:29:51 +0200
commita6f1e036de8f212f33ead7f5387c297afd8be26e (patch)
tree3bc68f88ed6e57749a1aa710222e15a664d71ec7 /src/libsystemd-network/sd-dhcp-server.c
parent212bbb1798e5746a669dfba4a1732a4eabe4f2d8 (diff)
sd-dhcp-server: linebreaks
Don't overflow unnecessarily.
Diffstat (limited to 'src/libsystemd-network/sd-dhcp-server.c')
-rw-r--r--src/libsystemd-network/sd-dhcp-server.c73
1 files changed, 47 insertions, 26 deletions
diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c
index c224aa1512..ab683228b4 100644
--- a/src/libsystemd-network/sd-dhcp-server.c
+++ b/src/libsystemd-network/sd-dhcp-server.c
@@ -31,7 +31,8 @@
#define DHCP_DEFAULT_LEASE_TIME 3600 /* one hour */
-int sd_dhcp_server_set_lease_pool(sd_dhcp_server *server, struct in_addr *address,
+int sd_dhcp_server_set_lease_pool(sd_dhcp_server *server,
+ struct in_addr *address,
size_t size) {
assert_return(server, -EINVAL);
assert_return(address, -EINVAL);
@@ -51,7 +52,8 @@ int sd_dhcp_server_set_lease_pool(sd_dhcp_server *server, struct in_addr *addres
return 0;
}
-int sd_dhcp_server_set_address(sd_dhcp_server *server, struct in_addr *address, unsigned char prefixlen) {
+int sd_dhcp_server_set_address(sd_dhcp_server *server, struct in_addr *address,
+ unsigned char prefixlen) {
assert_return(server, -EINVAL);
assert_return(address, -EINVAL);
assert_return(address->s_addr, -EINVAL);
@@ -78,7 +80,8 @@ sd_dhcp_server *sd_dhcp_server_ref(sd_dhcp_server *server) {
return server;
}
-unsigned long client_id_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]) {
+unsigned long client_id_hash_func(const void *p,
+ const uint8_t hash_key[HASH_KEY_SIZE]) {
uint64_t u;
const DHCPClientId *id = p;
@@ -155,7 +158,8 @@ int sd_dhcp_server_new(sd_dhcp_server **ret, int ifindex) {
server->address = htobe32(INADDR_ANY);
server->netmask = htobe32(INADDR_ANY);
server->index = ifindex;
- server->leases_by_client_id = hashmap_new(client_id_hash_func, client_id_compare_func);
+ server->leases_by_client_id = hashmap_new(client_id_hash_func,
+ client_id_compare_func);
*ret = server;
server = NULL;
@@ -163,7 +167,8 @@ int sd_dhcp_server_new(sd_dhcp_server **ret, int ifindex) {
return 0;
}
-int sd_dhcp_server_attach_event(sd_dhcp_server *server, sd_event *event, int priority) {
+int sd_dhcp_server_attach_event(sd_dhcp_server *server, sd_event *event,
+ int priority) {
int r;
assert_return(server, -EINVAL);
@@ -210,8 +215,8 @@ int sd_dhcp_server_stop(sd_dhcp_server *server) {
return 0;
}
-static int dhcp_server_send_unicast_raw(sd_dhcp_server *server, DHCPPacket *packet,
- size_t len) {
+static int dhcp_server_send_unicast_raw(sd_dhcp_server *server,
+ DHCPPacket *packet, size_t len) {
union sockaddr_union link = {
.ll.sll_family = AF_PACKET,
.ll.sll_protocol = htons(ETH_P_IP),
@@ -229,7 +234,8 @@ static int dhcp_server_send_unicast_raw(sd_dhcp_server *server, DHCPPacket *pack
memcpy(&link.ll.sll_addr, &packet->dhcp.chaddr, ETH_ALEN);
dhcp_packet_append_ip_headers(packet, server->address, DHCP_PORT_SERVER,
- packet->dhcp.yiaddr, DHCP_PORT_CLIENT, len);
+ packet->dhcp.yiaddr,
+ DHCP_PORT_CLIENT, len);
r = dhcp_network_send_raw_socket(server->fd_raw, &link, packet, len);
if (r < 0)
@@ -354,17 +360,20 @@ int dhcp_server_send_packet(sd_dhcp_server *server,
return dhcp_server_send_udp(server, destination, &packet->dhcp,
sizeof(DHCPMessage) + optoffset);
else if (requested_broadcast(req) || type == DHCP_NAK)
- return dhcp_server_send_udp(server, INADDR_BROADCAST, &packet->dhcp,
+ return dhcp_server_send_udp(server, INADDR_BROADCAST,
+ &packet->dhcp,
sizeof(DHCPMessage) + optoffset);
else
- /* we cannot send UDP packet to specific MAC address when the address is
- not yet configured, so must fall back to raw packets */
+ /* we cannot send UDP packet to specific MAC address when the
+ address is not yet configured, so must fall back to raw
+ packets */
return dhcp_server_send_unicast_raw(server, packet,
sizeof(DHCPPacket) + optoffset);
}
static int server_message_init(sd_dhcp_server *server, DHCPPacket **ret,
- uint8_t type, size_t *_optoffset, DHCPRequest *req) {
+ uint8_t type, size_t *_optoffset,
+ DHCPRequest *req) {
_cleanup_free_ DHCPPacket *packet = NULL;
size_t optoffset = 0;
int r;
@@ -378,8 +387,9 @@ static int server_message_init(sd_dhcp_server *server, DHCPPacket **ret,
if (!packet)
return -ENOMEM;
- r = dhcp_message_init(&packet->dhcp, BOOTREPLY, be32toh(req->message->xid),
- type, req->max_optlen, &optoffset);
+ r = dhcp_message_init(&packet->dhcp, BOOTREPLY,
+ be32toh(req->message->xid), type, req->max_optlen,
+ &optoffset);
if (r < 0)
return r;
@@ -394,7 +404,8 @@ static int server_message_init(sd_dhcp_server *server, DHCPPacket **ret,
return 0;
}
-static int server_send_offer(sd_dhcp_server *server, DHCPRequest *req, be32_t address) {
+static int server_send_offer(sd_dhcp_server *server, DHCPRequest *req,
+ be32_t address) {
_cleanup_free_ DHCPPacket *packet = NULL;
size_t offset;
be32_t lease_time;
@@ -408,7 +419,8 @@ static int server_send_offer(sd_dhcp_server *server, DHCPRequest *req, be32_t ad
lease_time = htobe32(req->lifetime);
r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0,
- DHCP_OPTION_IP_ADDRESS_LEASE_TIME, 4, &lease_time);
+ DHCP_OPTION_IP_ADDRESS_LEASE_TIME, 4,
+ &lease_time);
if (r < 0)
return r;
@@ -429,7 +441,8 @@ static int server_send_offer(sd_dhcp_server *server, DHCPRequest *req, be32_t ad
return 0;
}
-static int server_send_ack(sd_dhcp_server *server, DHCPRequest *req, be32_t address) {
+static int server_send_ack(sd_dhcp_server *server, DHCPRequest *req,
+ be32_t address) {
_cleanup_free_ DHCPPacket *packet = NULL;
size_t offset;
be32_t lease_time;
@@ -443,7 +456,8 @@ static int server_send_ack(sd_dhcp_server *server, DHCPRequest *req, be32_t addr
lease_time = htobe32(req->lifetime);
r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0,
- DHCP_OPTION_IP_ADDRESS_LEASE_TIME, 4, &lease_time);
+ DHCP_OPTION_IP_ADDRESS_LEASE_TIME, 4,
+ &lease_time);
if (r < 0)
return r;
@@ -480,8 +494,8 @@ static int server_send_nak(sd_dhcp_server *server, DHCPRequest *req) {
return 0;
}
-static int server_send_forcerenew(sd_dhcp_server *server, be32_t address, be32_t gateway,
- uint8_t chaddr[]) {
+static int server_send_forcerenew(sd_dhcp_server *server, be32_t address,
+ be32_t gateway, uint8_t chaddr[]) {
_cleanup_free_ DHCPPacket *packet = NULL;
size_t optoffset = 0;
int r;
@@ -579,7 +593,8 @@ static int ensure_sane_request(DHCPRequest *req, DHCPMessage *message) {
req->message = message;
- /* set client id based on mac address if client did not send an explicit one */
+ /* set client id based on mac address if client did not send an explicit
+ one */
if (!req->client_id.data) {
uint8_t *data;
@@ -643,7 +658,8 @@ int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
/* this only fails on critical errors */
return r;
- existing_lease = hashmap_get(server->leases_by_client_id, &req->client_id);
+ existing_lease = hashmap_get(server->leases_by_client_id,
+ &req->client_id);
switch(type) {
case DHCP_DISCOVER:
@@ -768,12 +784,15 @@ int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
return -ENOMEM;
}
lease->client_id.length = req->client_id.length;
- memcpy(&lease->chaddr, &req->message->chaddr, ETH_ALEN);
+ memcpy(&lease->chaddr, &req->message->chaddr,
+ ETH_ALEN);
lease->gateway = req->message->giaddr;
} else
lease = existing_lease;
- r = sd_event_now(server->event, clock_boottime_or_monotonic(), &time_now);
+ r = sd_event_now(server->event,
+ clock_boottime_or_monotonic(),
+ &time_now);
if (r < 0)
time_now = now(clock_boottime_or_monotonic());
lease->expiration = req->lifetime * USEC_PER_SEC + time_now;
@@ -793,7 +812,8 @@ int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
be32toh(req->message->xid));
server->bound_leases[pool_offset] = lease;
- hashmap_put(server->leases_by_client_id, &lease->client_id, lease);
+ hashmap_put(server->leases_by_client_id,
+ &lease->client_id, lease);
return DHCP_ACK;
}
@@ -885,7 +905,8 @@ static int server_receive_message(sd_event_source *s, int fd,
cmsg->cmsg_len == CMSG_LEN(sizeof(struct in_pktinfo))) {
struct in_pktinfo *info = (struct in_pktinfo*)CMSG_DATA(cmsg);
- /* TODO figure out if this can be done as a filter on the socket, like for IPv6 */
+ /* TODO figure out if this can be done as a filter on
+ * the socket, like for IPv6 */
if (server->index != info->ipi_ifindex)
return 0;