summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2014-01-21 03:07:50 +0000
committerkrw <krw@openbsd.org>2014-01-21 03:07:50 +0000
commit171f404ee8fdfb14927e71908b4ad3e576c30da5 (patch)
tree12bb534ff998697cbf3807c0884619dbc8c11afd
parentUpdate gcc-local(1) with recent changes to the toolchain: (diff)
downloadwireguard-openbsd-171f404ee8fdfb14927e71908b4ad3e576c30da5.tar.xz
wireguard-openbsd-171f404ee8fdfb14927e71908b4ad3e576c30da5.zip
Add parsing for options 121 (classless-static-routes) and 249
(classless-ms-static-routes). dhcpd can now specify and serve these options and dhclient can recognize and use supersede, etc. statements on them. Based on a diff from Stefan Rinke. Thanks!
-rw-r--r--sbin/dhclient/clparse.c9
-rw-r--r--sbin/dhclient/dhclient.c5
-rw-r--r--sbin/dhclient/dhcp.h3
-rw-r--r--sbin/dhclient/dhcpd.h3
-rw-r--r--sbin/dhclient/options.c14
-rw-r--r--sbin/dhclient/parse.c41
-rw-r--r--sbin/dhclient/tables.c7
-rw-r--r--usr.sbin/dhcpd/confpars.c53
-rw-r--r--usr.sbin/dhcpd/dhcp-options.510
-rw-r--r--usr.sbin/dhcpd/dhcp.h4
-rw-r--r--usr.sbin/dhcpd/tables.c6
11 files changed, 139 insertions, 16 deletions
diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c
index c5814012878..3869d3820ac 100644
--- a/sbin/dhclient/clparse.c
+++ b/sbin/dhclient/clparse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clparse.c,v 1.80 2014/01/20 01:12:17 krw Exp $ */
+/* $OpenBSD: clparse.c,v 1.81 2014/01/21 03:07:50 krw Exp $ */
/* Parser for dhclient config and lease files. */
@@ -600,6 +600,7 @@ parse_option_decl(FILE *cfile, struct option_data *options)
char *val;
int token;
u_int8_t buf[4];
+ u_int8_t cidr[5];
u_int8_t hunkbuf[1024];
int hunkix = 0;
char *fmt;
@@ -737,6 +738,12 @@ bad_flag:
len = 1;
dp = buf;
goto alloc;
+ case 'C':
+ if (!parse_cidr(cfile, cidr))
+ return (-1);
+ len = 1 + (cidr[0] + 7) / 8;
+ dp = cidr;
+ goto alloc;
default:
warning("Bad format %c in parse_option_param.",
*fmt);
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index 599d7f70030..6e5cb1db3d6 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.285 2014/01/20 09:16:36 deraadt Exp $ */
+/* $OpenBSD: dhclient.c,v 1.286 2014/01/21 03:07:50 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -883,6 +883,9 @@ bind_lease(void)
if (options[DHO_CLASSLESS_STATIC_ROUTES].len) {
add_classless_static_routes(ifi->rdomain,
&options[DHO_CLASSLESS_STATIC_ROUTES]);
+ } else if (options[DHO_CLASSLESS_MS_STATIC_ROUTES].len) {
+ add_classless_static_routes(ifi->rdomain,
+ &options[DHO_CLASSLESS_MS_STATIC_ROUTES]);
} else {
opt = &options[DHO_ROUTERS];
if (opt->len >= sizeof(gateway)) {
diff --git a/sbin/dhclient/dhcp.h b/sbin/dhclient/dhcp.h
index 586e1c9044b..731f8a97054 100644
--- a/sbin/dhclient/dhcp.h
+++ b/sbin/dhclient/dhcp.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcp.h,v 1.16 2013/12/05 22:31:35 krw Exp $ */
+/* $OpenBSD: dhcp.h,v 1.17 2014/01/21 03:07:50 krw Exp $ */
/* Protocol structures. */
@@ -174,6 +174,7 @@ struct dhcp_packet {
#define DHO_CLASSLESS_STATIC_ROUTES 121
#define DHO_TFTP_CONFIG_FILE 144
#define DHO_VOIP_CONFIGURATION_SERVER 150
+#define DHO_CLASSLESS_MS_STATIC_ROUTES 249
#define DHO_AUTOPROXY_SCRIPT 252
#define DHO_END 255
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h
index 26b8c37c4ab..51dd254a024 100644
--- a/sbin/dhclient/dhcpd.h
+++ b/sbin/dhclient/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.133 2014/01/19 10:06:09 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.134 2014/01/21 03:07:50 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -235,6 +235,7 @@ void skip_to_semi(FILE *);
int parse_semi(FILE *);
char *parse_string(FILE *);
int parse_ip_addr(FILE *, struct in_addr *);
+int parse_cidr(FILE *, unsigned char *);
void parse_ethernet(FILE *, struct ether_addr *);
void parse_lease_time(FILE *, time_t *);
int parse_decimal(FILE *, unsigned char *, char);
diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c
index d2f4a9561e9..754254c58fe 100644
--- a/sbin/dhclient/options.c
+++ b/sbin/dhclient/options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.c,v 1.66 2014/01/19 21:10:04 krw Exp $ */
+/* $OpenBSD: options.c,v 1.67 2014/01/21 03:07:50 krw Exp $ */
/* DHCP options parsing and reassembly. */
@@ -332,6 +332,9 @@ pretty_print_option(unsigned int code, struct option_data *option,
break;
case 'e':
break;
+ case 'C':
+ hunksize += 5;
+ break;
default:
warning("%s: garbage in format string: %s",
dhcp_options[code].name,
@@ -409,6 +412,15 @@ pretty_print_option(unsigned int code, struct option_data *option,
*dp ? "true" : "false");
dp++;
break;
+ case 'C':
+ memset(&foo, 0, sizeof(foo));
+ memcpy(&foo.s_addr, dp+1, (*dp + 7) / 8);
+ opcount = snprintf(op, opleft, "%s/%u",
+ inet_ntoa(foo), *dp);
+ if (opcount >= opleft || opcount == -1)
+ goto toobig;
+ dp += 1 + (*dp + 7) / 8;
+ break;
default:
warning("Unexpected format code %c", fmtbuf[j]);
goto toobig;
diff --git a/sbin/dhclient/parse.c b/sbin/dhclient/parse.c
index a79f996c463..d900d67b3a0 100644
--- a/sbin/dhclient/parse.c
+++ b/sbin/dhclient/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.36 2014/01/19 21:10:04 krw Exp $ */
+/* $OpenBSD: parse.c,v 1.37 2014/01/21 03:07:50 krw Exp $ */
/* Common parser code for dhcpd and dhclient. */
@@ -136,6 +136,45 @@ parse_string(FILE *cfile)
return (s);
}
+/* cidr :== ip-address "/" bit-count
+ * ip-address :== NUMBER [ DOT NUMBER [ DOT NUMBER [ DOT NUMBER ] ] ]
+ * bit-count :== 0..32
+ */
+int
+parse_cidr(FILE *cfile, unsigned char *cidr)
+{
+ struct in_addr addr;
+ int token;
+ int len;
+
+ token = '.';
+ len = 0;
+ for (token = '.'; token == '.'; token = next_token(NULL, cfile)) {
+ if (!parse_decimal(cfile, cidr + 1 + len, 'B'))
+ break;
+ if (++len == sizeof(addr)) {
+ token = next_token(NULL, cfile);
+ break;
+ }
+ }
+
+ if (!len) {
+ parse_warn("expecting CIDR subnet.");
+ skip_to_semi(cfile);
+ return (0);
+ } else if (token != '/') {
+ parse_warn("expecting '/'.");
+ skip_to_semi(cfile);
+ return (0);
+ } else if (!parse_decimal(cfile, cidr, 'B') || *cidr > 32) {
+ parse_warn("Expecting CIDR prefix length.");
+ skip_to_semi(cfile);
+ return (0);
+ }
+
+ return (1);
+}
+
int
parse_ip_addr(FILE *cfile, struct in_addr *addr)
{
diff --git a/sbin/dhclient/tables.c b/sbin/dhclient/tables.c
index 0375dab1e8f..84abdb8fda5 100644
--- a/sbin/dhclient/tables.c
+++ b/sbin/dhclient/tables.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tables.c,v 1.17 2014/01/19 21:10:04 krw Exp $ */
+/* $OpenBSD: tables.c,v 1.18 2014/01/21 03:07:50 krw Exp $ */
/* Tables of information. */
@@ -56,6 +56,7 @@
* t - ASCII text
* f - flag (true or false)
* A - array of whatever precedes (e.g., IA means array of IP addresses)
+ * C - CIDR description
*/
const struct option dhcp_options[256] = {
@@ -180,7 +181,7 @@ const struct option dhcp_options[256] = {
/* 118 */ { "option-118", "X" },
/* 119 */ { "option-119", "X" },
/* 120 */ { "option-120", "X" },
- /* 121 */ { "classless-static-routes", "X" },
+ /* 121 */ { "classless-static-routes", "CIA" },
/* 122 */ { "option-122", "X" },
/* 123 */ { "option-123", "X" },
/* 124 */ { "option-124", "X" },
@@ -308,7 +309,7 @@ const struct option dhcp_options[256] = {
/* 246 */ { "option-246", "X" },
/* 247 */ { "option-247", "X" },
/* 248 */ { "option-248", "X" },
- /* 249 */ { "option-249", "X" },
+ /* 249 */ { "classless-ms-static-routes", "CIA" },
/* 250 */ { "option-250", "X" },
/* 251 */ { "option-251", "X" },
/* 252 */ { "autoproxy-script", "t" },
diff --git a/usr.sbin/dhcpd/confpars.c b/usr.sbin/dhcpd/confpars.c
index fa1a3784bb3..e9254925276 100644
--- a/usr.sbin/dhcpd/confpars.c
+++ b/usr.sbin/dhcpd/confpars.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: confpars.c,v 1.21 2013/10/21 12:02:25 krw Exp $ */
+/* $OpenBSD: confpars.c,v 1.22 2014/01/21 03:07:51 krw Exp $ */
/*
* Copyright (c) 1995, 1996, 1997 The Internet Software Consortium.
@@ -818,6 +818,48 @@ void parse_group_declaration(cfile, group)
} while (1);
}
+/* cidr :== ip-address "/" bit-count
+ * ip-address :== NUMBER [ DOT NUMBER [ DOT NUMBER [ DOT NUMBER ] ] ]
+ * bit-count :== 0..32
+ */
+int
+parse_cidr(FILE *cfile, unsigned char *addr, unsigned char *prefix)
+{
+ char *val;
+ int token;
+ int len = 4;
+
+ token = peek_token(&val, cfile);
+
+ if (!parse_numeric_aggregate(cfile, addr, &len, '.', 10, 8)) {
+ parse_warn("Expecting CIDR subnet");
+ goto nocidr;
+ }
+
+ token = next_token(&val, cfile);
+ if (token != '/') {
+ parse_warn("Expecting '/'");
+ goto nocidr;
+ }
+
+ *prefix = 0;
+ token = next_token(&val, cfile);
+ if (token == TOK_NUMBER)
+ convert_num(prefix, val, 10, 8);
+
+ if (token != TOK_NUMBER || *prefix < 1 || *prefix > 32) {
+ parse_warn("Expecting CIDR prefix length, got '%s'", val);
+ goto nocidr;
+ }
+
+ return 1;
+
+nocidr:
+ if (token != ';')
+ skip_to_semi(cfile);
+ return 0;
+}
+
/* ip-addr-or-hostname :== ip-address | hostname
ip-address :== NUMBER DOT NUMBER DOT NUMBER DOT NUMBER
@@ -911,6 +953,7 @@ void parse_option_param(cfile, group)
char *val;
int token;
unsigned char buf[4];
+ unsigned char cprefix;
char *vendor;
char *fmt;
struct universe *universe;
@@ -1108,6 +1151,14 @@ void parse_option_param(cfile, group)
}
tree = tree_concat(tree, tree_const(buf, 1));
break;
+ case 'C':
+ if (!parse_cidr(cfile, buf, &cprefix))
+ return;
+ tree = tree_concat(tree, tree_const(&cprefix,
+ sizeof(cprefix)));
+ tree = tree_concat(tree, tree_const(buf,
+ sizeof(buf)));
+ break;
default:
warning("Bad format %c in parse_option_param.",
*fmt);
diff --git a/usr.sbin/dhcpd/dhcp-options.5 b/usr.sbin/dhcpd/dhcp-options.5
index a45f2a3e7ad..78603a956fd 100644
--- a/usr.sbin/dhcpd/dhcp-options.5
+++ b/usr.sbin/dhcpd/dhcp-options.5
@@ -1,4 +1,4 @@
-.\" $OpenBSD: dhcp-options.5,v 1.18 2014/01/03 16:21:58 jmc Exp $
+.\" $OpenBSD: dhcp-options.5,v 1.19 2014/01/21 03:07:51 krw Exp $
.\"
.\" Copyright (c) 1995, 1996, 1997, 1998 The Internet Software Consortium.
.\" All rights reserved.
@@ -36,7 +36,7 @@
.\" see ``http://www.isc.org/isc''. To learn more about Vixie
.\" Enterprises, see ``http://www.vix.com''.
.\"
-.Dd $Mdocdate: January 3 2014 $
+.Dd $Mdocdate: January 21 2014 $
.Dt DHCP-OPTIONS 5
.Os
.Sh NAME
@@ -606,6 +606,12 @@ option specifies a list of WWW servers available to the client.
This option specifies a list of systems that are running the X Window
System Display Manager and are available to the client.
Addresses should be listed in order of preference.
+.It Ic option classless-static-routes Ar ip/prefix ip Oo , Ar ip/prefix ip ... Oc ;
+This option specifies a list of static routes in CDIR notation, which
+should be sent to the client.
+.It Ic option classless-ms-static-routes Ar ip/prefix ip Oo , Ar ip/prefix ip ... Oc ;
+This option does the same as classless-static-routes, but uses option code 249
+instead of 121, since Windows XP and Windows Server 2003 ignore option 121.
.El
.Sh SEE ALSO
.Xr dhclient.conf 5 ,
diff --git a/usr.sbin/dhcpd/dhcp.h b/usr.sbin/dhcpd/dhcp.h
index 5ee1e5f102a..9a52393a5fe 100644
--- a/usr.sbin/dhcpd/dhcp.h
+++ b/usr.sbin/dhcpd/dhcp.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcp.h,v 1.9 2013/12/05 22:31:35 krw Exp $ */
+/* $OpenBSD: dhcp.h,v 1.10 2014/01/21 03:07:51 krw Exp $ */
/* Protocol structures... */
@@ -171,8 +171,10 @@ struct dhcp_packet {
#define DHO_NDS_SERVERS 85
#define DHO_NDS_TREE_NAME 86
#define DHO_NDS_CONTEXT 87
+#define DHO_CLASSLESS_STATIC_ROUTES 121
#define DHO_TFTP_CONFIG_FILE 144
#define DHO_VOIP_CONFIGURATION_SERVER 150
+#define DHO_CLASSLESS_MS_STATIC_ROUTES 249
#define DHO_AUTOPROXY_SCRIPT 252
#define DHO_END 255
diff --git a/usr.sbin/dhcpd/tables.c b/usr.sbin/dhcpd/tables.c
index 3e5315bf90b..027af5d42c5 100644
--- a/usr.sbin/dhcpd/tables.c
+++ b/usr.sbin/dhcpd/tables.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tables.c,v 1.9 2009/09/01 08:42:31 reyk Exp $ */
+/* $OpenBSD: tables.c,v 1.10 2014/01/21 03:07:51 krw Exp $ */
/* Tables of information... */
@@ -183,7 +183,7 @@ struct option dhcp_options[256] = {
{ "option-118", "X", &dhcp_universe, 118 },
{ "option-119", "X", &dhcp_universe, 119 },
{ "option-120", "X", &dhcp_universe, 120 },
- { "option-121", "X", &dhcp_universe, 121 },
+ { "classless-static-routes", "CIA", &dhcp_universe, 121 },
{ "option-122", "X", &dhcp_universe, 122 },
{ "option-123", "X", &dhcp_universe, 123 },
{ "option-124", "X", &dhcp_universe, 124 },
@@ -311,7 +311,7 @@ struct option dhcp_options[256] = {
{ "option-246", "X", &dhcp_universe, 246 },
{ "option-247", "X", &dhcp_universe, 247 },
{ "option-248", "X", &dhcp_universe, 248 },
- { "option-249", "X", &dhcp_universe, 249 },
+ { "classless-ms-static-routes", "CIA", &dhcp_universe, 249 },
{ "option-250", "X", &dhcp_universe, 250 },
{ "option-251", "X", &dhcp_universe, 251 },
{ "autoproxy-script", "t", &dhcp_universe, 252 },