From c85baeae3e9f3e1a0965bf956b59c74a9aa208e9 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Thu, 29 May 2014 12:52:27 +0000 Subject: [PATCH] -4 and -6 are now mutually exclusive and when running on a single interface per protocol pidfiles are created. This means that other control options suchs as -x and -n will require the -4 or -6 option as well. --- defs.h | 2 +- dhcpcd.8.in | 12 +++++++++++- dhcpcd.c | 29 ++++++++++++++++++++++++++--- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/defs.h b/defs.h index b97c0425..e9de7fa9 100644 --- a/defs.h +++ b/defs.h @@ -49,7 +49,7 @@ # define LEASEFILE6 DBDIR "/" PACKAGE "-%s.lease6" #endif #ifndef PIDFILE -# define PIDFILE RUNDIR "/" PACKAGE "%s%s.pid" +# define PIDFILE RUNDIR "/" PACKAGE "%s%s%s.pid" #endif #ifndef CONTROLSOCKET # define CONTROLSOCKET RUNDIR "/" PACKAGE "%s%s.sock" diff --git a/dhcpcd.8.in b/dhcpcd.8.in index 6033ea9e..fcd475ad 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 March 7, 2014 +.Dd May 29, 2014 .Dt DHCPCD 8 .Os .Sh NAME @@ -613,6 +613,16 @@ unicasts INFORM to the destination, otherwise it defaults to STATIC. requires a Berkley Packet Filter, or BPF device on BSD based systems and a Linux Socket Filter, or LPF device on Linux based systems for all IPv4 configuration. +.Pp +If restricting +.Nm +to a single interface and optionally address family via the command-line +then all futher calls to +.Nm +to rebind, reconfigure or exit need to include the same restrictive flags +so that +.Nm +knows which process to signal. .Sh FILES .Bl -ohang .It Pa @SYSCONFDIR@/dhcpcd.conf diff --git a/dhcpcd.c b/dhcpcd.c index 5ec6b8f0..482764d4 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -1116,7 +1116,7 @@ int main(int argc, char **argv) { struct dhcpcd_ctx ctx; - char pidfile[sizeof(PIDFILE) + IF_NAMESIZE]; + char pidfile[sizeof(PIDFILE) + IF_NAMESIZE + 1]; struct if_options *ifo; struct interface *ifp; uint16_t family = 0; @@ -1174,9 +1174,19 @@ main(int argc, char **argv) { switch (opt) { case '4': + if (family) { + syslog(LOG_ERR, "cannot specify more than one" + " address family"); + goto exit_failure; + } family = AF_INET; break; case '6': + if (family) { + syslog(LOG_ERR, "cannot specify more than one" + " address family"); + goto exit_failure; + } family = AF_INET6; break; case 'f': @@ -1278,16 +1288,29 @@ main(int argc, char **argv) /* If we have any other args, we should run as a single dhcpcd * instance for that interface. */ if (optind == argc - 1 && !(ctx.options & DHCPCD_MASTER)) { + const char *per; + if (strlen(argv[optind]) > IF_NAMESIZE) { syslog(LOG_ERR, "%s: interface name too long", argv[optind]); goto exit_failure; } + /* Allow a dhcpcd interface per address family */ + switch(family) { + case AF_INET: + per = "-4"; + break; + case AF_INET6: + per = "-6"; + break; + default: + per = ""; + } snprintf(pidfile, sizeof(pidfile), - PIDFILE, "-", argv[optind]); + PIDFILE, "-", argv[optind], per); } else { - snprintf(pidfile, sizeof(pidfile), PIDFILE, "", ""); + snprintf(pidfile, sizeof(pidfile), PIDFILE, "", "", ""); ctx.options |= DHCPCD_MASTER; } } -- 2.47.3