]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
If allowinterfaces is not specified, allow all configured interfaces
authorRoy Marples <roy@marples.name>
Tue, 18 Nov 2014 12:06:08 +0000 (12:06 +0000)
committerRoy Marples <roy@marples.name>
Tue, 18 Nov 2014 12:06:08 +0000 (12:06 +0000)
to work, such as loopback and ppp.

dhcpcd.8.in
dhcpcd.c
dhcpcd.h
if-options.c
if.c

index bd208ca40a1d595f0f5b1f7bcb053b74567ebaa3..4addd1367b8c744d6f97d31a36b1c6d908109b6d 100644 (file)
@@ -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
index e7262b6278a07ca13801bf3f0f78c541c3396c65..42a5e49ab2bd1b84c7515c27e3faca44943f21d9 100644 (file)
--- 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) {
index 3ee1699b2c715575f3fb7b061671cf6493620793..41561a67a5aceb8be63903225a627783ddb817cc 100644 (file)
--- 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;
index dc7162f03bf28d6ef4373bfeb29cd61b84e54073..898350347caa5be13f7a1988a05098eb30ac61f9 100644 (file)
@@ -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 c1858a037b5184c03c29568bd5f268ab95ad322a..8f01252152e549788e8de23e58b806e3f82794ef 100644 (file)
--- 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;
                        }