diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2013-06-01 16:26:08 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2013-06-01 16:26:08 +0000 |
commit | aedbb718fa5c0cf868beadc84888f716aa40a518 (patch) | |
tree | 0bef5f44660b9c5e475e49e6f6af085ec397aa4f /sbin/dhclient/dhclient.c | |
parent | 51a166362649e2fe7de4dd395ebd8018574499c0 (diff) |
Refactor the default route adding code to use a general route adding
function that will be reused for future work.
ok claudio@
Diffstat (limited to 'sbin/dhclient/dhclient.c')
-rw-r--r-- | sbin/dhclient/dhclient.c | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index a3f4900f36c..7c98573da33 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.247 2013/05/05 16:45:01 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.248 2013/06/01 16:26:07 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -108,6 +108,8 @@ struct client_lease *clone_lease(struct client_lease *); void socket_nonblockmode(int); void apply_ignore_list(char *); +void add_default_route(int, struct in_addr, struct in_addr); + #define ROUNDUP(a) \ ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) #define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len)) @@ -2263,3 +2265,42 @@ priv_write_file(struct imsg_write_file *imsg) close(fd); } + +/* + * add_default_route is the equivalent of + * + * route -q $rdomain add default -iface $router + * + * or + * + * route -q $rdomain add default $router + * + * depending on the contents of the gateway parameter. + */ +void +add_default_route(int rdomain, struct in_addr addr, struct in_addr gateway) +{ + struct imsg_add_route imsg; + int rslt; + + memset(&imsg, 0, sizeof(imsg)); + + imsg.rdomain = rdomain; + imsg.dest = addr; + imsg.addrs = RTA_DST | RTA_NETMASK; + + /* + * Set gateway address if and only if non-zero addr supplied. A + * gateway address of 0 implies '-iface'. + */ + if (bcmp(&gateway, &addr, sizeof(addr)) != 0) { + imsg.gateway = gateway; + imsg.addrs |= RTA_GATEWAY; + } + + rslt = imsg_compose(unpriv_ibuf, IMSG_ADD_ROUTE, 0, 0, -1, &imsg, + sizeof(imsg)); + + if (rslt == -1) + warning("add_route: imsg_compose: %s", strerror(errno)); +} |