]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
ipv4: allow configuration of static broadcast address
authorRoy Marples <roy@marples.name>
Mon, 8 Jan 2018 09:25:31 +0000 (09:25 +0000)
committerRoy Marples <roy@marples.name>
Mon, 8 Jan 2018 09:25:31 +0000 (09:25 +0000)
src/dhcp.c
src/dhcpcd.8.in
src/dhcpcd.conf.5.in
src/if-options.c
src/if-options.h
src/if.c

index df23a3959639ab4a9a5eba3b87b40db4c5be81f9..98767fc4325b91f62231bc11dfe13e46b8769841 100644 (file)
@@ -1462,8 +1462,11 @@ get_lease(struct interface *ifp,
        if (ifp->options->options & (DHCPCD_STATIC | DHCPCD_INFORM)) {
                if (ifp->options->req_addr.s_addr != INADDR_ANY) {
                        lease->mask = ifp->options->req_mask;
-                       lease->brd.s_addr =
-                           lease->addr.s_addr | ~lease->mask.s_addr;
+                       if (ifp->options->req_brd.s_addr != INADDR_ANY)
+                               lease->brd = ifp->options->req_brd;
+                       else
+                               lease->brd.s_addr =
+                                   lease->addr.s_addr | ~lease->mask.s_addr;
                } else {
                        const struct ipv4_addr *ia;
 
index 53e6b3c6719afc08703b19db3bbb1d94efb39105..27a149e7dcceda5c367fd2af1fdc58eea19c5a5e 100644 (file)
@@ -47,7 +47,7 @@
 .Op Fl Q , Fl Fl require Ar option
 .Op Fl r , Fl Fl request Ar address
 .Op Fl S , Fl Fl static Ar value
-.Op Fl s , Fl Fl inform Ar address Ns Op Ar /cidr
+.Op Fl s , Fl Fl inform Ar address Ns Op Ar /cidr Ns Op Ar /broadcast_address
 .Op Fl Fl inform6
 .Op Fl t , Fl Fl timeout Ar seconds
 .Op Fl u , Fl Fl userclass Ar class
@@ -444,7 +444,7 @@ If no
 is given then the first address currently assigned to the
 .Ar interface
 is used.
-.It Fl s , Fl Fl inform Ar address Ns Op Ar /cidr
+.It Fl s , Fl Fl inform Ar address Ns Op Ar /cidr Ns Op Ar /broadcast_address
 Behaves like
 .Fl r , Fl Fl request
 as above, but sends a DHCP INFORM instead of DISCOVER/REQUEST.
index 9bc8fad0e786e82936b3848ab9ba1a7327106f4d..407302315161647bada5337bd84a0f06b8e63b87 100644 (file)
@@ -225,7 +225,7 @@ If no
 is given then the first address currently assigned to the
 .Ar interface
 is used.
-.It Ic inform Op Ar address Ns Op Ar /cidr
+.It Ic inform Op Ar address Ns Op Ar /cidr Ns Op Ar /broadcast_address
 Behaves like
 .Ic request
 as above, but sends a DHCP INFORM instead of DISCOVER/REQUEST.
@@ -602,8 +602,8 @@ If you set
 .Nm dhcpcd
 will continue auto-configuation as normal.
 .Pp
-Here is an example which configures two static address, an IPv4 router, DNS
-and disables IPv6 auto-configuration.
+Here is an example which configures two static address, overriding the default
+IPv4 broadcast address, an IPv4 router, DNS and disables IPv6 auto-configuration.
 You could also use the
 .Ic inform6
 command here if you wished to obtain more information via DHCPv6.
@@ -613,6 +613,7 @@ option instead of setting a static address.
 .D1 interface eth0
 .D1 noipv6rs
 .D1 static ip_address=192.168.0.10/24
+.D1 static broadcast_address=192.168.0.63
 .D1 static ip6_address=fd51:42f8:caae:d92e::ff/64
 .D1 static routers=192.168.0.1
 .D1 static domain_name_servers=192.168.0.1 fd51:42f8:caae:d92e::1
index c7416ea58e7c123033b5e614f7e6b3d37745feda..40a7e7a5325619419fca3c31449f3cb7585689f1 100644 (file)
@@ -815,8 +815,21 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                break;
        case 's':
                if (arg && *arg != '\0') {
-                       if (parse_addr(&ifo->req_addr, &ifo->req_mask, arg)
-                           != 0)
+                       /* Strip out a broadcast address */
+                       p = strchr(arg, '/');
+                       if (p != NULL) {
+                               p = strchr(p + 1, '/');
+                               if (p != NULL)
+                                       *p = '\0';
+                       }
+                       i = parse_addr(&ifo->req_addr, &ifo->req_mask, arg);
+                       if (p != NULL) {
+                               /* Ensure the original string is preserved */
+                               *p++ = '/';
+                               if (i == 0)
+                                       i = parse_addr(&ifo->req_brd, NULL, p);
+                       }
+                       if (i != 0)
                                return -1;
                } else {
                        ifo->req_addr.s_addr = 0;
@@ -1060,6 +1073,11 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                {
                        if (parse_addr(&ifo->req_mask, NULL, p) != 0)
                                return -1;
+               } else if (strncmp(arg, "broadcast_address=",
+                   strlen("broadcast_address=")) == 0)
+               {
+                       if (parse_addr(&ifo->req_brd, NULL, p) != 0)
+                               return -1;
                } else if (strncmp(arg, "routes=", strlen("routes=")) == 0 ||
                    strncmp(arg, "static_routes=",
                        strlen("static_routes=")) == 0 ||
index 164ad5933a9f9e6b98e926ff3ae20c363bf0443d..4852d4b761c7df23b85ad6c4b981515701c842ca 100644 (file)
@@ -180,6 +180,7 @@ struct if_options {
 
        struct in_addr req_addr;
        struct in_addr req_mask;
+       struct in_addr req_brd;
        struct rt_head routes;
        struct in6_addr req_addr6;
        uint8_t req_prefix_len;
index adeb6d921f2f91bec479a158a876495f87745106..85535029afeae7695d0eaa225f639a8a56225d37 100644 (file)
--- a/src/if.c
+++ b/src/if.c
@@ -533,7 +533,9 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs,
                        }
                }
 
-               if (!(ctx->options & (DHCPCD_DUMPLEASE | DHCPCD_TEST))) {
+               if (active &&
+                   !(ctx->options & (DHCPCD_DUMPLEASE | DHCPCD_TEST)))
+               {
                        /* Handle any platform init for the interface */
                        if (active != IF_INACTIVE && if_init(ifp) == -1) {
                                logerr("%s: if_init", ifp->name);