diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2015-02-10 04:20:27 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2015-02-10 04:20:27 +0000 |
commit | 7fc0f9ee39dfdb1e0afacd8f4c9d2741fa79bce5 (patch) | |
tree | d7680d581b532e4aa24531706885fcd503164fae /sbin | |
parent | 08e65b9018e7e47927597b2a9c649599efe72bfe (diff) |
Groundwork for better route support over multiple interfaces by
using RTM_IFA to bind routes to an interface. Keep the subnet route
conflict avoidance code for the time being.
diff from claudio@ as part of larger routing magic diff.
ok claudio@ mpi@
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/dhclient/dhclient.c | 25 | ||||
-rw-r--r-- | sbin/dhclient/dhcpd.h | 5 | ||||
-rw-r--r-- | sbin/dhclient/kroute.c | 24 | ||||
-rw-r--r-- | sbin/dhclient/privsep.h | 3 |
4 files changed, 38 insertions, 19 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 4bba00a1524..e407b9831db 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.357 2015/02/07 10:08:06 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.358 2015/02/10 04:20:26 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -108,7 +108,7 @@ void apply_ignore_list(char *); void add_direct_route(struct in_addr, struct in_addr, struct in_addr); void add_default_route(struct in_addr, struct in_addr); -void add_static_routes(struct option_data *); +void add_static_routes(struct option_data *, struct in_addr); void add_classless_static_routes(struct option_data *, struct in_addr); int compare_lease(struct client_lease *, struct client_lease *); @@ -964,7 +964,8 @@ bind_lease(void) add_default_route(client->active->address, gateway); } if (options[DHO_STATIC_ROUTES].len) - add_static_routes(&options[DHO_STATIC_ROUTES]); + add_static_routes(&options[DHO_STATIC_ROUTES], + client->active->address); } newlease: @@ -2443,7 +2444,9 @@ priv_write_file(char *path, int flags, mode_t mode, uid_t uid, gid_t gid, void add_direct_route(struct in_addr dest, struct in_addr mask, struct in_addr iface) { - add_route(dest, mask, iface, + struct in_addr ifa = { INADDR_ANY }; + + add_route(dest, mask, iface, ifa, RTA_DST | RTA_NETMASK | RTA_GATEWAY, RTF_CLONING | RTF_STATIC); } @@ -2473,15 +2476,15 @@ add_default_route(struct in_addr addr, struct in_addr gateway) * claiming there is no gateway address to use. */ if (bcmp(&gateway, &addr, sizeof(addr)) != 0) { - addrs |= RTA_GATEWAY; + addrs |= RTA_GATEWAY | RTA_IFA; flags |= RTF_GATEWAY | RTF_STATIC; } - add_route(dest, netmask, gateway, addrs, flags); + add_route(dest, netmask, gateway, addr, addrs, flags); } void -add_static_routes(struct option_data *static_routes) +add_static_routes(struct option_data *static_routes, struct in_addr iface) { struct in_addr dest, netmask, gateway; struct in_addr *addr; @@ -2499,8 +2502,8 @@ add_static_routes(struct option_data *static_routes) gateway.s_addr = (addr+1)->s_addr; /* XXX Order implies priority but we're ignoring that. */ - add_route(dest, netmask, gateway, - RTA_DST | RTA_GATEWAY, RTF_GATEWAY | RTF_STATIC); + add_route(dest, netmask, gateway, iface, + RTA_DST | RTA_GATEWAY | RTA_IFA, RTF_GATEWAY | RTF_STATIC); } } @@ -2537,8 +2540,8 @@ add_classless_static_routes(struct option_data *opt, struct in_addr iface) if (gateway.s_addr == INADDR_ANY) add_direct_route(dest, netmask, iface); else - add_route(dest, netmask, gateway, - RTA_DST | RTA_GATEWAY | RTA_NETMASK, + add_route(dest, netmask, gateway, iface, + RTA_DST | RTA_GATEWAY | RTA_NETMASK | RTA_IFA, RTF_GATEWAY | RTF_STATIC); } } diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 3b9d736e2dd..c773eef5c44 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.148 2015/02/07 02:07:32 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.149 2015/02/10 04:20:26 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -301,7 +301,8 @@ void add_address(struct in_addr, struct in_addr); void flush_routes(void); -void add_route(struct in_addr, struct in_addr, struct in_addr, int, int); +void add_route(struct in_addr, struct in_addr, struct in_addr, struct in_addr, + int, int); void sendhup(struct client_lease *); diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c index b899bd331b2..3a47c39f476 100644 --- a/sbin/dhclient/kroute.c +++ b/sbin/dhclient/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.74 2015/02/08 01:20:40 krw Exp $ */ +/* $OpenBSD: kroute.c,v 1.75 2015/02/10 04:20:26 krw Exp $ */ /* * Copyright 2012 Kenneth R Westerback <krw@openbsd.org> @@ -162,8 +162,8 @@ priv_flush_routes(struct imsg_flush_routes *imsg) } void -add_route(struct in_addr dest, struct in_addr netmask, struct in_addr gateway, - int addrs, int flags) +add_route(struct in_addr dest, struct in_addr netmask, + struct in_addr gateway, struct in_addr ifa, int addrs, int flags) { struct imsg_add_route imsg; int rslt; @@ -171,6 +171,7 @@ add_route(struct in_addr dest, struct in_addr netmask, struct in_addr gateway, imsg.dest = dest; imsg.gateway = gateway; imsg.netmask = netmask; + imsg.ifa = ifa; imsg.addrs = addrs; imsg.flags = flags; @@ -186,9 +187,9 @@ void priv_add_route(struct imsg_add_route *imsg) { struct rt_msghdr rtm; - struct sockaddr_in dest, gateway, mask; + struct sockaddr_in dest, gateway, mask, ifa; struct sockaddr_rtlabel label; - struct iovec iov[5]; + struct iovec iov[6]; int s, i, iovcnt = 0; if ((s = socket(AF_ROUTE, SOCK_RAW, 0)) == -1) @@ -248,6 +249,19 @@ priv_add_route(struct imsg_add_route *imsg) iov[iovcnt++].iov_len = sizeof(mask); } + if (imsg->addrs & RTA_IFA) { + memset(&ifa, 0, sizeof(ifa)); + + ifa.sin_len = sizeof(ifa); + ifa.sin_family = AF_INET; + ifa.sin_addr.s_addr = imsg->ifa.s_addr; + + rtm.rtm_msglen += sizeof(ifa); + + iov[iovcnt].iov_base = &ifa; + iov[iovcnt++].iov_len = sizeof(ifa); + } + /* Add our label so we can identify the route as our creation. */ if (create_route_label(&label) == 0) { rtm.rtm_addrs |= RTA_LABEL; diff --git a/sbin/dhclient/privsep.h b/sbin/dhclient/privsep.h index 34bcb64cd3a..d9215dc6867 100644 --- a/sbin/dhclient/privsep.h +++ b/sbin/dhclient/privsep.h @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep.h,v 1.27 2015/02/07 10:08:06 krw Exp $ */ +/* $OpenBSD: privsep.h,v 1.28 2015/02/10 04:20:26 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -49,6 +49,7 @@ struct imsg_add_route { struct in_addr dest; struct in_addr netmask; struct in_addr gateway; + struct in_addr ifa; int addrs; int flags; }; |