Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 71d1f507aa5910fbb0d5cbf6fcca9fd03e8ef7c5 1 parent 4a4f00d
authored May 23, 2012
87  conf.c
... ...
@@ -1,4 +1,4 @@
1  
-/* $nsh: conf.c,v 1.72 2012/05/21 14:46:11 chris Exp $ */
  1
+/* $nsh: conf.c,v 1.73 2012/05/23 05:45:35 chris Exp $ */
2 2
 /*
3 3
  * Copyright (c) 2002-2009 Chris Cappuccio <chris@nmedia.net>
4 4
  *
@@ -67,6 +67,7 @@ void conf_intgroup(FILE *, int, char *);
67 67
 void conf_keepalive(FILE *, int, char *);
68 68
 void conf_groupattrib(FILE *);
69 69
 int dhclient_isenabled(char *);
  70
+int islateif(char *);
70 71
 int isdefaultroute4(struct sockaddr *sa);
71 72
 int scantext(char *, char *);
72 73
 
@@ -83,6 +84,37 @@ static const struct {
83 84
 	{ "lo",		MTU_IGNORE },
84 85
 };
85 86
 
  87
+/*
  88
+ * these interfaces get started in a specific order
  89
+ *
  90
+ * pfsync gets delayed until pf rules are loaded
  91
+ *
  92
+ * /etc/netstart says:
  93
+ *
  94
+ * The trunk interfaces need to come up first in this list.
  95
+ * The (s)vlan interfaces need to come up after trunk.
  96
+ * Configure all the carp interfaces which we know about before default route.
  97
+ *
  98
+ * Configure PPPoE, GIF, GRE and TUN interfaces, delayed because they require
  99
+ * routes to be set.  TUN might depend on PPPoE, and GIF or GRE may depend on
  100
+ * either of them.
  101
+ */
  102
+
  103
+static const struct {
  104
+	char *name;
  105
+} latestartifs[] = {
  106
+	{ "trunk" },
  107
+	{ "svlan" },
  108
+	{ "vlan" },
  109
+	{ "carp" },
  110
+	{ "gif" },
  111
+	{ "gre" },
  112
+	{ "pfsync" },
  113
+	{ "pppoe" },
  114
+	{ "tun" },
  115
+	{ "bridge" },
  116
+};
  117
+
86 118
 int
87 119
 conf(FILE *output)
88 120
 {
@@ -103,7 +135,17 @@ conf(FILE *output)
103 135
 	fprintf(output, "!\n");
104 136
 	conf_ctl(output, "dns");
105 137
 
  138
+	/*
  139
+	 * start all intefaces not listed in 'latestartifs'
  140
+	 */
106 141
 	conf_interfaces(output, NULL);
  142
+	/*
  143
+	 * start these interfaces in specific order
  144
+	 */
  145
+	conf_interfaces(output, "trunk");
  146
+	conf_interfaces(output, "svlan");
  147
+	conf_interfaces(output, "vlan");
  148
+	conf_interfaces(output, "carp");
107 149
 
108 150
 	conf_groupattrib(output);
109 151
 
@@ -127,21 +169,39 @@ conf(FILE *output)
127 169
 	conf_routes(output, "route ", AF_INET, RTF_STATIC);
128 170
 
129 171
 	fprintf(output, "!\n");
  172
+	/*
  173
+	 * these interfaces must start after routes are set
  174
+	 */
  175
+	conf_interfaces(output, "pppoe");
  176
+	conf_interfaces(output, "tun");
  177
+	conf_interfaces(output, "gif");
  178
+	conf_interfaces(output, "gre");
  179
+	conf_interfaces(output, "bridge");
130 180
 
  181
+	fprintf(output, "!\n");
131 182
 	conf_ctl(output, "pf");
132 183
 
  184
+	/*
  185
+	 * this interface must start after pf is loaded
  186
+	 */
133 187
 	conf_interfaces(output, "pfsync");
134 188
 
  189
+	conf_ctl(output, "snmp");
  190
+	conf_ctl(output, "ldp");
  191
+	conf_ctl(output, "rip");
135 192
 	conf_ctl(output, "ospf");
  193
+	/* conf_ctl(output, "ospf6"); */
136 194
 	conf_ctl(output, "bgp");
137  
-	conf_ctl(output, "rip");
  195
+	conf_ctl(output, "ifstate");
138 196
 	conf_ctl(output, "ipsec");
  197
+	conf_ctl(output, "ike");
139 198
 	conf_ctl(output, "dvmrp");
140 199
 	conf_ctl(output, "relay");
141 200
 	conf_ctl(output, "sasync");
142 201
 	conf_ctl(output, "dhcp");
143  
-	conf_ctl(output, "snmp");
144 202
 	conf_ctl(output, "ntp");
  203
+	conf_ctl(output, "smtp");
  204
+	conf_ctl(output, "ldap");
145 205
 	conf_ctl(output, "ftp-proxy");
146 206
 	conf_ctl(output, "inet");
147 207
 	conf_ctl(output, "sshd");
@@ -283,6 +343,17 @@ int scantext(char *fname, char *string)
283 343
 	return(found);
284 344
 }
285 345
 
  346
+int islateif(char *ifname)
  347
