diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2013-06-09 22:39:52 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2013-06-09 22:39:52 +0000 |
commit | c8aee3f8eca3a7d57d397dfa65f33e265ec49aa5 (patch) | |
tree | 33718a63d75d82a09f9a60fe024d70b88a2dd846 | |
parent | 80d641b141f400d2697c55e7420e673e2911ebcb (diff) |
Make route adding interface more flexible by passing flags to be
used rather than deducing them. Use priv_add_route() to add
the 127.0.0.1 address when adding an address.
-rw-r--r-- | sbin/dhclient/dhclient.c | 18 | ||||
-rw-r--r-- | sbin/dhclient/dhcpd.h | 4 | ||||
-rw-r--r-- | sbin/dhclient/kroute.c | 91 | ||||
-rw-r--r-- | sbin/dhclient/privsep.h | 3 |
4 files changed, 28 insertions, 88 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index dc0feac7bff..fb3b3cd0122 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.253 2013/06/09 17:31:54 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.254 2013/06/09 22:39:51 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -2290,21 +2290,24 @@ void add_default_route(int rdomain, struct in_addr addr, struct in_addr gateway) { struct in_addr netmask, dest; - int addrs; + int addrs, flags; memset(&netmask, 0, sizeof(netmask)); memset(&dest, 0, sizeof(dest)); addrs = RTA_DST | RTA_NETMASK; + flags = 0; /* * When 'addr' and 'gateway' are identical the desired behaviour is * to emulate the '-iface' variant of 'route'. This is done by * claiming there is no gateway address to use. */ - if (bcmp(&gateway, &addr, sizeof(addr)) != 0) + if (bcmp(&gateway, &addr, sizeof(addr)) != 0) { addrs |= RTA_GATEWAY; + flags |= RTF_GATEWAY | RTF_STATIC; + } - add_route(rdomain, dest, netmask, gateway, addrs); + add_route(rdomain, dest, netmask, gateway, addrs, flags); } void @@ -2314,7 +2317,7 @@ add_static_routes(int rdomain, struct option_data *static_routes) u_int8_t *addr; int i; - memset(&netmask, 0, sizeof(netmask)); /* Always 0 for class addrs. */ + memset(&netmask, 0, sizeof(netmask)); /* Not used for CLASSFULL! */ for (i = 0; (i + 7) < static_routes->len; i += 8) { addr = &static_routes->data[i]; @@ -2328,7 +2331,7 @@ add_static_routes(int rdomain, struct option_data *static_routes) /* XXX Order implies priority but we're ignoring that. */ add_route(rdomain, dest, netmask, gateway, - RTA_DST | RTA_GATEWAY); + RTA_DST | RTA_GATEWAY, RTF_GATEWAY | RTF_STATIC); } } @@ -2361,6 +2364,7 @@ void add_classless_static_routes(int rdomain, continue; /* OBSD TCP/IP doesn't support this. */ add_route(rdomain, dest, netmask, gateway, - RTA_DST | RTA_GATEWAY | RTA_NETMASK); + RTA_DST | RTA_GATEWAY | RTA_NETMASK, + RTF_GATEWAY | RTF_STATIC); } } diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 26b15b88a9b..282bb8795a7 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.120 2013/06/09 15:06:34 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.121 2013/06/09 22:39:51 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -343,4 +343,4 @@ void add_address(char *, int, struct in_addr, struct in_addr); void flush_routes(char *, int); -void add_route(int, struct in_addr, struct in_addr, struct in_addr, int); +void add_route(int, struct in_addr, struct in_addr, struct in_addr, int, int); diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c index 2b40fd26993..eda78953b6f 100644 --- a/sbin/dhclient/kroute.c +++ b/sbin/dhclient/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.53 2013/06/09 17:31:54 krw Exp $ */ +/* $OpenBSD: kroute.c,v 1.54 2013/06/09 22:39:51 krw Exp $ */ /* * Copyright 2012 Kenneth R Westerback <krw@openbsd.org> @@ -172,7 +172,7 @@ priv_flush_routes(struct imsg_flush_routes *imsg) void add_route(int rdomain, struct in_addr dest, struct in_addr netmask, - struct in_addr gateway, int addrs) + struct in_addr gateway, int addrs, int flags) { struct imsg_add_route imsg; int rslt; @@ -184,6 +184,7 @@ add_route(int rdomain, struct in_addr dest, struct in_addr netmask, imsg.gateway = gateway; imsg.netmask = netmask; imsg.addrs = addrs; + imsg.flags = flags; rslt = imsg_compose(unpriv_ibuf, IMSG_ADD_ROUTE, 0, 0, -1, &imsg, sizeof(imsg)); @@ -213,6 +214,8 @@ priv_add_route(struct imsg_add_route *imsg) rtm.rtm_tableid = imsg->rdomain; rtm.rtm_priority = RTP_NONE; rtm.rtm_msglen = sizeof(rtm); + rtm.rtm_addrs = imsg->addrs; + rtm.rtm_flags = imsg->flags; iov[iovcnt].iov_base = &rtm; iov[iovcnt++].iov_len = sizeof(rtm); @@ -224,7 +227,6 @@ priv_add_route(struct imsg_add_route *imsg) dest.sin_family = AF_INET; dest.sin_addr.s_addr = imsg->dest.s_addr; - rtm.rtm_addrs |= RTA_DST; rtm.rtm_msglen += sizeof(dest); iov[iovcnt].iov_base = &dest; @@ -238,8 +240,6 @@ priv_add_route(struct imsg_add_route *imsg) gateway.sin_family = AF_INET; gateway.sin_addr.s_addr = imsg->gateway.s_addr; - rtm.rtm_flags |= RTF_GATEWAY | RTF_STATIC; - rtm.rtm_addrs |= RTA_GATEWAY; rtm.rtm_msglen += sizeof(gateway); iov[iovcnt].iov_base = &gateway; @@ -253,7 +253,6 @@ priv_add_route(struct imsg_add_route *imsg) mask.sin_family = AF_INET; mask.sin_addr.s_addr = imsg->netmask.s_addr; - rtm.rtm_addrs |= RTA_NETMASK; rtm.rtm_msglen += sizeof(mask); iov[iovcnt].iov_base = &mask; @@ -411,13 +410,10 @@ add_address(char *ifname, int rdomain, struct in_addr addr, void priv_add_address(struct imsg_add_address *imsg) { + struct imsg_add_route rimsg; struct ifaliasreq ifaliasreq; - struct rt_msghdr rtm; - struct sockaddr_in dest, gateway; - struct sockaddr_rtlabel label; - struct iovec iov[4]; struct sockaddr_in *in; - int s, i, iovcnt = 0; + int s; if (imsg->addr.s_addr == INADDR_ANY) { /* Notification that the active_addr has been deleted. */ @@ -460,74 +456,13 @@ priv_add_address(struct imsg_add_address *imsg) /* * Add the 127.0.0.1 route for the specified address. */ + memset(&rimsg, 0, sizeof(rimsg)); + rimsg.dest.s_addr = imsg->addr.s_addr; + rimsg.gateway.s_addr = inet_addr("127.0.0.1"); + rimsg.addrs = RTA_DST | RTA_GATEWAY; + rimsg.flags = RTF_GATEWAY | RTF_STATIC; - if ((s = socket(AF_ROUTE, SOCK_RAW, 0)) == -1) - error("Routing Socket open failed: %s", strerror(errno)); - - /* Build RTM header */ - - memset(&rtm, 0, sizeof(rtm)); - - rtm.rtm_version = RTM_VERSION; - rtm.rtm_type = RTM_ADD; - rtm.rtm_tableid = imsg->rdomain; - rtm.rtm_priority = RTP_NONE; - rtm.rtm_msglen = sizeof(rtm); - - iov[iovcnt].iov_base = &rtm; - iov[iovcnt++].iov_len = sizeof(rtm); - - /* Set destination address */ - - memset(&dest, 0, sizeof(dest)); - - dest.sin_len = sizeof(dest); - dest.sin_family = AF_INET; - dest.sin_addr.s_addr = imsg->addr.s_addr; - - rtm.rtm_addrs |= RTA_DST; - rtm.rtm_msglen += sizeof(dest); - - iov[iovcnt].iov_base = &dest; - iov[iovcnt++].iov_len = sizeof(dest); - - /* Set gateway address */ - - memset(&gateway, 0, sizeof(gateway)); - - gateway.sin_len = sizeof(gateway); - gateway.sin_family = AF_INET; - gateway.sin_addr.s_addr = inet_addr("127.0.0.1"); - - rtm.rtm_flags |= RTF_GATEWAY; - rtm.rtm_addrs |= RTA_GATEWAY; - rtm.rtm_msglen += sizeof(gateway); - - iov[iovcnt].iov_base = &gateway; - iov[iovcnt++].iov_len = sizeof(gateway); - - /* Add our label so we can identify the route as our creation. */ - if (create_route_label(&label) == 0) { - rtm.rtm_addrs |= RTA_LABEL; - rtm.rtm_msglen += sizeof(label); - iov[iovcnt].iov_base = &label; - iov[iovcnt++].iov_len = sizeof(label); - } - - /* Check for EEXIST since other dhclient may not be done. */ - for (i = 0; i < 5; i++) { - if (writev(s, iov, iovcnt) != -1) - break; - if (errno == ENETUNREACH) { - /* Not our responsibility to ensure 127/8 exists. */ - break; - } else if (errno != EEXIST) - error("failed to add 127.0.0.1 route: %s", - strerror(errno)); - sleep(1); - } - - close(s); + priv_add_route(&rimsg); active_addr = imsg->addr; } diff --git a/sbin/dhclient/privsep.h b/sbin/dhclient/privsep.h index c436fd09d34..4af9d745d7b 100644 --- a/sbin/dhclient/privsep.h +++ b/sbin/dhclient/privsep.h @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep.h,v 1.21 2013/06/09 15:06:34 krw Exp $ */ +/* $OpenBSD: privsep.h,v 1.22 2013/06/09 22:39:51 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -55,6 +55,7 @@ struct imsg_add_route { struct in_addr gateway; int rdomain; int addrs; + int flags; }; struct imsg_hup { |