Prototype support for /etc/netork/interfaces

This patch adds prototype support for the Debian/Ubuntu/Busybox network
configuration file /etc/netork/interfaces.  If this file exists Finit
will call `ifup` for each (non-commented-out) interface marked `auto`.

With this implementation we block boot until all ifup commands have
returned, which is less than ideal.  A better approach would be to ifup
only loopback and create deferred tasklets to be run in parallel with
the rest of the boot.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2016-07-21 16:11:50 +02:00
parent 42181a3031
commit 6380f17d1f
4 changed files with 53 additions and 26 deletions
-18
View File
@@ -23,7 +23,6 @@
#include "config.h" /* Generated by configure script */
#include <ctype.h>
#include <dirent.h>
#include <string.h>
#include <sys/resource.h>
@@ -41,23 +40,6 @@
static int parse_conf(char *file);
static char *strip_line(char *line)
{
char *ptr;
/* Trim leading whitespace */
while (*line && isblank(*line))
line++;
/* Strip any comment at end of line */
ptr = line;
while (*ptr && *ptr != '#')
ptr++;
*ptr = 0;
return line;
}
void conf_parse_cmdline(void)
{
FILE *fp;
+33 -8
View File
@@ -75,6 +75,8 @@ static void networking(void)
{
size_t i;
glob_t gl;
FILE *fp;
char buf[160];
/* Setup kernel specific settings, e.g. allow broadcast ping, etc. */
glob("/run/sysctl.d/*.conf", 0, NULL, &gl);
@@ -86,19 +88,42 @@ static void networking(void)
glob("/etc/sysctl.conf", GLOB_APPEND, NULL, &gl);
if (gl.gl_pathc > 0) {
for (i = 0; i < gl.gl_pathc; i++) {
char cmd[160];
snprintf(cmd, sizeof(cmd), "/sbin/sysctl -e -p %s >/dev/null", gl.gl_pathv[i]);
run(cmd);
snprintf(buf, sizeof(buf), "/sbin/sysctl -e -p %s >/dev/null", gl.gl_pathv[i]);
run(buf);
}
globfree(&gl);
}
/* Run user network start script, or fall back to at least loopback */
if (network)
/* Run user network start script if enabled */
if (network) {
run_interactive(network, "Starting networking: %s", network);
else
ifconfig("lo", "127.0.0.1", "255.0.0.0", 1);
return;
}
/* Debian/Ubuntu/Busybox interfaces file */
fp = fopen("/etc/network/interfaces", "r");
if (fp) {
i = 0;
/* Bring up all 'auto' interfaces */
while (fgets(buf, sizeof(buf), fp)) {
chomp(buf);
strip_line(buf);
if (!strncmp(buf, "auto", 4)) {
memcpy(buf, "ifup", 4);
run_interactive(buf, "Bringing up interface %s", buf[5]);
i++;
}
}
fclose(fp);
if (i)
return;
}
/* Fall back to bring up at least loopback */
ifconfig("lo", "127.0.0.1", "255.0.0.0", 1);
}
/* Requires /proc to be mounted */
+18
View File
@@ -22,6 +22,7 @@
* THE SOFTWARE.
*/
#include <ctype.h> /* isblank() */
#include <errno.h>
#include <grp.h>
#include <pwd.h>
@@ -39,6 +40,23 @@
#include "helpers.h"
#include "private.h"
char *strip_line(char *line)
{
char *ptr;
/* Trim leading whitespace */
while (*line && isblank(*line))
line++;
/* Strip any comment at end of line */
ptr = line;
while (*ptr && *ptr != '#')
ptr++;
*ptr = 0;
return line;
}
static int encode(int lvl)
{
if (!lvl) return 0;
+2
View File
@@ -61,6 +61,8 @@ do { \
#define _e(fmt, args...) do { fprintf(stderr, "finit:%s:%s() - " fmt "\n", __FILE__, __func__, ##args); } while (0)
#define _pe(fmt, args...) do { fprintf(stderr, "finit:%s:%s() - " fmt ". Error %d: %s\n", __FILE__, __func__, ##args, errno, strerror(errno)); } while (0)
char *strip_line (char *line);
void runlevel_set (int pre, int now);
char *runlevel_string (int levels);