+{
  348
+	int i;
  349
+
  350
+	for (i = 0; i < sizeof(latestartifs) / sizeof(latestartifs[0]); i++)
  351
+		if (isprefix(latestartifs[i].name, ifname))  
  352
+			return(1);
  353
+
  354
+	return(0);
  355
+}
  356
+
286 357
 void conf_interfaces(FILE *output, char *only)
287 358
 {
288 359
 	FILE *dhcpif, *llfile;
@@ -310,16 +381,14 @@ void conf_interfaces(FILE *output, char *only)
310 381
 	}
311 382
 
312 383
 	for (ifnp = ifn_list; ifnp->if_name != NULL; ifnp++) {
313  
-		strlcpy(ifr.ifr_name, ifnp->if_name, sizeof(ifr.ifr_name));
314  
-
315 384
 		if (only && !isprefix(only, ifnp->if_name))
316 385
 			/* only display interfaces which start with ... */
317 386
 			continue;
318  
-		if (!only) {
  387
+		if (!only && islateif(ifnp->if_name))
319 388
 			/* interface prefixes to exclude on generic run */
320  
-			if (isprefix("pfsync", ifnp->if_name))
321  
-				continue;
322  
-		}
  389
+			continue;
  390
+
  391
+		strlcpy(ifr.ifr_name, ifnp->if_name, sizeof(ifr.ifr_name));
323 392
 
324 393
 		if (ioctl(ifs, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
325 394
 			printf("%% conf: SIOCGIFFLAGS: %s\n", strerror(errno));
15  ctl.c
... ...
@@ -1,4 +1,4 @@
1  
-/* $nsh: ctl.c,v 1.29 2012/05/19 23:59:56 chris Exp $ */
  1
+/* $nsh: ctl.c,v 1.30 2012/05/23 05:45:35 chris Exp $ */
2 2
 /*
3 3
  * Copyright (c) 2008 Chris Cappuccio <chris@nmedia.net>
4 4
  *
@@ -44,6 +44,7 @@
44 44
 #define LDPD		"/usr/sbin/ldpd"
45 45
 #define SMTPD		"/usr/sbin/smtpd"
46 46
 #define LDAPD		"/usr/sbin/ldapd"
  47
+#define IFSTATED	"/usr/sbin/ifstated"
47 48
 #ifndef DHCPLEASES
48 49
 #define DHCPLEASES	"/var/db/dhcpd.leases"
49 50
 #endif
@@ -178,6 +179,17 @@ struct ctl ctl_dvmrp[] = {
178 179
 	{ 0, 0, { 0 }, 0, 0 }
179 180
 };
180 181
 
  182
+char *ctl_ifstate_test[] = { IFSTATED, "-nf", IFSTATECONF_TEMP, '\0' };
  183
+struct ctl ctl_ifstate[] = {
  184
+	{ "enable",     "enable service",
  185
+	    { IFSTATED, "-f", IFSTATECONF_TEMP, NULL }, NULL, X_ENABLE },
  186
+	{ "disable",    "disable service",
  187
+	    { PKILL, "ifstated", NULL }, NULL, X_DISABLE },
  188
+	{ "edit",       "edit configuration",
  189
+	    { "ifstate", (char *)ctl_ifstate_test,  NULL }, call_editor, NULL },
  190
+	{ 0, 0, { 0 }, 0, 0 }
  191
+};
  192
+
181 193
 struct ctl ctl_sasync[] = {
182 194
 	{ "enable",     "enable service",
183 195
 	    { SASYNCD, "-c", SASYNCCONF_TEMP, NULL }, NULL, X_ENABLE },
@@ -341,6 +353,7 @@ struct daemons ctl_daemons[] = {
341 353
 	{ "inet",	"Inet", ctl_inet,	INETCONF_TEMP,	0600, 0 },
342 354
 	{ "smtp",	"SMTP", ctl_smtp,	SMTPCONF_TEMP,	0600, 0 },
343 355
 	{ "ldap",	"LDAP", ctl_ldap,	LDAPCONF_TEMP,	0600, 0 },
  356
+	{ "ifstate",	"Interface state", ctl_ifstate,	IFSTATECONF_TEMP, 0600, 0 },
344 357
 	{ 0, 0, 0, 0, 0 }
345 358
 };
346 359
 
3  externs.h
... ...
@@ -1,4 +1,4 @@
1  
-/* $nsh: externs.h,v 1.78 2012/05/21 14:46:11 chris Exp $ */
  1
+/* $nsh: externs.h,v 1.79 2012/05/23 05:45:35 chris Exp $ */
2 2
 /*
3 3
  * nsh externs, prototypes and macros
4 4
  */
@@ -119,6 +119,7 @@ extern char metricnames[];
119 119
 #define SSHDCONF_TEMP	"/var/run/sshd.conf"
120 120
 #define SMTPCONF_TEMP 	"/var/run/smtpd.conf"
121 121
 #define LDAPCONF_TEMP	"/var/run/ldapd.conf"
  122
+#define IFSTATECONF_TEMP "/var/run/ifstated.conf"
122 123
 /* flag_x flags */
123 124
 #define X_ENABLE  (void *)1
124 125
 #define X_DISABLE (void *)2

0 notes on commit 71d1f50

Please sign in to comment.
Something went wrong with that request. Please try again.