summaryrefslogtreecommitdiff
path: root/sbin/dhclient/parse.c
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2014-01-21 03:07:52 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2014-01-21 03:07:52 +0000
commitccebaf6330c1236514987ed985fa4d83b955bbee (patch)
tree2f938103a4ae15e4ce3f02b6cebf46e02605151a /sbin/dhclient/parse.c
parent54bb067f7ca618dd4db30a3a61dcd8eb3e27796e (diff)
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!
Diffstat (limited to 'sbin/dhclient/parse.c')
-rw-r--r--sbin/dhclient/parse.c41
1 files changed, 40 insertions, 1 deletions
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)
{