diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2017-07-22 17:55:21 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2017-07-22 17:55:21 +0000 |
commit | 7d9fba71442eb742c6318960049db385fa766b75 (patch) | |
tree | a1fc5a359201262a7caab30f972e734c2cc34d47 /sbin | |
parent | 431a3ec9878798da2ce3a3c85b432c5a93b08e15 (diff) |
Add set_routes() and move bind_lease() route magic
into it. Swap parameter order in add_default_route() to
be consistant with other add_*_route() functions.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/dhclient/dhclient.c | 51 | ||||
-rw-r--r-- | sbin/dhclient/dhcpd.h | 4 | ||||
-rw-r--r-- | sbin/dhclient/kroute.c | 43 |
3 files changed, 53 insertions, 45 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 0385e98afb2..3837900fe8e 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.477 2017/07/22 15:34:22 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.478 2017/07/22 17:55:20 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -880,8 +880,6 @@ dhcpnak(struct interface_info *ifi, struct option_data *options, char *info) void bind_lease(struct interface_info *ifi) { - struct in_addr gateway, mask; - struct option_data *opt; struct option_data *options; struct client_lease *lease, *pl; struct proposal *active_proposal = NULL; @@ -934,47 +932,16 @@ bind_lease(struct interface_info *ifi) delete_addresses(ifi->name); flush_routes(); - opt = &options[DHO_INTERFACE_MTU]; - set_mtu(opt); - - opt = &options[DHO_SUBNET_MASK]; - set_address(ifi->active->address, opt); + set_mtu(&options[DHO_INTERFACE_MTU]); - if (options[DHO_CLASSLESS_STATIC_ROUTES].len != 0) { - add_classless_static_routes( - &options[DHO_CLASSLESS_STATIC_ROUTES], - ifi->active->address); - } else if (options[DHO_CLASSLESS_MS_STATIC_ROUTES].len != 0) { - add_classless_static_routes( - &options[DHO_CLASSLESS_MS_STATIC_ROUTES], - ifi->active->address); - } else { - opt = &options[DHO_ROUTERS]; - if (opt->len >= sizeof(gateway)) { - /* XXX Only use FIRST router address for now. */ - gateway.s_addr = ((struct in_addr *)opt->data)->s_addr; - - /* - * To be compatible with ISC DHCP behavior on Linux, if - * we were given a /32 IP assignment, then add a /32 - * direct route for the gateway to make it routable. - */ - opt = &options[DHO_SUBNET_MASK]; - if (opt->len == sizeof(mask)) { - mask.s_addr = ((struct in_addr *) - opt->data)->s_addr; - if (mask.s_addr == INADDR_BROADCAST) { - add_direct_route(gateway, mask, - ifi->active->address); - } - } + set_address(ifi->active->address, &options[DHO_SUBNET_MASK]); - add_default_route(ifi->active->address, gateway); - } - if (options[DHO_STATIC_ROUTES].len != 0) - add_static_routes(&options[DHO_STATIC_ROUTES], - ifi->active->address); - } + set_routes(ifi->active->address, + &options[DHO_CLASSLESS_STATIC_ROUTES], + &options[DHO_CLASSLESS_MS_STATIC_ROUTES], + &options[DHO_ROUTERS], + &options[DHO_STATIC_ROUTES], + &options[DHO_SUBNET_MASK]); newlease: log_info("bound to %s -- renewal in %lld seconds.", diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 3431f5f5a70..71cd4b40867 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.214 2017/07/22 14:56:27 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.215 2017/07/22 17:55:20 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -239,6 +239,8 @@ void delete_address(struct in_addr); void set_mtu(struct option_data *); void set_address(struct in_addr, struct option_data *); +void set_routes(struct in_addr, struct option_data *, struct option_data *, + struct option_data *, struct option_data *, struct option_data *); void flush_routes(void); diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c index 6bf8067cdd8..e38044d2287 100644 --- a/sbin/dhclient/kroute.c +++ b/sbin/dhclient/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.112 2017/07/22 14:56:27 krw Exp $ */ +/* $OpenBSD: kroute.c,v 1.113 2017/07/22 17:55:20 krw Exp $ */ /* * Copyright 2012 Kenneth R Westerback <krw@openbsd.org> @@ -272,7 +272,7 @@ add_direct_route(struct in_addr dest, struct in_addr mask, * route -q $rdomain add default $router */ void -add_default_route(struct in_addr addr, struct in_addr gateway) +add_default_route(struct in_addr gateway, struct in_addr addr) { struct in_addr netmask, dest; int addrs, flags; @@ -396,6 +396,45 @@ create_route_label(struct sockaddr_rtlabel *label) return 0; } +void +set_routes(struct in_addr addr, struct option_data *classless, + struct option_data *msclassless, struct option_data *routers, + struct option_data *classfull, struct option_data *subnet) +{ + struct in_addr gateway, mask; + + if (classless->len != 0) { + add_classless_static_routes(classless, addr); + return; + } + + if (msclassless->len != 0) { + add_classless_static_routes(msclassless, addr); + return; + } + + if (routers->len >= sizeof(gateway)) { + /* XXX Only use FIRST router address for now. */ + gateway.s_addr = ((struct in_addr *)routers->data)->s_addr; + + /* + * To be compatible with ISC DHCP behavior on Linux, if + * we were given a /32 IP assignment, then add a /32 + * direct route for the gateway to make it routable. + */ + if (subnet->len == sizeof(mask)) { + mask.s_addr = ((struct in_addr *)subnet->data)->s_addr; + if (mask.s_addr == INADDR_BROADCAST) + add_direct_route(gateway, mask, addr); + } + + add_default_route(gateway, addr); + } + + if (classfull->len != 0) + add_static_routes(classfull, addr); +} + /* * [priv_]add_route() add a single route to the routing table. */ |