#include "ipv4ll.h"
#include "net.h"
-#define ARP_LEN \
+#define ARP_LEN \
(sizeof(struct arphdr) + (2 * sizeof(uint32_t)) + (2 * HWADDR_LEN))
static int
state->fail.s_addr = 0;
for(;;) {
bytes = get_raw_packet(iface, ETHERTYPE_ARP,
- arp_buffer, sizeof(arp_buffer));
+ arp_buffer, sizeof(arp_buffer));
if (bytes == 0 || bytes == -1)
return;
/* We must have a full ARP header */
/* Check for conflict */
if (state->offer &&
(reply_s == state->offer->yiaddr ||
- (reply_s == 0 && reply_t == state->offer->yiaddr)))
+ (reply_s == 0 && reply_t == state->offer->yiaddr)))
state->fail.s_addr = state->offer->yiaddr;
/* Handle IPv4LL conflicts */
if (IN_LINKLOCAL(htonl(iface->addr.s_addr)) &&
(reply_s == iface->addr.s_addr ||
- (reply_s == 0 && reply_t == iface->addr.s_addr)))
+ (reply_s == 0 && reply_t == iface->addr.s_addr)))
state->fail.s_addr = iface->addr.s_addr;
if (state->fail.s_addr) {
syslog(LOG_ERR, "%s: hardware address %s claims %s",
- iface->name,
- hwaddr_ntoa((unsigned char *)hw_s,
- (size_t)ar.ar_hln),
- inet_ntoa(state->fail));
+ iface->name,
+ hwaddr_ntoa((unsigned char *)hw_s,
+ (size_t)ar.ar_hln),
+ inet_ntoa(state->fail));
errno = EEXIST;
handle_arp_failure(iface);
return;
}
if (++state->claims < ANNOUNCE_NUM)
syslog(LOG_DEBUG,
- "%s: sending ARP announce (%d of %d), "
- "next in %d.00 seconds",
- iface->name, state->claims, ANNOUNCE_NUM, ANNOUNCE_WAIT);
+ "%s: sending ARP announce (%d of %d), "
+ "next in %d.00 seconds",
+ iface->name, state->claims, ANNOUNCE_NUM, ANNOUNCE_WAIT);
else
syslog(LOG_DEBUG,
- "%s: sending ARP announce (%d of %d)",
- iface->name, state->claims, ANNOUNCE_NUM);
+ "%s: sending ARP announce (%d of %d)",
+ iface->name, state->claims, ANNOUNCE_NUM);
if (send_arp(iface, ARPOP_REQUEST,
- state->new->yiaddr, state->new->yiaddr) == -1)
+ state->new->yiaddr, state->new->yiaddr) == -1)
syslog(LOG_ERR, "send_arp: %m");
if (state->claims < ANNOUNCE_NUM) {
add_timeout_sec(ANNOUNCE_WAIT, send_arp_announce, iface);
}
if (state->probes == 0) {
syslog(LOG_INFO, "%s: checking %s is available"
- " on attached networks",
- iface->name, inet_ntoa(addr));
+ " on attached networks",
+ iface->name, inet_ntoa(addr));
}
if (++state->probes < PROBE_NUM) {
tv.tv_sec = PROBE_MIN;
add_timeout_tv(&tv, bind_interface, iface);
}
syslog(LOG_DEBUG,
- "%s: sending ARP probe (%d of %d), next in %0.2f seconds",
- iface->name, state->probes, PROBE_NUM, timeval_to_double(&tv));
+ "%s: sending ARP probe (%d of %d), next in %0.2f seconds",
+ iface->name, state->probes, PROBE_NUM, timeval_to_double(&tv));
if (send_arp(iface, ARPOP_REQUEST, 0, addr.s_addr) == -1)
syslog(LOG_ERR, "send_arp: %m");
}
}
syslog(LOG_INFO, "forking to background");
switch (pid = fork()) {
- case -1:
- syslog(LOG_ERR, "fork: %m");
- exit(EXIT_FAILURE);
- /* NOTREACHED */
- case 0:
- setsid();
- /* Notify parent it's safe to exit as we've detached. */
- close(sidpipe[0]);
- if (write(sidpipe[1], &buf, 1) == -1)
- syslog(LOG_ERR, "failed to notify parent: %m");
- close(sidpipe[1]);
- if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
- dup2(fd, STDIN_FILENO);
- dup2(fd, STDOUT_FILENO);
- dup2(fd, STDERR_FILENO);
- if (fd > STDERR_FILENO)
- close(fd);
- }
- break;
- default:
- signal_reset();
- /* Wait for child to detach */
- close(sidpipe[1]);
- if (read(sidpipe[0], &buf, 1) == -1)
- syslog(LOG_ERR, "failed to read child: %m");
- close(sidpipe[0]);
- break;
+ case -1:
+ syslog(LOG_ERR, "fork: %m");
+ exit(EXIT_FAILURE);
+ /* NOTREACHED */
+ case 0:
+ setsid();
+ /* Notify parent it's safe to exit as we've detached. */
+ close(sidpipe[0]);
+ if (write(sidpipe[1], &buf, 1) == -1)
+ syslog(LOG_ERR, "failed to notify parent: %m");
+ close(sidpipe[1]);
+ if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
+ dup2(fd, STDIN_FILENO);
+ dup2(fd, STDOUT_FILENO);
+ dup2(fd, STDERR_FILENO);
+ if (fd > STDERR_FILENO)
+ close(fd);
+ }
+ break;
+ default:
+ signal_reset();
+ /* Wait for child to detach */
+ close(sidpipe[1]);
+ if (read(sidpipe[0], &buf, 1) == -1)
+ syslog(LOG_ERR, "failed to read child: %m");
+ close(sidpipe[0]);
+ break;
}
/* Done with the fd now */
if (pid != 0) {
get_lease(lease, state->new);
if (ifo->options & DHCPCD_STATIC) {
syslog(LOG_INFO, "%s: using static address %s",
- iface->name, inet_ntoa(lease->addr));
+ iface->name, inet_ntoa(lease->addr));
lease->leasetime = ~0U;
lease->net.s_addr = ifo->request_netmask.s_addr;
state->reason = "STATIC";
} else if (IN_LINKLOCAL(htonl(state->new->yiaddr))) {
syslog(LOG_INFO, "%s: using IPv4LL address %s",
- iface->name, inet_ntoa(lease->addr));
+ iface->name, inet_ntoa(lease->addr));
lease->leasetime = ~0U;
state->reason = "IPV4LL";
} else if (ifo->options & DHCPCD_INFORM) {
else
lease->addr.s_addr = iface->addr.s_addr;
syslog(LOG_INFO, "%s: received approval for %s", iface->name,
- inet_ntoa(lease->addr));
+ inet_ntoa(lease->addr));
lease->leasetime = ~0U;
state->reason = "INFORM";
} else {
else if (lease->frominfo)
state->reason = "TIMEOUT";
if (lease->leasetime == ~0U) {
- lease->renewaltime = lease->rebindtime = lease->leasetime;
+ lease->renewaltime =
+ lease->rebindtime =
+ lease->leasetime;
syslog(LOG_INFO, "%s: leased %s for infinity",
- iface->name, inet_ntoa(lease->addr));
+ iface->name, inet_ntoa(lease->addr));
} else {
if (lease->rebindtime == 0)
lease->rebindtime = lease->leasetime * T2;
else if (lease->rebindtime >= lease->leasetime) {
lease->rebindtime = lease->leasetime * T2;
syslog(LOG_ERR,
- "%s: rebind time greater than lease "
- "time, forcing to %u seconds",
- iface->name, lease->rebindtime);
+ "%s: rebind time greater than lease "
+ "time, forcing to %u seconds",
+ iface->name, lease->rebindtime);
}
if (lease->renewaltime == 0)
lease->renewaltime = lease->leasetime * T1;
else if (lease->renewaltime > lease->rebindtime) {
lease->renewaltime = lease->leasetime * T1;
syslog(LOG_ERR,
- "%s: renewal time greater than rebind "
- "time, forcing to %u seconds",
- iface->name, lease->renewaltime);
+ "%s: renewal time greater than rebind "
+ "time, forcing to %u seconds",
+ iface->name, lease->renewaltime);
}
syslog(LOG_INFO,
- "%s: leased %s for %u seconds", iface->name,
- inet_ntoa(lease->addr), lease->leasetime);
+ "%s: leased %s for %u seconds", iface->name,
+ inet_ntoa(lease->addr), lease->leasetime);
}
}
if (options & DHCPCD_TEST) {
ssize_t
send_raw_packet(const struct interface *iface, int protocol,
- const void *data, ssize_t len)
+ const void *data, ssize_t len)
{
struct iovec iov[2];
struct ether_header hw;
* So we pass the buffer in the API so we can loop on >1 packet. */
ssize_t
get_raw_packet(struct interface *iface, int protocol,
- void *data, ssize_t len)
+ void *data, ssize_t len)
{
int fd = -1;
struct bpf_hdr packet;
}
bytes = -1;
memcpy(&packet, iface->buffer + iface->buffer_pos,
- sizeof(packet));
+ sizeof(packet));
if (packet.bh_caplen != packet.bh_datalen)
goto next; /* Incomplete packet, drop. */
if (iface->buffer_pos + packet.bh_caplen + packet.bh_hdrlen >
memcpy(data, payload, bytes);
next:
iface->buffer_pos += BPF_WORDALIGN(packet.bh_hdrlen +
- packet.bh_caplen);
+ packet.bh_caplen);
if (iface->buffer_pos >= iface->buffer_len)
iface->buffer_len = iface->buffer_pos = 0;
if (bytes != -1)
{
int flags;
- if ((flags = fcntl(fd, F_GETFD, 0)) == -1
- || fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1)
+ if ((flags = fcntl(fd, F_GETFD, 0)) == -1 ||
+ fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1)
{
syslog(LOG_ERR, "fcntl: %m");
return -1;
{
int flags;
- if ((flags = fcntl(fd, F_GETFL, 0)) == -1
- || fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)
+ if ((flags = fcntl(fd, F_GETFL, 0)) == -1 ||
+ fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)
{
syslog(LOG_ERR, "fcntl: %m");
return -1;
static void
append_config(char ***env, ssize_t *len,
- const char *prefix, const char *const *config)
+ const char *prefix, const char *const *config)
{
ssize_t i, j, e1;
char **ne, *eq;
eq = strchr(config[i], '=');
e1 = eq - config[i] + 1;
for (j = 0; j < *len; j++) {
- if (strncmp(ne[j] + strlen(prefix) + 1, config[i], e1) == 0) {
+ if (strncmp(ne[j] + strlen(prefix) + 1,
+ config[i], e1) == 0)
+ {
free(ne[j]);
ne[j] = make_var(prefix, config[i]);
break;
if (e > 0) {
env = xrealloc(env, sizeof(char *) * (elen + e + 1));
elen += configure_env(env + elen, "old",
- iface->state->old, ifo);
+ iface->state->old, ifo);
}
append_config(&env, &elen, "old",
- (const char *const *)ifo->config);
+ (const char *const *)ifo->config);
}
if (iface->state->new) {
e = configure_env(NULL, NULL, iface->state->new, ifo);
if (e > 0) {
env = xrealloc(env, sizeof(char *) * (elen + e + 1));
elen += configure_env(env + elen, "new",
- iface->state->new, ifo);
+ iface->state->new, ifo);
}
append_config(&env, &elen, "new",
- (const char *const *)ifo->config);
+ (const char *const *)ifo->config);
}
/* Add our base environment */
struct iovec iov[2];
syslog(LOG_DEBUG, "%s: executing `%s', reason %s",
- iface->name, argv[0], iface->state->reason);
+ iface->name, argv[0], iface->state->reason);
/* Make our env */
elen = make_env(iface, &env);
if (fd->listener) {
if (bigenv == NULL) {
elen = arraytostr((const char *const *)env,
- &bigenv);
+ &bigenv);
iov[0].iov_base = &elen;
iov[0].iov_len = sizeof(ssize_t);
iov[1].iov_base = bigenv;
static struct rt *
find_route(struct rt *rts, const struct rt *r, struct rt **lrt,
- const struct rt *srt)
+ const struct rt *srt)
{
struct rt *rt;
for (rt = rts; rt; rt = rt->next) {
if (rt->dest.s_addr == r->dest.s_addr &&
#if HAVE_ROUTE_METRIC
- (srt || (!rt->iface || rt->iface->metric == r->iface->metric)) &&
+ (srt || (!rt->iface ||
+ rt->iface->metric == r->iface->metric)) &&
#endif
(!srt || srt != rt) &&
rt->net.s_addr == r->net.s_addr)
strlcpy(addr, inet_ntoa(rt->dest), sizeof(addr));
if (rt->gate.s_addr == INADDR_ANY)
syslog(LOG_DEBUG, "%s: %s route to %s/%d", ifname, cmd,
- addr, inet_ntocidr(rt->net));
+ addr, inet_ntocidr(rt->net));
else if (rt->gate.s_addr == rt->dest.s_addr &&
- rt->net.s_addr == INADDR_BROADCAST)
+ rt->net.s_addr == INADDR_BROADCAST)
syslog(LOG_DEBUG, "%s: %s host route to %s", ifname, cmd,
- addr);
+ addr);
else if (rt->dest.s_addr == INADDR_ANY && rt->net.s_addr == INADDR_ANY)
syslog(LOG_DEBUG, "%s: %s default route via %s", ifname, cmd,
- inet_ntoa(rt->gate));
+ inet_ntoa(rt->gate));
else
syslog(LOG_DEBUG, "%s: %s route to %s/%d via %s", ifname, cmd,
- addr, inet_ntocidr(rt->net), inet_ntoa(rt->gate));
+ addr, inet_ntocidr(rt->net), inet_ntoa(rt->gate));
}
/* If something other than dhcpcd removes a route,
desc_route("changing", nrt, iface->name);
/* We don't call change_route because it doesn't work when something
* has already used it. */
- del_route(ort->iface, &ort->dest, &ort->net, &ort->gate, ort->iface->metric);
- if (!add_route(iface, &nrt->dest, &nrt->net, &nrt->gate, iface->metric))
+ del_route(ort->iface, &ort->dest, &ort->net, &ort->gate,
+ ort->iface->metric);
+ if (!add_route(iface, &nrt->dest, &nrt->net, &nrt->gate,
+ iface->metric))
return 0;
syslog(LOG_ERR, "%s: add_route: %m", iface->name);
return -1;
int retval;
syslog(LOG_DEBUG, "%s: deleting IP address %s/%d",
- iface->name,
- inet_ntoa(iface->addr),
- inet_ntocidr(iface->net));
+ iface->name,
+ inet_ntoa(iface->addr),
+ inet_ntocidr(iface->net));
retval = del_address(iface, &iface->addr, &iface->net);
if (retval == -1 && errno != EADDRNOTAVAIL)
syslog(LOG_ERR, "del_address: %m");
!has_address(iface->name, &lease->addr, &lease->net))
{
syslog(LOG_DEBUG, "%s: adding IP address %s/%d",
- iface->name, inet_ntoa(lease->addr),
- inet_ntocidr(lease->net));
+ iface->name, inet_ntoa(lease->addr),
+ inet_ntocidr(lease->net));
if (add_address(iface,
- &lease->addr, &lease->net, &lease->brd) == -1 &&
+ &lease->addr, &lease->net, &lease->brd) == -1 &&
errno != EEXIST)
{
syslog(LOG_ERR, "add_address: %m");
#include "eloop.h"
static int fd = -1;
-struct sockaddr_un sun;
static char buffer[1024];
static char *argvp[255];
+struct sockaddr_un sun;
struct fd_list *fds = NULL;
static void
return -1;
unlink(CONTROLSOCKET);
if (bind(fd, (struct sockaddr *)&sun, len) == -1 ||
- chmod(CONTROLSOCKET, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) == -1 ||
+ chmod(CONTROLSOCKET,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) == -1 ||
set_cloexec(fd) == -1 ||
set_nonblock(fd) == -1 ||
listen(fd, sizeof(fds)) == -1)
/* Our aggregate option buffer.
* We ONLY use this when options are split, which for most purposes is
* practically never. See RFC3396 for details. */
-static uint8_t *dhcp_opt_buffer;
+static uint8_t *opt_buffer;
struct dhcp_opt {
uint8_t option;
static const struct dhcp_opt const dhcp_opts[] = {
{ 1, IPV4 | REQUEST, "subnet_mask" },
- /* RFC 3442 states that the CSR has to come before all other routes.
- * For completeness, we also specify static routes, then routers. */
+ /* RFC 3442 states that the CSR has to come before all other
+ * routes. For completeness, we also specify static routes,
+ * then routers. */
{ 121, RFC3442 | REQUEST, "classless_static_routes" },
{ 249, RFC3442, "ms_classless_static_routes" },
{ 33, IPV4 | ARRAY | REQUEST, "static_routes" },
if (match) {
if (add == 1)
add_option_mask(mask,
- opt->option);
+ opt->option);
else
del_option_mask(mask,
- opt->option);
+ opt->option);
break;
}
}
if (type)
*type = opt->type;
- if (opt->type == 0 || opt->type & STRING || opt->type & RFC3442)
+ if (opt->type == 0 ||
+ opt->type & STRING ||
+ opt->type & RFC3442)
return 0;
sz = 0;
static void
free_option_buffer(void)
{
- free(dhcp_opt_buffer);
+ free(opt_buffer);
}
#endif
o = *p++;
if (o == opt) {
if (op) {
- if (!dhcp_opt_buffer) {
- dhcp_opt_buffer = xmalloc(sizeof(struct dhcp_message));
+ if (!opt_buffer) {
+ opt_buffer = xmalloc(sizeof(*dhcp));
#ifdef DEBUG_MEMORY
atexit(free_option_buffer);
#endif
}
if (!bp)
- bp = dhcp_opt_buffer;
+ bp = opt_buffer;
memcpy(bp, op, ol);
bp += ol;
}
*len = bl;
if (bp) {
memcpy(bp, op, ol);
- return (const uint8_t *)&dhcp_opt_buffer;
+ return (const uint8_t *)&opt_buffer;
}
if (op)
return op;
return p - dst;
}
-#define PUTADDR(_type, _val) \
-{ \
- *p++ = _type; \
- *p++ = 4; \
- memcpy(p, &_val.s_addr, 4); \
- p += 4; \
-}
+#define PUTADDR(_type, _val) \
+ { \
+ *p++ = _type; \
+ *p++ = 4; \
+ memcpy(p, &_val.s_addr, 4); \
+ p += 4; \
+ }
ssize_t
make_message(struct dhcp_message **message,
- const struct interface *iface,
- uint8_t type)
+ const struct interface *iface,
+ uint8_t type)
{
struct dhcp_message *dhcp;
uint8_t *m, *lp, *p;
p = dhcp->options;
if ((type == DHCP_INFORM ||
- type == DHCP_RELEASE ||
- type == DHCP_REQUEST) &&
+ type == DHCP_RELEASE ||
+ type == DHCP_REQUEST) &&
!IN_LINKLOCAL(ntohl(iface->addr.s_addr)))
{
dhcp->ciaddr = iface->addr.s_addr;
- /* Just incase we haven't actually configured the address yet */
+ /* In-case we haven't actually configured the address yet */
if (type == DHCP_INFORM && iface->addr.s_addr == 0)
dhcp->ciaddr = lease->addr.s_addr;
/* Zero the address if we're currently on a different subnet */
if (type == DHCP_DECLINE ||
type == DHCP_DISCOVER ||
(type == DHCP_REQUEST &&
- lease->addr.s_addr != iface->addr.s_addr))
+ lease->addr.s_addr != iface->addr.s_addr))
{
PUTADDR(DHO_IPADDRESS, lease->addr);
if (lease->server.s_addr)
}
if (type == DHCP_RELEASE) {
- if (lease->server.s_addr)
- PUTADDR(DHO_SERVERID, lease->server);
+ if (lease->server.s_addr)
+ PUTADDR(DHO_SERVERID, lease->server);
}
}
if (ifo->vendorclassid[0]) {
*p++ = DHO_VENDORCLASSID;
memcpy(p, ifo->vendorclassid,
- ifo->vendorclassid[0] + 1);
+ ifo->vendorclassid[0] + 1);
p += ifo->vendorclassid[0] + 1;
}
*p++ = 0;
for (opt = dhcp_opts; opt->option; opt++) {
if (!(opt->type & REQUEST ||
- has_option_mask(ifo->requestmask, opt->option)))
+ has_option_mask(ifo->requestmask, opt->option)))
continue;
if (type == DHCP_INFORM &&
(opt->option == DHO_RENEWALTIME ||
- opt->option == DHO_REBINDTIME))
+ opt->option == DHO_REBINDTIME))
continue;
*p++ = opt->option;
}
continue;
}
switch (c) {
- case '"': /* FALLTHROUGH */
- case '\'': /* FALLTHROUGH */
- case '$': /* FALLTHROUGH */
- case '`': /* FALLTHROUGH */
- case '\\': /* FALLTHROUGH */
- if (s) {
- if (len < 3) {
- errno = ENOBUFS;
- return -1;
- }
- *s++ = '\\';
- len--;
+ case '"': /* FALLTHROUGH */
+ case '\'': /* FALLTHROUGH */
+ case '$': /* FALLTHROUGH */
+ case '`': /* FALLTHROUGH */
+ case '\\': /* FALLTHROUGH */
+ if (s) {
+ if (len < 3) {
+ errno = ENOBUFS;
+ return -1;
}
- bytes++;
- break;
+ *s++ = '\\';
+ len--;
+ }
+ bytes++;
+ break;
}
if (s) {
*s++ = c;
ssize_t
configure_env(char **env, const char *prefix, const struct dhcp_message *dhcp,
- const struct if_options *ifo)
+ const struct if_options *ifo)
{
unsigned int i;
const uint8_t *p;
static void
usage(void)
{
- printf("usage: "PACKAGE" [-dknpqxyADEGHKLOTV] [-c script] [-f file ] [-h hostname]\n"
- " [-i classID ] [-l leasetime] [-m metric] [-o option] [-r ipaddr]\n"
- " [-s ipaddr] [-t timeout] [-u userclass] [-F none|ptr|both]\n"
- " [-I clientID] [-C hookscript] [-Q option] [-X ipaddr] <interface>\n");
+ printf("usage: "PACKAGE" [-dknpqxyADEGHKLOTV] [-c script] [-f file ]"
+ " [-h hostname]\n"
+ " [-i classID ] [-l leasetime] [-m metric]"
+ " [-o option] [-r ipaddr]\n"
+ " [-s ipaddr] [-t timeout] [-u userclass]"
+ " [-F none|ptr|both]\n"
+ " [-I clientID] [-C hookscript] [-Q option]"
+ " [-X ipaddr] <interface>\n");
}
static void
static void
send_message(struct interface *iface, int type,
- void (*callback)(void *))
+ void (*callback)(void *))
{
struct if_state *state = iface->state;
struct dhcp_message *dhcp;
if (!callback)
syslog(LOG_DEBUG, "%s: sending %s with xid 0x%x",
- iface->name, get_dhcp_op(type), state->xid);
+ iface->name, get_dhcp_op(type), state->xid);
else {
if (state->interval == 0)
state->interval = 4;
tv.tv_sec = state->interval + DHCP_RAND_MIN;
tv.tv_usec = arc4random() % (DHCP_RAND_MAX_U - DHCP_RAND_MIN_U);
syslog(LOG_DEBUG,
- "%s: sending %s (xid 0x%x), next in %0.2f seconds",
- iface->name, get_dhcp_op(type), state->xid,
- timeval_to_double(&tv));
+ "%s: sending %s (xid 0x%x), next in %0.2f seconds",
+ iface->name, get_dhcp_op(type), state->xid,
+ timeval_to_double(&tv));
}
/* If we couldn't open a UDP port for our IP address
* then we cannot renew.
struct interface *iface = arg;
syslog(LOG_ERR, "%s: failed to renew, attmepting to rebind",
- iface->name);
+ iface->name);
iface->state->state = DHS_REBIND;
delete_timeout(send_renew, iface);
iface->state->lease.server.s_addr = 0;
static void
log_dhcp(int lvl, const char *msg,
- const struct interface *iface, const struct dhcp_message *dhcp)
+ const struct interface *iface, const struct dhcp_message *dhcp)
{
char *a;
struct in_addr addr;
r = get_option_addr(&addr.s_addr, dhcp, DHO_SERVERID);
if (dhcp->servername[0] && r == 0)
syslog(lvl, "%s: %s %s from %s `%s'", iface->name, msg, a,
- inet_ntoa(addr), dhcp->servername);
+ inet_ntoa(addr), dhcp->servername);
else if (r == 0)
syslog(lvl, "%s: %s %s from %s",
- iface->name, msg, a, inet_ntoa(addr));
+ iface->name, msg, a, inet_ntoa(addr));
else
syslog(lvl, "%s: %s %s", iface->name, msg, a);
free(a);
continue;
if (dhcp->servername[0])
syslog(LOG_WARNING,
- "%s: ignoring blacklisted server %s `%s'",
- iface->name,
- inet_ntoa(addr), dhcp->servername);
+ "%s: ignoring blacklisted server %s `%s'",
+ iface->name,
+ inet_ntoa(addr), dhcp->servername);
else
syslog(LOG_WARNING,
- "%s: ignoring blacklisted server %s",
- iface->name, inet_ntoa(addr));
+ "%s: ignoring blacklisted server %s",
+ iface->name, inet_ntoa(addr));
return;
}
}
packet = xmalloc(udp_dhcp_len);
for(;;) {
bytes = get_raw_packet(iface, ETHERTYPE_IP,
- packet, udp_dhcp_len);
+ packet, udp_dhcp_len);
if (bytes == 0 || bytes == -1)
break;
if (valid_udp_packet(packet) == -1)
bytes = get_udp_data(&pp, packet);
if ((size_t)bytes > sizeof(*dhcp)) {
syslog(LOG_ERR, "%s: packet greater than DHCP size",
- iface->name);
+ iface->name);
continue;
}
if (!dhcp)
memcpy(dhcp, pp, bytes);
if (dhcp->cookie != htonl(MAGIC_COOKIE)) {
syslog(LOG_DEBUG, "%s: bogus cookie, ignoring",
- iface->name);
+ iface->name);
continue;
}
/* Ensure it's the right transaction */
if (iface->state->xid != dhcp->xid) {
syslog(LOG_DEBUG,
- "%s: ignoring packet with xid 0x%x as"
- " it's not ours (0x%x)",
- iface->name, dhcp->xid, iface->state->xid);
+ "%s: ignoring packet with xid 0x%x as"
+ " it's not ours (0x%x)",
+ iface->name, dhcp->xid, iface->state->xid);
continue;
}
/* Ensure packet is for us */
memcmp(dhcp->chaddr, iface->hwaddr, iface->hwlen))
{
syslog(LOG_DEBUG, "%s: xid 0x%x is not for our hwaddr %s",
- iface->name, dhcp->xid,
- hwaddr_ntoa(dhcp->chaddr, sizeof(dhcp->chaddr)));
+ iface->name, dhcp->xid,
+ hwaddr_ntoa(dhcp->chaddr, sizeof(dhcp->chaddr)));
continue;
}
handle_dhcp(iface, &dhcp);
!IN_LINKLOCAL(htonl(iface->state->lease.addr.s_addr)))
{
syslog(LOG_INFO, "%s: releasing lease of %s",
- iface->name, inet_ntoa(iface->state->lease.addr));
+ iface->name, inet_ntoa(iface->state->lease.addr));
open_sockets(iface);
send_message(iface, DHCP_RELEASE, NULL);
drop_config(iface, "RELEASE");
memcpy(iface->clientid + 2, iface->name, ifl);
if (ifl < 4)
memset(iface->clientid + 2 + ifl,
- 0, 4 - ifl);
+ 0, 4 - ifl);
} else {
ifl = htonl(if_nametoindex(iface->name));
memcpy(iface->clientid + 2, &ifl, 4);
iface->clientid[0] = len;
iface->clientid[1] = iface->family;
memcpy(iface->clientid + 2, iface->hwaddr,
- iface->hwlen);
+ iface->hwlen);
}
}
}
struct interface *iface = arg;
syslog(LOG_INFO, "%s: renewing lease of %s",
- iface->name, inet_ntoa(iface->state->lease.addr));
+ iface->name, inet_ntoa(iface->state->lease.addr));
iface->state->state = DHS_RENEW;
iface->state->xid = arc4random();
open_sockets(iface);
}
if (ifo->options & DHCPCD_INFORM) {
syslog(LOG_INFO, "%s: informing address of %s",
- iface->name, inet_ntoa(iface->state->lease.addr));
+ iface->name, inet_ntoa(iface->state->lease.addr));
} else {
syslog(LOG_INFO, "%s: rebinding lease of %s",
- iface->name, inet_ntoa(iface->state->lease.addr));
+ iface->name, inet_ntoa(iface->state->lease.addr));
}
iface->state->state = DHS_REBOOT;
iface->state->xid = arc4random();
if (ifo->request_address.s_addr) {
/* This also changes netmask */
if (iface->state->options->options & DHCPCD_INFORM &&
- !has_address(iface->name, &ifo->request_address,
- &ifo->request_netmask))
+ !has_address(iface->name, &ifo->request_address,
+ &ifo->request_netmask))
{
syslog(LOG_DEBUG, "%s: adding IP address %s/%d",
- iface->name, inet_ntoa(ifo->request_address),
- inet_ntocidr(ifo->request_netmask));
+ iface->name, inet_ntoa(ifo->request_address),
+ inet_ntocidr(ifo->request_netmask));
if (add_address(iface, &ifo->request_address,
- &ifo->request_netmask, NULL) == -1 &&
+ &ifo->request_netmask, NULL) == -1 &&
errno != EEXIST)
{
syslog(LOG_ERR, "add_address: %m");
ifo->request_address.s_addr = 0;
} else
iface->state->offer = read_lease(iface);
-/* if (iface->state->offer) {
- if (IN_LINKLOCAL(htonl(iface->state->offer->yiaddr))) {
- free(iface->state->offer);
- iface->state->offer = NULL;
- }
- } */
if (iface->state->offer) {
get_lease(&iface->state->lease, iface->state->offer);
iface->state->lease.frominfo = 1;
if (IN_LINKLOCAL(htonl(iface->state->offer->yiaddr))) {
- if (iface->state->offer->yiaddr == iface->addr.s_addr) {
+ if (iface->state->offer->yiaddr ==
+ iface->addr.s_addr)
+ {
free(iface->state->offer);
iface->state->offer = NULL;
}
} else if (stat(iface->leasefile, &st) == 0 &&
- get_option_uint32(&l, iface->state->offer,
- DHO_LEASETIME) == 0)
+ get_option_uint32(&l, iface->state->offer,
+ DHO_LEASETIME) == 0)
{
/* Offset lease times and check expiry */
gettimeofday(&now, NULL);
if (!iface->state->offer)
start_discover(iface);
else if (IN_LINKLOCAL(htonl(iface->state->lease.addr.s_addr)) &&
- iface->state->options->options & DHCPCD_IPV4LL)
+ iface->state->options->options & DHCPCD_IPV4LL)
start_ipv4ll(iface);
else
start_reboot(iface);
{
struct if_state *ifs;
- if (iface->state) {
+ if (iface->state)
ifs = iface->state;
- } else
+ else
ifs = iface->state = xzalloc(sizeof(*ifs));
ifs->state = DHS_INIT;
handle_link(_unused void *arg)
{
if (manage_link(linkfd,
- handle_carrier,
- handle_new_interface,
- handle_remove_interface) == -1)
+ handle_carrier,
+ handle_new_interface,
+ handle_remove_interface) == -1)
syslog(LOG_ERR, "manage_link: %m");
}
return;
default:
syslog(LOG_ERR,
- "received signal %d, but don't know what to do with it",
- sig);
+ "received signal %d, but don't know what to do with it",
+ sig);
return;
}
break;
if (iface->carrier != LINK_DOWN &&
(do_release ||
- iface->state->options->options & DHCPCD_RELEASE))
+ iface->state->options->options & DHCPCD_RELEASE))
send_release(iface);
stop_interface(iface);
}
if (!(options & DHCPCD_MASTER)) {
control_fd = open_control();
if (control_fd != -1) {
- syslog(LOG_INFO, "sending commands to master dhcpcd process");
+ syslog(LOG_INFO,
+ "sending commands to master dhcpcd process");
i = send_control(argc, argv);
if (i > 0) {
syslog(LOG_DEBUG, "send OK");
}
if (geteuid())
- syslog(LOG_WARNING, PACKAGE " will not work correctly unless"
- " run as root");
+ syslog(LOG_WARNING,
+ PACKAGE " will not work correctly unless run as root");
if (sig != 0) {
i = -1;
pid = read_pid();
if (pid != 0)
syslog(LOG_INFO, "sending signal %d to pid %d",
- sig, pid);
+ sig, pid);
if (!pid || (i = kill(pid, sig))) {
if (sig != SIGALRM)
kill(pid, 0) == 0)
{
syslog(LOG_ERR, ""PACKAGE
- " already running on pid %d (%s)",
- pid, pidfile);
+ " already running on pid %d (%s)",
+ pid, pidfile);
exit(EXIT_FAILURE);
}
break;
if (!iface)
syslog(LOG_ERR, "%s: interface not found or invalid",
- ifv[i]);
+ ifv[i]);
}
if (!ifaces) {
if (ifc == 0)
!(options & DHCPCD_LINK))
{
syslog(LOG_ERR, "aborting as we're not backgrounding"
- " with link detection");
+ " with link detection");
exit(EXIT_FAILURE);
}
}
}
void
-add_timeout_tv(const struct timeval *when,
- void (*callback)(void *), void *arg)
+add_timeout_tv(const struct timeval *when, void (*callback)(void *), void *arg)
{
struct timeval w;
struct timeout *t, *tt = NULL;
}
void
-add_timeout_sec(time_t when,
- void (*callback)(void *), void *arg)
+add_timeout_sec(time_t when, void (*callback)(void *), void *arg)
{
struct timeval tv;
* callbacks given. Handy for deleting everything apart from the expire
* timeout. */
void
-delete_timeouts(void *arg,
- void (*callback)(void *), ...)
+delete_timeouts(void *arg, void (*callback)(void *), ...)
{
struct timeout *t, *tt, *last = NULL;
va_list va;
timersub(&timeouts->when, &now, &tv);
if (tv.tv_sec > INT_MAX / 1000 ||
(tv.tv_sec == INT_MAX / 1000 &&
- (tv.tv_usec + 999) / 1000 > INT_MAX % 1000))
+ (tv.tv_usec + 999) / 1000 > INT_MAX % 1000))
msecs = INT_MAX;
else
msecs = tv.tv_sec * 1000 +
- (tv.tv_usec + 999) / 1000;
+ (tv.tv_usec + 999) / 1000;
} else
/* No timeouts, so wait forever. */
msecs = -1;
#include "if-options.h"
#include "net.h"
-#define ROUNDUP(a) \
+#define ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
/* Darwin doesn't define this for some very odd reason */
#ifndef SA_SIZE
-# define SA_SIZE(sa) \
- ( (!(sa) || ((struct sockaddr *)(sa))->sa_len == 0) ? \
- sizeof(long) : \
- 1 + ( (((struct sockaddr *)(sa))->sa_len - 1) | (sizeof(long) - 1) ) )
+# define SA_SIZE(sa) \
+ ( (!(sa) || ((struct sockaddr *)(sa))->sa_len == 0) ? \
+ sizeof(long) : \
+ 1 + ( (((struct sockaddr *)(sa))->sa_len - 1) | \
+ (sizeof(long) - 1) ) )
#endif
static int a_fd = -1;
int
if_address(const struct interface *iface, const struct in_addr *address,
- const struct in_addr *netmask, const struct in_addr *broadcast,
- int action)
+ const struct in_addr *netmask, const struct in_addr *broadcast,
+ int action)
{
int retval;
struct ifaliasreq ifa;
memset(&ifa, 0, sizeof(ifa));
strlcpy(ifa.ifra_name, iface->name, sizeof(ifa.ifra_name));
-#define ADDADDR(_var, _addr) { \
- _s.sa = &_var; \
- _s.sin->sin_family = AF_INET; \
- _s.sin->sin_len = sizeof(*_s.sin); \
- memcpy(&_s.sin->sin_addr, _addr, sizeof(_s.sin->sin_addr)); \
-}
+#define ADDADDR(_var, _addr) { \
+ _s.sa = &_var; \
+ _s.sin->sin_family = AF_INET; \
+ _s.sin->sin_len = sizeof(*_s.sin); \
+ memcpy(&_s.sin->sin_addr, _addr, sizeof(_s.sin->sin_addr)); \
+ }
ADDADDR(ifa.ifra_addr, address);
ADDADDR(ifa.ifra_mask, netmask);
/* ARGSUSED4 */
int
if_route(const struct interface *iface, const struct in_addr *dest,
- const struct in_addr *net, const struct in_addr *gate,
- _unused int metric, int action)
+ const struct in_addr *net, const struct in_addr *gate,
+ _unused int metric, int action)
{
union sockunion {
struct sockaddr sa;
size_t l;
int retval = 0;
-#define ADDSU(_su) { \
- l = SA_SIZE(&(_su.sa)); \
- memcpy(bp, &(_su), l); \
- bp += l; \
-}
-#define ADDADDR(_addr) { \
- memset (&su, 0, sizeof(su)); \
- su.sin.sin_family = AF_INET; \
- su.sin.sin_len = sizeof(su.sin); \
- memcpy (&su.sin.sin_addr, _addr, sizeof(su.sin.sin_addr)); \
- ADDSU(su); \
-}
+#define ADDSU(_su) { \
+ l = SA_SIZE(&(_su.sa)); \
+ memcpy(bp, &(_su), l); \
+ bp += l; \
+ }
+#define ADDADDR(_addr) { \
+ memset (&su, 0, sizeof(su)); \
+ su.sin.sin_family = AF_INET; \
+ su.sin.sin_len = sizeof(su.sin); \
+ memcpy (&su.sin.sin_addr, _addr, sizeof(su.sin.sin_addr)); \
+ ADDSU(su); \
+ }
memset(&rtm, 0, sizeof(rtm));
rtm.hdr.rtm_version = RTM_VERSION;
}
ADDADDR(dest);
- if (rtm.hdr.rtm_flags & RTF_HOST || !(rtm.hdr.rtm_flags & RTF_STATIC)) {
+ if (rtm.hdr.rtm_flags & RTF_HOST ||
+ !(rtm.hdr.rtm_flags & RTF_STATIC))
+ {
/* Make us a link layer socket for the host gateway */
memset(&su, 0, sizeof(su));
su.sdl.sdl_len = sizeof(struct sockaddr_dl);
#define BUFFER_LEN 2048
int
manage_link(int fd,
- void (*if_carrier)(const char *),
- void (*if_add)(const char *),
- void (*if_remove)(const char *))
+ void (*if_carrier)(const char *),
+ void (*if_add)(const char *),
+ void (*if_remove)(const char *))
{
char buffer[2048], *p, *e;
char ifname[IF_NAMESIZE];
rt.iface = NULL;
sin = (struct sockaddr_in *)sa;
memcpy(&rt.dest.s_addr, &sin->sin_addr.s_addr,
- sizeof(rt.dest.s_addr));
+ sizeof(rt.dest.s_addr));
sa = (struct sockaddr *)
(ROUNDUP(sa->sa_len) + (char *)sa);
sin = (struct sockaddr_in *)sa;
memcpy(&rt.gate.s_addr, &sin->sin_addr.s_addr,
- sizeof(rt.gate.s_addr));
+ sizeof(rt.gate.s_addr));
sa = (struct sockaddr *)
(ROUNDUP(sa->sa_len) + (char *)sa);
sin = (struct sockaddr_in *)sa;
memcpy(&rt.net.s_addr, &sin->sin_addr.s_addr,
- sizeof(rt.net.s_addr));
+ sizeof(rt.net.s_addr));
route_deleted(&rt);
break;
}
static void
discover_link(struct interface **ifs, int argc, char * const *argv,
- struct ifreq *ifr)
+ struct ifreq *ifr)
{
struct interface *ifp, *ifl = NULL;
struct sockaddr_dl *sdl;
default:
/* Don't needlessly spam console on startup */
if (!(options & DHCPCD_MASTER &&
- !(options & DHCPCD_DAEMONISED) &&
- options & DHCPCD_QUIET))
+ !(options & DHCPCD_DAEMONISED) &&
+ options & DHCPCD_QUIET))
syslog(LOG_ERR, "%s: unsupported interface type",
- ifr->ifr_name);
+ ifr->ifr_name);
free(ifp);
ifp = NULL;
break;
static int
get_netlink(int fd, int flags,
- int (*callback)(struct nlmsghdr *))
+ int (*callback)(struct nlmsghdr *))
{
char *buffer = NULL;
ssize_t bytes;
switch (rta->rta_type) {
case RTA_DST:
memcpy(&rt.dest.s_addr, RTA_DATA(rta),
- sizeof(rt.dest.s_addr));
+ sizeof(rt.dest.s_addr));
break;
case RTA_GATEWAY:
memcpy(&rt.gate.s_addr, RTA_DATA(rta),
- sizeof(rt.gate.s_addr));
+ sizeof(rt.gate.s_addr));
break;
case RTA_OIF:
idx = *(int *)RTA_DATA(rta);
int
manage_link(int fd,
- void (*if_carrier)(const char *),
- void (*if_add)(const char *),
- void (*if_remove)(const char *))
+ void (*if_carrier)(const char *),
+ void (*if_add)(const char *),
+ void (*if_remove)(const char *))
{
nl_carrier = if_carrier;
nl_add = if_add;
return r;
}
-#define NLMSG_TAIL(nmsg) \
+#define NLMSG_TAIL(nmsg) \
((struct rtattr *)(((ptrdiff_t)(nmsg))+NLMSG_ALIGN((nmsg)->nlmsg_len)))
static int
add_attr_l(struct nlmsghdr *n, unsigned int maxlen, int type,
- const void *data, int alen)
+ const void *data, int alen)
{
int len = RTA_LENGTH(alen);
struct rtattr *rta;
int
if_address(const struct interface *iface,
- const struct in_addr *address, const struct in_addr *netmask,
- const struct in_addr *broadcast, int action)
+ const struct in_addr *address, const struct in_addr *netmask,
+ const struct in_addr *broadcast, int action)
{
struct nlma *nlm;
int retval = 0;
nlm->ifa.ifa_prefixlen = inet_ntocidr(*netmask);
/* This creates the aliased interface */
add_attr_l(&nlm->hdr, sizeof(*nlm), IFA_LABEL,
- iface->name, strlen(iface->name) + 1);
+ iface->name, strlen(iface->name) + 1);
add_attr_l(&nlm->hdr, sizeof(*nlm), IFA_LOCAL,
- &address->s_addr, sizeof(address->s_addr));
+ &address->s_addr, sizeof(address->s_addr));
if (action >= 0 && broadcast)
add_attr_l(&nlm->hdr, sizeof(*nlm), IFA_BROADCAST,
- &broadcast->s_addr, sizeof(broadcast->s_addr));
+ &broadcast->s_addr, sizeof(broadcast->s_addr));
if (send_netlink(&nlm->hdr) == -1)
retval = -1;
int
if_route(const struct interface *iface,
- const struct in_addr *destination, const struct in_addr *netmask,
- const struct in_addr *gateway, int metric, int action)
+ const struct in_addr *destination, const struct in_addr *netmask,
+ const struct in_addr *gateway, int metric, int action)
{
struct nlmr *nlm;
unsigned int ifindex;
nlm->rt.rtm_protocol = RTPROT_BOOT;
if (gateway->s_addr == INADDR_ANY ||
(gateway->s_addr == destination->s_addr &&
- netmask->s_addr == INADDR_BROADCAST))
+ netmask->s_addr == INADDR_BROADCAST))
nlm->rt.rtm_scope = RT_SCOPE_LINK;
else
nlm->rt.rtm_scope = RT_SCOPE_UNIVERSE;
nlm->rt.rtm_dst_len = inet_ntocidr(*netmask);
add_attr_l(&nlm->hdr, sizeof(*nlm), RTA_DST,
- &destination->s_addr, sizeof(destination->s_addr));
+ &destination->s_addr, sizeof(destination->s_addr));
if (nlm->rt.rtm_protocol == RTPROT_KERNEL) {
add_attr_l(&nlm->hdr, sizeof(*nlm), RTA_PREFSRC,
- &iface->addr.s_addr, sizeof(iface->addr.s_addr));
+ &iface->addr.s_addr, sizeof(iface->addr.s_addr));
}
/* If destination == gateway then don't add the gateway */
if (destination->s_addr != gateway->s_addr ||
netmask->s_addr != INADDR_BROADCAST)
add_attr_l(&nlm->hdr, sizeof(*nlm), RTA_GATEWAY,
- &gateway->s_addr, sizeof(gateway->s_addr));
+ &gateway->s_addr, sizeof(gateway->s_addr));
add_attr_32(&nlm->hdr, sizeof(*nlm), RTA_OIF, ifindex);
add_attr_32(&nlm->hdr, sizeof(*nlm), RTA_PRIORITY, metric);
*p++ = '\0';
if (net != NULL &&
(sscanf(p, "%d", &i) != 1 ||
- inet_cidrtoaddr(i, net) != 0))
+ inet_cidrtoaddr(i, net) != 0))
{
syslog(LOG_ERR, "`%s' is not a valid CIDR", p);
return -1;
case 'h':
if (arg) {
s = parse_string(ifo->hostname,
- HOSTNAME_MAX_LEN, arg);
+ HOSTNAME_MAX_LEN, arg);
if (s == -1) {
syslog(LOG_ERR, "hostname: %m");
return -1;
}
if (s != 0 && ifo->hostname[0] == '.') {
- syslog(LOG_ERR, "hostname cannot begin with .");
+ syslog(LOG_ERR,
+ "hostname cannot begin with .");
return -1;
}
ifo->hostname[s] = '\0';
case 'i':
if (arg)
s = parse_string((char *)ifo->vendorclassid + 1,
- VENDORCLASSID_MAX_LEN, arg);
+ VENDORCLASSID_MAX_LEN, arg);
else
s = 0;
if (s == -1) {
case 'l':
if (*arg == '-') {
syslog(LOG_ERR,
- "leasetime must be a positive value");
+ "leasetime must be a positive value");
return -1;
}
errno = 0;
ifo->request_address.s_addr = 0;
} else {
if (parse_addr(&ifo->request_address,
- &ifo->request_netmask,
- arg) != 0)
+ &ifo->request_netmask,
+ arg) != 0)
return -1;
}
break;
break;
case 'u':
s = USERCLASS_MAX_LEN - ifo->userclass[0] - 1;
- s = parse_string((char *)ifo->userclass + ifo->userclass[0] + 2,
- s, arg);
+ s = parse_string((char *)ifo->userclass +
+ ifo->userclass[0] + 2,
+ s, arg);
if (s == -1) {
syslog(LOG_ERR, "userclass: %m");
return -1;
arg = p + 1;
if (i < 1 || i > 254) {
syslog(LOG_ERR, "vendor option should be between"
- " 1 and 254 inclusive");
+ " 1 and 254 inclusive");
return -1;
}
s = VENDOR_MAX_LEN - ifo->vendor[0] - 2;
errno = ENOBUFS;
} else
memcpy(ifo->vendor + ifo->vendor[0] + 3,
- &addr.s_addr, sizeof(addr.s_addr));
+ &addr.s_addr, sizeof(addr.s_addr));
} else {
- s = parse_string((char *)ifo->vendor + ifo->vendor[0] + 3,
- s, arg);
+ s = parse_string((char *)ifo->vendor +
+ ifo->vendor[0] + 3, s, arg);
}
if (s == -1) {
syslog(LOG_ERR, "vendor: %m");
ifo->clientid[1] = 0;
if (arg)
s = parse_string_hwaddr((char *)ifo->clientid + 1,
- CLIENTID_MAX_LEN, arg, 1);
+ CLIENTID_MAX_LEN, arg, 1);
else
s = 0;
if (s == -1) {
p++;
if (strncmp(arg, "ip_address=", strlen("ip_address=")) == 0) {
if (parse_addr(&ifo->request_address,
- &ifo->request_netmask, p) != 0)
+ &ifo->request_netmask, p) != 0)
return -1;
ifo->options |= DHCPCD_STATIC;
} else if (strncmp(arg, "routes=", strlen("routes=")) == 0 ||
- strncmp(arg, "static_routes=", strlen("static_routes=")) == 0 ||
- strncmp(arg, "classless_static_routes=", strlen("classless_static_routes=")) == 0 ||
- strncmp(arg, "ms_classless_static_routes=", strlen("ms_classless_static_routes=")) == 0)
+ strncmp(arg, "static_routes=", strlen("static_routes=")) == 0 ||
+ strncmp(arg, "classless_static_routes=", strlen("classless_static_routes=")) == 0 ||
+ strncmp(arg, "ms_classless_static_routes=", strlen("ms_classless_static_routes=")) == 0)
{
np = strchr(p, ' ');
if (np == NULL) {
s = 0;
if (ifo->config != NULL) {
while (ifo->config[s] != NULL) {
- if (strncmp(ifo->config[s], arg, p - arg) == 0) {
- printf("match\n");
+ if (strncmp(ifo->config[s], arg,
+ p - arg) == 0)
+ {
free(ifo->config[s]);
ifo->config[s] = xstrdup(arg);
return 1;
s++;
}
}
- ifo->config = xrealloc(ifo->config, sizeof(char *) * (s + 2));
+ ifo->config = xrealloc(ifo->config,
+ sizeof(char *) * (s + 2));
ifo->config[s] = xstrdup(arg);
ifo->config[s + 1] = NULL;
}
case 'X':
if (!inet_aton(arg, &addr)) {
syslog(LOG_ERR, "`%s' is not a valid IP address",
- arg);
+ arg);
return -1;
}
ifo->blacklist = xrealloc(ifo->blacklist,
if (cf_options[i].has_arg == required_argument && !line) {
fprintf(stderr,
- PACKAGE ": option requires an argument -- %s\n",
- opt);
+ PACKAGE ": option requires an argument -- %s\n",
+ opt);
return -1;
}
strcmp(ifo->hostname, "localhost") == 0)
ifo->hostname[0] = '\0';
ifo->vendorclassid[0] = snprintf((char *)ifo->vendorclassid + 1,
- VENDORCLASSID_MAX_LEN,
- "%s %s", PACKAGE, VERSION);
+ VENDORCLASSID_MAX_LEN,
+ "%s %s", PACKAGE, VERSION);
/* Parse our options file */
f = fopen(file ? file : CONFIG, "r");
if (line && *line) {
p = line + strlen(line) - 1;
while (p != line &&
- (*p == ' ' || *p == '\t') &&
- *(p - 1) != '\\')
+ (*p == ' ' || *p == '\t') &&
+ *(p - 1) != '\\')
*p-- = '\0';
}
/* Start of an interface block, skip if not ours */
for (;;) {
dhcp->yiaddr = htonl(LINKLOCAL_ADDR |
- (((uint32_t)abs((int)arc4random())
- % 0xFD00) + 0x0100));
+ (((uint32_t)abs((int)arc4random())
+ % 0xFD00) + 0x0100));
if (dhcp->yiaddr != old_addr &&
IN_LINKLOCAL(ntohl(dhcp->yiaddr)))
break;
if (!iface->state->offer ||
!IN_LINKLOCAL(htonl(iface->state->offer->yiaddr)))
{
- syslog(LOG_INFO, "%s: probing for an IPv4LL address", iface->name);
+ syslog(LOG_INFO, "%s: probing for an IPv4LL address",
+ iface->name);
delete_timeout(NULL, iface);
free(iface->state->offer);
iface->state->offer = make_ipv4ll_lease(0);
iface->state->offer = NULL;
if (++iface->state->conflicts > MAX_CONFLICTS) {
syslog(LOG_ERR, "%s: failed to acquire an IPv4LL address",
- iface->name);
+ iface->name);
iface->state->interval = RATE_LIMIT_INTERVAL / 2;
start_discover(iface);
} else {
/* Broadcast address for IPoIB */
static const uint8_t ipv4_bcast_addr[] = {
0x00, 0xff, 0xff, 0xff,
- 0xff, 0x12, 0x40, 0x1b, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff
+ 0xff, 0x12, 0x40, 0x1b, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff
};
int
ssize_t
send_raw_packet(const struct interface *iface, int protocol,
- const void *data, ssize_t len)
+ const void *data, ssize_t len)
{
union sockunion {
struct sockaddr sa;
su.sll.sll_halen = iface->hwlen;
if (iface->family == ARPHRD_INFINIBAND)
memcpy(&su.sll.sll_addr,
- &ipv4_bcast_addr, sizeof(ipv4_bcast_addr));
+ &ipv4_bcast_addr, sizeof(ipv4_bcast_addr));
else
memset(&su.sll.sll_addr, 0xff, iface->hwlen);
if (protocol == ETHERTYPE_ARP)
cidr++;
mask <<= 1;
}
-
return cidr;
}
addr->s_addr = 0;
if (ocets > 0) {
memset(&addr->s_addr, 255, (size_t)ocets - 1);
- memset((unsigned char *)&addr->s_addr + (ocets - 1),
- (256 - (1 << (32 - cidr) % 8)), 1);
+
+ memset((unsigned char *)&addr->s_addr + (ocets - 1),
+ (256 - (1 << (32 - cidr) % 8)), 1);
}
return 0;
default:
/* Don't needlessly spam console on startup */
if (!(options & DHCPCD_MASTER &&
- !(options & DHCPCD_DAEMONISED) &&
- options & DHCPCD_QUIET))
+ !(options & DHCPCD_DAEMONISED) &&
+ options & DHCPCD_QUIET))
syslog(LOG_ERR, "%s: unsupported media family",
- iface->name);
+ iface->name);
goto eexit;
}
memcpy(iface->hwaddr, ifr.ifr_hwaddr.sa_data, iface->hwlen);
if (up_interface(ifname) != 0)
goto eexit;
snprintf(iface->leasefile, sizeof(iface->leasefile),
- LEASEFILE, ifname);
+ LEASEFILE, ifname);
iface->arpable = arpable;
/* 0 is a valid fd, so init to -1 */
iface->raw_fd = -1;
int
do_interface(const char *ifname,
- void (*do_link)(struct interface **, int, char * const *, struct ifreq *),
- struct interface **ifs, int argc, char * const *argv,
- struct in_addr *addr, struct in_addr *net, int act)
+ void (*do_link)(struct interface **, int, char * const *, struct ifreq *),
+ struct interface **ifs, int argc, char * const *argv,
+ struct in_addr *addr, struct in_addr *net, int act)
{
int s;
struct ifconf ifc;
#ifndef __linux__
if (ifr->ifr_addr.sa_len > sizeof(ifr->ifr_ifru))
p += offsetof(struct ifreq, ifr_ifru) +
- ifr->ifr_addr.sa_len;
+ ifr->ifr_addr.sa_len;
else
#endif
p += sizeof(*ifr);
p = strchr(ifr.ifr_name, ':');
if (p)
*p = '\0';
- if (setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) == -1)
+ if (setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, &ifr,
+ sizeof(ifr)) == -1)
goto eexit;
#endif
/* As we don't use this socket for receiving, set the
ssize_t
send_packet(const struct interface *iface, struct in_addr to,
- const uint8_t *data, ssize_t len)
+ const uint8_t *data, ssize_t len)
{
struct sockaddr_in sin;
sin.sin_addr.s_addr = to.s_addr;
sin.sin_port = htons(DHCP_SERVER_PORT);
return sendto(iface->udp_fd, data, len, 0,
- (struct sockaddr *)&sin, sizeof(sin));
+ (struct sockaddr *)&sin, sizeof(sin));
}
struct udp_dhcp_packet
ssize_t
make_udp_packet(uint8_t **packet, const uint8_t *data, size_t length,
- struct in_addr source, struct in_addr dest)
+ struct in_addr source, struct in_addr dest)
{
struct udp_dhcp_packet *udpp;
struct ip *ip;
memcpy(&packet, udp, sizeof(packet));
*data = udp + offsetof(struct udp_dhcp_packet, dhcp);
- return ntohs(packet.ip.ip_len) - sizeof(packet.ip) - sizeof(packet.udp);
+ return ntohs(packet.ip.ip_len) -
+ sizeof(packet.ip) -
+ sizeof(packet.udp);
}
int
static const int handle_sigs[] = {
SIGALRM,
- SIGHUP,
- SIGINT,
- SIGPIPE,
- SIGTERM
+ SIGHUP,
+ SIGINT,
+ SIGPIPE,
+ SIGTERM
};
static void