From 0427b5aa560532d3c58c57c887e565b4fd7dceb5 Mon Sep 17 00:00:00 2001 From: Peter Hessler Date: Wed, 2 Jun 2010 09:57:17 +0000 Subject: Have dhclient obey the interface's rdomain, instead of doing routes on rdomain 0. OK krw@, claudio@ sharp stick prodding from claudio@ --- sbin/dhclient/dhclient-script | 22 +++++++++++----------- sbin/dhclient/dhclient.c | 13 ++++++++++++- sbin/dhclient/dhcpd.h | 4 +++- sbin/dhclient/dispatch.c | 25 ++++++++++++++++++++++++- 4 files changed, 50 insertions(+), 14 deletions(-) (limited to 'sbin') diff --git a/sbin/dhclient/dhclient-script b/sbin/dhclient/dhclient-script index adc1212be75..06001d3f835 100644 --- a/sbin/dhclient/dhclient-script +++ b/sbin/dhclient/dhclient-script @@ -1,6 +1,6 @@ #!/bin/sh # -# $OpenBSD: dhclient-script,v 1.16 2010/04/04 22:53:50 jsg Exp $ +# $OpenBSD: dhclient-script,v 1.17 2010/06/02 09:57:16 phessler Exp $ # # Copyright (c) 2003 Kenneth R Westerback # @@ -24,7 +24,7 @@ delete_old_address() { if [ -n "$old_ip_address" ]; then ifconfig $interface inet $old_ip_address delete $medium - route delete "$old_ip_address" 127.0.0.1 >/dev/null 2>&1 + route $rdomain delete "$old_ip_address" 127.0.0.1 >/dev/null 2>&1 fi } @@ -42,7 +42,7 @@ add_new_address() { $medium # XXX Original TIMEOUT code did not do this unless $new_routers was set? - route add $new_ip_address 127.0.0.1 >/dev/null 2>&1 + route $rdomain add $new_ip_address 127.0.0.1 >/dev/null 2>&1 } ip6_add_new_address() { @@ -56,7 +56,7 @@ delete_old_alias() { if [ -n "$alias_ip_address" ]; then ifconfig $interface \ inet $alias_ip_address delete > /dev/null 2>&1 - route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1 + route $rdomain delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1 fi } @@ -64,19 +64,19 @@ add_new_alias() { if [ -n "$alias_ip_address" ]; then ifconfig $interface inet $alias_ip_address alias netmask \ $alias_subnet_mask - route add $alias_ip_address 127.0.0.1 + route $rdomain add $alias_ip_address 127.0.0.1 fi } delete_old_routes() { # Delete existing default route. We only allow one, so no need to # process $old_routers list. - route -n flush -inet -iface $interface >/dev/null 2>&1 + route $rdomain -n flush -inet -iface $interface >/dev/null 2>&1 if [ -n "$old_static_routes" ]; then set $old_static_routes while [ $# -gt 1 ]; do - route delete "$1" "$2" + route $rdomain delete "$1" "$2" shift; shift done fi @@ -85,12 +85,12 @@ delete_old_routes() { } add_new_routes() { - route -n flush -inet -iface $interface >/dev/null 2>&1 + route $rdomain -n flush -inet -iface $interface >/dev/null 2>&1 for router in $new_routers; do if [ "$new_ip_address" = "$router" ]; then - route add default -iface $router >/dev/null 2>&1 + route $rdomain add default -iface $router >/dev/null 2>&1 else - route add default $router >/dev/null 2>&1 + route $rdomain add default $router >/dev/null 2>&1 fi # 2nd and subsequent default routers error out, so explicitly # stop processing the list after the first one. @@ -100,7 +100,7 @@ add_new_routes() { if [ -n "$new_static_routes" ]; then set $new_static_routes while [ $# -gt 1 ]; do - route add $1 $2 + route $rdomain add $1 $2 shift; shift done fi diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 5f5fae7b7c8..5c1926956ec 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.133 2010/03/25 18:37:36 stevesk Exp $ */ +/* $OpenBSD: dhclient.c,v 1.134 2010/06/02 09:57:16 phessler Exp $ */ /* * Copyright 2004 Henning Brauer @@ -336,6 +336,9 @@ main(int argc, char *argv[]) sockaddr_broadcast.sin_len = sizeof(sockaddr_broadcast); inaddr_any.s_addr = INADDR_ANY; + /* Put us into the correct rdomain */ + ifi->rdomain = get_rdomain(ifi->name); + read_client_conf(); if (interface_status(ifi->name) == 0) { @@ -1589,6 +1592,8 @@ script_init(char *reason, struct string_list *medium) void priv_script_init(char *reason, char *medium) { + char *rdomain; + client->scriptEnvsize = 100; if (client->scriptEnv == NULL) client->scriptEnv = @@ -1604,6 +1609,12 @@ priv_script_init(char *reason, char *medium) script_set_env("", "interface", ifi->name); + if (asprintf(&rdomain, "-T %d", ifi->rdomain) == -1) + error("script_init: no memory for environment"); + + script_set_env("", "rdomain", rdomain); + free(rdomain); + if (medium) script_set_env("", "medium", medium); diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index bbcd1dd513f..53841d9ff0c 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.69 2009/06/06 04:02:42 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.70 2010/06/02 09:57:16 phessler Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -191,6 +191,7 @@ struct interface_info { int errors; u_int16_t index; int linkstat; + int rdomain; }; struct timeout { @@ -261,6 +262,7 @@ int interface_link_status(char *); int interface_status(char *); int interface_link_forceup(char *); void interface_link_forcedown(char *); +int get_rdomain(char *); /* tables.c */ extern const struct option dhcp_options[256]; diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c index 0a798596de4..d1302f09fed 100644 --- a/sbin/dhclient/dispatch.c +++ b/sbin/dhclient/dispatch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dispatch.c,v 1.45 2009/11/26 23:14:29 krw Exp $ */ +/* $OpenBSD: dispatch.c,v 1.46 2010/06/02 09:57:16 phessler Exp $ */ /* * Copyright 2004 Henning Brauer @@ -134,6 +134,11 @@ another: if (!ifi->linkstat) interfaces_invalidated = 0; + if (ifi->rdomain != get_rdomain(ifi->name)) + error("Interface %s:" + " rdomain changed out from under us", + ifi->name); + if (timeouts) { struct timeout *t; @@ -448,3 +453,21 @@ interface_link_status(char *ifname) } return (1); } + +int +get_rdomain(char *name) +{ + int rv = 0, s; + struct ifreq ifr; + + if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) + error("get_rdomain socket: %m"); + + bzero(&ifr, sizeof(ifr)); + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + if (ioctl(s, SIOCGIFRTABLEID, (caddr_t)&ifr) != -1) + rv = ifr.ifr_rdomainid; + + close(s); + return rv; +} -- cgit v1.2.3