summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorPeter Hessler <phessler@cvs.openbsd.org>2010-06-02 09:57:17 +0000
committerPeter Hessler <phessler@cvs.openbsd.org>2010-06-02 09:57:17 +0000
commit0427b5aa560532d3c58c57c887e565b4fd7dceb5 (patch)
tree06ba08307ddbe62058f5ca72c09cc5a1250e2ea6 /sbin
parent13b1162ae35520b2ef563914fff32ea410a4a485 (diff)
Have dhclient obey the interface's rdomain, instead of doing routes on
rdomain 0. OK krw@, claudio@ sharp stick prodding from claudio@
Diffstat (limited to 'sbin')
-rw-r--r--sbin/dhclient/dhclient-script22
-rw-r--r--sbin/dhclient/dhclient.c13
-rw-r--r--sbin/dhclient/dhcpd.h4
-rw-r--r--sbin/dhclient/dispatch.c25
4 files changed, 50 insertions, 14 deletions
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 <krw@openbsd.org>
#
@@ -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 <henning@openbsd.org>
@@ -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 <henning@openbsd.org>
@@ -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 <henning@openbsd.org>
@@ -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;
+}