From: Roy Marples Date: Tue, 18 Nov 2014 12:06:08 +0000 (+0000) Subject: If allowinterfaces is not specified, allow all configured interfaces X-Git-Tag: v6.6.3~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d91c2e720f229921793f7f04c29e31977b22896;p=thirdparty%2Fdhcpcd.git If allowinterfaces is not specified, allow all configured interfaces to work, such as loopback and ppp. --- diff --git a/dhcpcd.8.in b/dhcpcd.8.in index bd208ca4..4addd136 100644 --- a/dhcpcd.8.in +++ b/dhcpcd.8.in @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd September 30, 2014 +.Dd November 18, 2014 .Dt DHCPCD 8 .Os .Sh NAME @@ -101,6 +101,16 @@ It will then attempt to renew its lease and reconfigure if the new lease changes when the lease beings to expire or the DHCP server sends message to renew early. .Pp +If any interface reports a working carrier then +.Nm +will try and obtain a lease before forking to the background, +otherwise it will fork right away. +This behaviour can be modified with the +.Fl b , Fl Fl background +and +.Fl w , Fl Fl waitip +options. +.Pp .Nm is also an implementation of the BOOTP client specified in .Li RFC 951 . @@ -142,8 +152,11 @@ If a list of interfaces are given on the command line, then .Nm only works with those interfaces, otherwise .Nm -discovers available Ethernet interfaces. -This is called Master mode and this behaviour can be forced with the +discovers available Ethernet interfaces that can be configured. +When +.Nm +is operating on more than one interface, +it is called Master mode. and this behaviour can be forced with the .Fl M , Fl Fl master option so that an individual interface can start .Nm @@ -151,15 +164,6 @@ but only one instance is running. The .Nm dhcpcd-ui project expects dhcpcd to be running this way. -If any interface reports a working carrier then -.Nm -will try and obtain a lease before forking to the background, -otherwise it will fork right away. -This behaviour can be modified with the -.Fl b , Fl Fl background -and -.Fl w , Fl Fl waitip -options. .Pp If a single interface is given then .Nm diff --git a/dhcpcd.c b/dhcpcd.c index e7262b62..42a5e49a 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -149,6 +149,12 @@ free_globals(struct dhcpcd_ctx *ctx) free(ctx->ifdv); ctx->ifdv = NULL; } + if (ctx->ifcc) { + for (; ctx->ifcc > 0; ctx->ifcc--) + free(ctx->ifcv[ctx->ifcc - 1]); + free(ctx->ifcv); + ctx->ifcv = NULL; + } #ifdef INET if (ctx->dhcp_opts) { diff --git a/dhcpcd.h b/dhcpcd.h index 3ee1699b..41561a67 100644 --- a/dhcpcd.h +++ b/dhcpcd.h @@ -94,6 +94,8 @@ struct dhcpcd_ctx { char **ifdv; /* denied interfaces */ int ifc; /* listed interfaces */ char **ifv; /* listed interfaces */ + int ifcc; /* configured interfaces */ + char **ifcv; /* configured interfaces */ unsigned char *duid; size_t duid_len; int pid_fd; diff --git a/if-options.c b/if-options.c index dc7162f0..89835034 100644 --- a/if-options.c +++ b/if-options.c @@ -2165,10 +2165,30 @@ read_config(struct dhcpcd_ctx *ctx, } /* Start of an interface block, skip if not ours */ if (strcmp(option, "interface") == 0) { + char **n; + if (ifname && line && strcmp(line, ifname) == 0) skip = 0; else skip = 1; + if (ifname) + continue; + + n = realloc(ctx->ifcv, + sizeof(char *) * ((size_t)ctx->ifcc + 1)); + if (n == NULL) { + syslog(LOG_ERR, "%s: %m", __func__); + continue; + } + ctx->ifcv = n; + ctx->ifcv[ctx->ifcc] = strdup(line); + if (ctx->ifcv[ctx->ifcc] == NULL) { + syslog(LOG_ERR, "%s: %m", __func__); + continue; + } + ctx->ifcc++; + syslog(LOG_DEBUG, "allowing interface %s", + ctx->ifcv[ctx->ifcc - 1]); continue; } /* Start of an ssid block, skip if not ours */ diff --git a/if.c b/if.c index c1858a03..8f012521 100644 --- a/if.c +++ b/if.c @@ -166,6 +166,18 @@ if_setflag(struct interface *ifp, short flag) return r; } +static int +if_hasconf(struct dhcpcd_ctx *ctx, const char *ifname) +{ + int i; + + for (i = 0; i < ctx->ifcc; i++) { + if (strcmp(ctx->ifcv[i], ifname) == 0) + return 1; + } + return 0; +} + struct if_head * if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv) { @@ -285,11 +297,11 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv) /* Don't allow loopback or pointopoint unless explicit */ if (ifa->ifa_flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) { - if ((argc == 0 || argc == -1) && ctx->ifac == 0) + if ((argc == 0 || argc == -1) && + ctx->ifac == 0 && !if_hasconf(ctx, p)) continue; } - if (if_vimaster(p) == 1) { syslog(argc ? LOG_ERR : LOG_DEBUG, "%s: is a Virtual Interface Master, skipping", p); @@ -336,8 +348,9 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv) #ifdef IFT_BRIDGE case IFT_BRIDGE: /* Don't allow bridge unless explicit */ - if ((argc == 0 || argc == -1) - && ctx->ifac == 0) + if ((argc == 0 || argc == -1) && + ctx->ifac == 0 && + !if_hasconf(ctx, ifp->name)) { if_free(ifp); continue; @@ -386,7 +399,9 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv) /* We only work on ethernet by default */ if (ifp->family != ARPHRD_ETHER) { - if ((argc == 0 || argc == -1) && ctx->ifac == 0) { + if ((argc == 0 || argc == -1) && + ctx->ifac == 0 && !if_hasconf(ctx, ifp->name)) + { if_free(ifp); continue; } @@ -403,8 +418,8 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv) break; default: syslog(LOG_WARNING, - "%s: unsupported interface type %.2x" - ", family %.2x", + "%s: unsupported interface type %.2x, " + "family %.2x", ifp->name, sdl_type, ifp->family); break; }