Permalink
Browse files

Add ifstated handler

Fix interface start order. Configs will now be organized to start interfaces in the same order as /etc/netstart. This may fix problems for some trunk and carp users, and also possibly fixes issues with other (now reorganized) interface types. (I could see it being a problem for someone trying to use svlan on top of vlan and there are also potential problems configuring gre/gif before routes are established)
  • Loading branch information...
1 parent 4a4f00d commit 71d1f507aa5910fbb0d5cbf6fcca9fd03e8ef7c5 chris committed May 23, 2012
Showing with 94 additions and 11 deletions.
  1. +78 −9 conf.c
  2. +14 −1 ctl.c
  3. +2 −1 externs.h
View
87 conf.c
@@ -1,4 +1,4 @@
-/* $nsh: conf.c,v 1.72 2012/05/21 14:46:11 chris Exp $ */
+/* $nsh: conf.c,v 1.73 2012/05/23 05:45:35 chris Exp $ */
/*
* Copyright (c) 2002-2009 Chris Cappuccio <chris@nmedia.net>
*
@@ -67,6 +67,7 @@ void conf_intgroup(FILE *, int, char *);
void conf_keepalive(FILE *, int, char *);
void conf_groupattrib(FILE *);
int dhclient_isenabled(char *);
+int islateif(char *);
int isdefaultroute4(struct sockaddr *sa);
int scantext(char *, char *);
@@ -83,6 +84,37 @@ static const struct {
{ "lo", MTU_IGNORE },
};
+/*
+ * these interfaces get started in a specific order
+ *
+ * pfsync gets delayed until pf rules are loaded
+ *
+ * /etc/netstart says:
+ *
+ * The trunk interfaces need to come up first in this list.
+ * The (s)vlan interfaces need to come up after trunk.
+ * Configure all the carp interfaces which we know about before default route.
+ *
+ * Configure PPPoE, GIF, GRE and TUN interfaces, delayed because they require
+ * routes to be set. TUN might depend on PPPoE, and GIF or GRE may depend on
+ * either of them.
+ */
+
+static const struct {
+ char *name;
+} latestartifs[] = {
+ { "trunk" },
+ { "svlan" },
+ { "vlan" },
+ { "carp" },
+ { "gif" },
+ { "gre" },
+ { "pfsync" },
+ { "pppoe" },
+ { "tun" },
+ { "bridge" },
+};
+
int
conf(FILE *output)
{
@@ -103,7 +135,17 @@ conf(FILE *output)
fprintf(output, "!\n");
conf_ctl(output, "dns");
+ /*
+ * start all intefaces not listed in 'latestartifs'
+ */
conf_interfaces(output, NULL);
+ /*
+ * start these interfaces in specific order
+ */
+ conf_interfaces(output, "trunk");
+ conf_interfaces(output, "svlan");
+ conf_interfaces(output, "vlan");
+ conf_interfaces(output, "carp");
conf_groupattrib(output);
@@ -127,21 +169,39 @@ conf(FILE *output)
conf_routes(output, "route ", AF_INET, RTF_STATIC);
fprintf(output, "!\n");
+ /*
+ * these interfaces must start after routes are set
+ */
+ conf_interfaces(output, "pppoe");
+ conf_interfaces(output, "tun");
+ conf_interfaces(output, "gif");
+ conf_interfaces(output, "gre");
+ conf_interfaces(output, "bridge");
+ fprintf(output, "!\n");
conf_ctl(output, "pf");
+ /*
+ * this interface must start after pf is loaded
+ */
conf_interfaces(output, "pfsync");
+ conf_ctl(output, "snmp");
+ conf_ctl(output, "ldp");
+ conf_ctl(output, "rip");
conf_ctl(output, "ospf");
+ /* conf_ctl(output, "ospf6"); */
conf_ctl(output, "bgp");
- conf_ctl(output, "rip");
+ conf_ctl(output, "ifstate");
conf_ctl(output, "ipsec");
+ conf_ctl(output, "ike");
conf_ctl(output, "dvmrp");
conf_ctl(output, "relay");
conf_ctl(output, "sasync");
conf_ctl(output, "dhcp");
- conf_ctl(output, "snmp");
conf_ctl(output, "ntp");
+ conf_ctl(output, "smtp");
+ conf_ctl(output, "ldap");
conf_ctl(output, "ftp-proxy");
conf_ctl(output, "inet");
conf_ctl(output, "sshd");
@@ -283,6 +343,17 @@ int scantext(char *fname, char *string)
return(found);
}
+int islateif(char *ifname)
+{
+ int i;
+
+ for (i = 0; i < sizeof(latestartifs) / sizeof(latestartifs[0]); i++)
+ if (isprefix(latestartifs[i].name, ifname))
+ return(1);
+
+ return(0);
+}
+
void conf_interfaces(FILE *output, char *only)
{
FILE *dhcpif, *llfile;
@@ -310,16 +381,14 @@ void conf_interfaces(FILE *output, char *only)
}
for (ifnp = ifn_list; ifnp->if_name != NULL; ifnp++) {
- strlcpy(ifr.ifr_name, ifnp->if_name, sizeof(ifr.ifr_name));
-
if (only && !isprefix(only, ifnp->if_name))
/* only display interfaces which start with ... */
continue;
- if (!only) {
+ if (!only && islateif(ifnp->if_name))
/* interface prefixes to exclude on generic run */
- if (isprefix("pfsync", ifnp->if_name))
- continue;
- }
+ continue;
+
+ strlcpy(ifr.ifr_name, ifnp->if_name, sizeof(ifr.ifr_name));
if (ioctl(ifs, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
printf("%% conf: SIOCGIFFLAGS: %s\n", strerror(errno));
View
15 ctl.c
@@ -1,4 +1,4 @@
-/* $nsh: ctl.c,v 1.29 2012/05/19 23:59:56 chris Exp $ */
+/* $nsh: ctl.c,v 1.30 2012/05/23 05:45:35 chris Exp $ */
/*
* Copyright (c) 2008 Chris Cappuccio <chris@nmedia.net>
*
@@ -44,6 +44,7 @@
#define LDPD "/usr/sbin/ldpd"
#define SMTPD "/usr/sbin/smtpd"
#define LDAPD "/usr/sbin/ldapd"
+#define IFSTATED "/usr/sbin/ifstated"
#ifndef DHCPLEASES
#define DHCPLEASES "/var/db/dhcpd.leases"
#endif
@@ -178,6 +179,17 @@ struct ctl ctl_dvmrp[] = {
{ 0, 0, { 0 }, 0, 0 }
};
+char *ctl_ifstate_test[] = { IFSTATED, "-nf", IFSTATECONF_TEMP, '\0' };
+struct ctl ctl_ifstate[] = {
+ { "enable", "enable service",
+ { IFSTATED, "-f", IFSTATECONF_TEMP, NULL }, NULL, X_ENABLE },
+ { "disable", "disable service",
+ { PKILL, "ifstated", NULL }, NULL, X_DISABLE },
+ { "edit", "edit configuration",
+ { "ifstate", (char *)ctl_ifstate_test, NULL }, call_editor, NULL },
+ { 0, 0, { 0 }, 0, 0 }
+};
+
struct ctl ctl_sasync[] = {
{ "enable", "enable service",
{ SASYNCD, "-c", SASYNCCONF_TEMP, NULL }, NULL, X_ENABLE },
@@ -341,6 +353,7 @@ struct daemons ctl_daemons[] = {
{ "inet", "Inet", ctl_inet, INETCONF_TEMP, 0600, 0 },
{ "smtp", "SMTP", ctl_smtp, SMTPCONF_TEMP, 0600, 0 },
{ "ldap", "LDAP", ctl_ldap, LDAPCONF_TEMP, 0600, 0 },
+ { "ifstate", "Interface state", ctl_ifstate, IFSTATECONF_TEMP, 0600, 0 },
{ 0, 0, 0, 0, 0 }
};
View
@@ -1,4 +1,4 @@
-/* $nsh: externs.h,v 1.78 2012/05/21 14:46:11 chris Exp $ */
+/* $nsh: externs.h,v 1.79 2012/05/23 05:45:35 chris Exp $ */
/*
* nsh externs, prototypes and macros
*/
@@ -119,6 +119,7 @@ extern char metricnames[];
#define SSHDCONF_TEMP "/var/run/sshd.conf"
#define SMTPCONF_TEMP "/var/run/smtpd.conf"
#define LDAPCONF_TEMP "/var/run/ldapd.conf"
+#define IFSTATECONF_TEMP "/var/run/ifstated.conf"
/* flag_x flags */
#define X_ENABLE (void *)1
#define X_DISABLE (void *)2

0 comments on commit 71d1f50

Please sign in to comment.