Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 2 | /* |
| 3 | * ifupdown for busybox |
Denis Vlasenko | 0beaff8 | 2007-09-21 13:16:32 +0000 | [diff] [blame] | 4 | * Copyright (c) 2002 Glenn McGrath |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 5 | * Copyright (c) 2003-2004 Erik Andersen <andersen@codepoet.org> |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 6 | * |
| 7 | * Based on ifupdown v 0.6.4 by Anthony Towns |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 8 | * Copyright (c) 1999 Anthony Towns <aj@azure.humbug.org.au> |
| 9 | * |
Glenn L McGrath | 398ff9d | 2002-12-06 11:51:46 +0000 | [diff] [blame] | 10 | * Changes to upstream version |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 11 | * Remove checks for kernel version, assume kernel version 2.2.0 or better. |
Glenn L McGrath | 398ff9d | 2002-12-06 11:51:46 +0000 | [diff] [blame] | 12 | * Lines in the interfaces file cannot wrap. |
Denis Vlasenko | 2a86a61 | 2007-07-19 21:49:30 +0000 | [diff] [blame] | 13 | * To adhere to the FHS, the default state file is /var/run/ifstate |
| 14 | * (defined via CONFIG_IFUPDOWN_IFSTATE_PATH) and can be overridden by build |
| 15 | * configuration. |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 16 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 17 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 20 | //usage:#define ifup_trivial_usage |
| 21 | //usage: "[-an"IF_FEATURE_IFUPDOWN_MAPPING("m")"vf] [-i FILE] IFACE..." |
| 22 | //usage:#define ifup_full_usage "\n\n" |
Denys Vlasenko | 6642676 | 2011-06-05 03:58:28 +0200 | [diff] [blame] | 23 | //usage: " -a De/configure all interfaces automatically" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 24 | //usage: "\n -i FILE Use FILE for interface definitions" |
| 25 | //usage: "\n -n Print out what would happen, but don't do it" |
| 26 | //usage: IF_FEATURE_IFUPDOWN_MAPPING( |
| 27 | //usage: "\n (note: doesn't disable mappings)" |
| 28 | //usage: "\n -m Don't run any mappings" |
| 29 | //usage: ) |
| 30 | //usage: "\n -v Print out what would happen before doing it" |
| 31 | //usage: "\n -f Force de/configuration" |
| 32 | //usage: |
| 33 | //usage:#define ifdown_trivial_usage |
| 34 | //usage: "[-an"IF_FEATURE_IFUPDOWN_MAPPING("m")"vf] [-i FILE] IFACE..." |
| 35 | //usage:#define ifdown_full_usage "\n\n" |
Denys Vlasenko | 6642676 | 2011-06-05 03:58:28 +0200 | [diff] [blame] | 36 | //usage: " -a De/configure all interfaces automatically" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 37 | //usage: "\n -i FILE Use FILE for interface definitions" |
| 38 | //usage: "\n -n Print out what would happen, but don't do it" |
| 39 | //usage: IF_FEATURE_IFUPDOWN_MAPPING( |
| 40 | //usage: "\n (note: doesn't disable mappings)" |
| 41 | //usage: "\n -m Don't run any mappings" |
| 42 | //usage: ) |
| 43 | //usage: "\n -v Print out what would happen before doing it" |
| 44 | //usage: "\n -f Force de/configuration" |
| 45 | |
Denys Vlasenko | 043b1e5 | 2009-09-06 12:47:55 +0200 | [diff] [blame] | 46 | #include "libbb.h" |
| 47 | /* After libbb.h, since it needs sys/types.h on some systems */ |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 48 | #include <sys/utsname.h> |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 49 | #include <fnmatch.h> |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 50 | |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 51 | #define MAX_OPT_DEPTH 10 |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 52 | |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 53 | #if ENABLE_FEATURE_IFUPDOWN_MAPPING |
Eric Andersen | 233b170 | 2003-06-05 19:37:01 +0000 | [diff] [blame] | 54 | #define MAX_INTERFACE_LENGTH 10 |
| 55 | #endif |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 56 | |
Wade Berrier | 142c5cb | 2008-11-14 21:18:45 +0000 | [diff] [blame] | 57 | #define UDHCPC_CMD_OPTIONS CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS |
| 58 | |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 59 | #define debug_noise(args...) /*fprintf(stderr, args)*/ |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 60 | |
| 61 | /* Forward declaration */ |
| 62 | struct interface_defn_t; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 63 | |
Denis Vlasenko | 097c324 | 2006-11-27 16:59:15 +0000 | [diff] [blame] | 64 | typedef int execfn(char *command); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 65 | |
Denis Vlasenko | 89ef65f | 2007-01-29 23:43:18 +0000 | [diff] [blame] | 66 | struct method_t { |
| 67 | const char *name; |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 68 | int (*up)(struct interface_defn_t *ifd, execfn *e) FAST_FUNC; |
| 69 | int (*down)(struct interface_defn_t *ifd, execfn *e) FAST_FUNC; |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 70 | }; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 71 | |
Denis Vlasenko | 89ef65f | 2007-01-29 23:43:18 +0000 | [diff] [blame] | 72 | struct address_family_t { |
| 73 | const char *name; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 74 | int n_methods; |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 75 | const struct method_t *method; |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 76 | }; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 77 | |
Denis Vlasenko | 89ef65f | 2007-01-29 23:43:18 +0000 | [diff] [blame] | 78 | struct mapping_defn_t { |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 79 | struct mapping_defn_t *next; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 80 | |
| 81 | int max_matches; |
| 82 | int n_matches; |
| 83 | char **match; |
| 84 | |
| 85 | char *script; |
| 86 | |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 87 | int n_mappings; |
| 88 | char **mapping; |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 89 | }; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 90 | |
Denis Vlasenko | 89ef65f | 2007-01-29 23:43:18 +0000 | [diff] [blame] | 91 | struct variable_t { |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 92 | char *name; |
| 93 | char *value; |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 94 | }; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 95 | |
Denis Vlasenko | 89ef65f | 2007-01-29 23:43:18 +0000 | [diff] [blame] | 96 | struct interface_defn_t { |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 97 | const struct address_family_t *address_family; |
| 98 | const struct method_t *method; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 99 | |
Rob Landley | e813ddb | 2006-02-28 03:53:14 +0000 | [diff] [blame] | 100 | char *iface; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 101 | int n_options; |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 102 | struct variable_t *option; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
Denis Vlasenko | 89ef65f | 2007-01-29 23:43:18 +0000 | [diff] [blame] | 105 | struct interfaces_file_t { |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 106 | llist_t *autointerfaces; |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 107 | llist_t *ifaces; |
| 108 | struct mapping_defn_t *mappings; |
| 109 | }; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 110 | |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 111 | |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 112 | #define OPTION_STR "anvf" IF_FEATURE_IFUPDOWN_MAPPING("m") "i:" |
Denis Vlasenko | 7f1f5b0 | 2006-09-23 12:49:01 +0000 | [diff] [blame] | 113 | enum { |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 114 | OPT_do_all = 0x1, |
| 115 | OPT_no_act = 0x2, |
| 116 | OPT_verbose = 0x4, |
| 117 | OPT_force = 0x8, |
Denis Vlasenko | 7f1f5b0 | 2006-09-23 12:49:01 +0000 | [diff] [blame] | 118 | OPT_no_mappings = 0x10, |
| 119 | }; |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 120 | #define DO_ALL (option_mask32 & OPT_do_all) |
| 121 | #define NO_ACT (option_mask32 & OPT_no_act) |
| 122 | #define VERBOSE (option_mask32 & OPT_verbose) |
| 123 | #define FORCE (option_mask32 & OPT_force) |
Denis Vlasenko | c12f530 | 2006-10-06 09:49:47 +0000 | [diff] [blame] | 124 | #define NO_MAPPINGS (option_mask32 & OPT_no_mappings) |
Denis Vlasenko | 7f1f5b0 | 2006-09-23 12:49:01 +0000 | [diff] [blame] | 125 | |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 126 | |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 127 | struct globals { |
| 128 | char **my_environ; |
| 129 | const char *startup_PATH; |
Denys Vlasenko | 681efe2 | 2011-03-08 21:00:36 +0100 | [diff] [blame] | 130 | char *shell; |
Denys Vlasenko | 98a4c7c | 2010-02-04 15:00:15 +0100 | [diff] [blame] | 131 | } FIX_ALIASING; |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 132 | #define G (*(struct globals*)&bb_common_bufsiz1) |
| 133 | #define INIT_G() do { } while (0) |
| 134 | |
Denis Vlasenko | 2f4399c | 2006-09-27 14:14:51 +0000 | [diff] [blame] | 135 | |
Denys Vlasenko | 9c28fb8 | 2011-10-19 02:37:08 +0200 | [diff] [blame] | 136 | static const char keywords_up_down[] ALIGN1 = |
| 137 | "up\0" |
| 138 | "down\0" |
| 139 | "pre-up\0" |
Denys Vlasenko | 9c28fb8 | 2011-10-19 02:37:08 +0200 | [diff] [blame] | 140 | "post-down\0" |
| 141 | ; |
| 142 | |
| 143 | |
Mike Frysinger | b049c0e | 2006-06-20 23:03:27 +0000 | [diff] [blame] | 144 | #if ENABLE_FEATURE_IFUPDOWN_IPV4 || ENABLE_FEATURE_IFUPDOWN_IPV6 |
| 145 | |
Denis Vlasenko | 93ad1c2 | 2006-11-23 15:07:38 +0000 | [diff] [blame] | 146 | static void addstr(char **bufp, const char *str, size_t str_length) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 147 | { |
Denis Vlasenko | 93ad1c2 | 2006-11-23 15:07:38 +0000 | [diff] [blame] | 148 | /* xasprintf trick will be smaller, but we are often |
| 149 | * called with str_length == 1 - don't want to have |
| 150 | * THAT much of malloc/freeing! */ |
| 151 | char *buf = *bufp; |
| 152 | int len = (buf ? strlen(buf) : 0); |
| 153 | str_length++; |
| 154 | buf = xrealloc(buf, len + str_length); |
| 155 | /* copies at most str_length-1 chars! */ |
| 156 | safe_strncpy(buf + len, str, str_length); |
| 157 | *bufp = buf; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Denis Vlasenko | f6f43df | 2006-10-11 22:16:56 +0000 | [diff] [blame] | 160 | static int strncmpz(const char *l, const char *r, size_t llen) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 161 | { |
| 162 | int i = strncmp(l, r, llen); |
| 163 | |
Denis Vlasenko | 93ad1c2 | 2006-11-23 15:07:38 +0000 | [diff] [blame] | 164 | if (i == 0) |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 165 | return - (unsigned char)r[llen]; |
Denis Vlasenko | 93ad1c2 | 2006-11-23 15:07:38 +0000 | [diff] [blame] | 166 | return i; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Denis Vlasenko | f6f43df | 2006-10-11 22:16:56 +0000 | [diff] [blame] | 169 | static char *get_var(const char *id, size_t idlen, struct interface_defn_t *ifd) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 170 | { |
| 171 | int i; |
| 172 | |
| 173 | if (strncmpz(id, "iface", idlen) == 0) { |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 174 | // ubuntu's ifup doesn't do this: |
| 175 | //static char *label_buf; |
Denis Vlasenko | ff2b6d2 | 2007-11-23 03:39:45 +0000 | [diff] [blame] | 176 | //char *result; |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 177 | //free(label_buf); |
| 178 | //label_buf = xstrdup(ifd->iface); |
| 179 | // Remove virtual iface suffix |
Denis Vlasenko | ff2b6d2 | 2007-11-23 03:39:45 +0000 | [diff] [blame] | 180 | //result = strchrnul(label_buf, ':'); |
| 181 | //*result = '\0'; |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 182 | //return label_buf; |
| 183 | |
| 184 | return ifd->iface; |
Denis Vlasenko | 93ad1c2 | 2006-11-23 15:07:38 +0000 | [diff] [blame] | 185 | } |
| 186 | if (strncmpz(id, "label", idlen) == 0) { |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 187 | return ifd->iface; |
Denis Vlasenko | 93ad1c2 | 2006-11-23 15:07:38 +0000 | [diff] [blame] | 188 | } |
| 189 | for (i = 0; i < ifd->n_options; i++) { |
| 190 | if (strncmpz(id, ifd->option[i].name, idlen) == 0) { |
| 191 | return ifd->option[i].value; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 192 | } |
| 193 | } |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 194 | return NULL; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 197 | # if ENABLE_FEATURE_IFUPDOWN_IP |
Denis Vlasenko | a483691 | 2007-07-03 08:26:24 +0000 | [diff] [blame] | 198 | static int count_netmask_bits(const char *dotted_quad) |
| 199 | { |
| 200 | // int result; |
| 201 | // unsigned a, b, c, d; |
| 202 | // /* Found a netmask... Check if it is dotted quad */ |
| 203 | // if (sscanf(dotted_quad, "%u.%u.%u.%u", &a, &b, &c, &d) != 4) |
| 204 | // return -1; |
| 205 | // if ((a|b|c|d) >> 8) |
| 206 | // return -1; /* one of numbers is >= 256 */ |
| 207 | // d |= (a << 24) | (b << 16) | (c << 8); /* IP */ |
| 208 | // d = ~d; /* 11110000 -> 00001111 */ |
| 209 | |
| 210 | /* Shorter version */ |
| 211 | int result; |
| 212 | struct in_addr ip; |
| 213 | unsigned d; |
| 214 | |
| 215 | if (inet_aton(dotted_quad, &ip) == 0) |
| 216 | return -1; /* malformed dotted IP */ |
| 217 | d = ntohl(ip.s_addr); /* IP in host order */ |
| 218 | d = ~d; /* 11110000 -> 00001111 */ |
| 219 | if (d & (d+1)) /* check that it is in 00001111 form */ |
| 220 | return -1; /* no it is not */ |
| 221 | result = 32; |
| 222 | while (d) { |
| 223 | d >>= 1; |
| 224 | result--; |
| 225 | } |
| 226 | return result; |
| 227 | } |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 228 | # endif |
Denis Vlasenko | a483691 | 2007-07-03 08:26:24 +0000 | [diff] [blame] | 229 | |
Denis Vlasenko | f6f43df | 2006-10-11 22:16:56 +0000 | [diff] [blame] | 230 | static char *parse(const char *command, struct interface_defn_t *ifd) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 231 | { |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 232 | size_t old_pos[MAX_OPT_DEPTH] = { 0 }; |
Denys Vlasenko | 3f21044 | 2012-11-09 17:16:40 +0100 | [diff] [blame] | 233 | smallint okay[MAX_OPT_DEPTH] = { 1 }; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 234 | int opt_depth = 1; |
Denis Vlasenko | 8cd1a28 | 2006-12-19 23:01:33 +0000 | [diff] [blame] | 235 | char *result = NULL; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 236 | |
| 237 | while (*command) { |
| 238 | switch (*command) { |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 239 | default: |
Denis Vlasenko | 93ad1c2 | 2006-11-23 15:07:38 +0000 | [diff] [blame] | 240 | addstr(&result, command, 1); |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 241 | command++; |
| 242 | break; |
| 243 | case '\\': |
Denys Vlasenko | 3f21044 | 2012-11-09 17:16:40 +0100 | [diff] [blame] | 244 | if (command[1]) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 245 | command++; |
Denys Vlasenko | 3f21044 | 2012-11-09 17:16:40 +0100 | [diff] [blame] | 246 | addstr(&result, command, 1); |
| 247 | command++; |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 248 | break; |
| 249 | case '[': |
| 250 | if (command[1] == '[' && opt_depth < MAX_OPT_DEPTH) { |
Denis Vlasenko | 8cd1a28 | 2006-12-19 23:01:33 +0000 | [diff] [blame] | 251 | old_pos[opt_depth] = result ? strlen(result) : 0; |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 252 | okay[opt_depth] = 1; |
| 253 | opt_depth++; |
| 254 | command += 2; |
| 255 | } else { |
Denys Vlasenko | 1118133 | 2012-11-05 13:22:56 +0100 | [diff] [blame] | 256 | addstr(&result, command, 1); |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 257 | command++; |
| 258 | } |
| 259 | break; |
| 260 | case ']': |
| 261 | if (command[1] == ']' && opt_depth > 1) { |
| 262 | opt_depth--; |
| 263 | if (!okay[opt_depth]) { |
Denis Vlasenko | 93ad1c2 | 2006-11-23 15:07:38 +0000 | [diff] [blame] | 264 | result[old_pos[opt_depth]] = '\0'; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 265 | } |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 266 | command += 2; |
| 267 | } else { |
Denys Vlasenko | 1118133 | 2012-11-05 13:22:56 +0100 | [diff] [blame] | 268 | addstr(&result, command, 1); |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 269 | command++; |
| 270 | } |
| 271 | break; |
| 272 | case '%': |
| 273 | { |
| 274 | char *nextpercent; |
| 275 | char *varvalue; |
| 276 | |
| 277 | command++; |
| 278 | nextpercent = strchr(command, '%'); |
| 279 | if (!nextpercent) { |
Denys Vlasenko | a803bfa | 2012-11-05 14:18:36 +0100 | [diff] [blame] | 280 | /* Unterminated %var% */ |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 281 | free(result); |
| 282 | return NULL; |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 283 | } |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 284 | |
| 285 | varvalue = get_var(command, nextpercent - command, ifd); |
| 286 | |
| 287 | if (varvalue) { |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 288 | # if ENABLE_FEATURE_IFUPDOWN_IP |
Denis Vlasenko | ee777c4 | 2008-08-12 01:35:34 +0000 | [diff] [blame] | 289 | /* "hwaddress <class> <address>": |
| 290 | * unlike ifconfig, ip doesnt want <class> |
| 291 | * (usually "ether" keyword). Skip it. */ |
| 292 | if (strncmp(command, "hwaddress", 9) == 0) { |
| 293 | varvalue = skip_whitespace(skip_non_whitespace(varvalue)); |
| 294 | } |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 295 | # endif |
Denis Vlasenko | 93ad1c2 | 2006-11-23 15:07:38 +0000 | [diff] [blame] | 296 | addstr(&result, varvalue, strlen(varvalue)); |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 297 | } else { |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 298 | # if ENABLE_FEATURE_IFUPDOWN_IP |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 299 | /* Sigh... Add a special case for 'ip' to convert from |
| 300 | * dotted quad to bit count style netmasks. */ |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 301 | if (strncmp(command, "bnmask", 6) == 0) { |
Denis Vlasenko | 93ad1c2 | 2006-11-23 15:07:38 +0000 | [diff] [blame] | 302 | unsigned res; |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 303 | varvalue = get_var("netmask", 7, ifd); |
Denis Vlasenko | a483691 | 2007-07-03 08:26:24 +0000 | [diff] [blame] | 304 | if (varvalue) { |
| 305 | res = count_netmask_bits(varvalue); |
| 306 | if (res > 0) { |
| 307 | const char *argument = utoa(res); |
| 308 | addstr(&result, argument, strlen(argument)); |
| 309 | command = nextpercent + 1; |
| 310 | break; |
| 311 | } |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 312 | } |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 313 | } |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 314 | # endif |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 315 | okay[opt_depth - 1] = 0; |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 316 | } |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 317 | |
| 318 | command = nextpercent + 1; |
| 319 | } |
| 320 | break; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | |
| 324 | if (opt_depth > 1) { |
Denys Vlasenko | a803bfa | 2012-11-05 14:18:36 +0100 | [diff] [blame] | 325 | /* Unbalanced bracket */ |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 326 | free(result); |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 327 | return NULL; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | if (!okay[0]) { |
Denys Vlasenko | a803bfa | 2012-11-05 14:18:36 +0100 | [diff] [blame] | 331 | /* Undefined variable and we aren't in a bracket */ |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 332 | free(result); |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 333 | return NULL; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 334 | } |
| 335 | |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 336 | return result; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 339 | /* execute() returns 1 for success and 0 for failure */ |
Denis Vlasenko | f6f43df | 2006-10-11 22:16:56 +0000 | [diff] [blame] | 340 | static int execute(const char *command, struct interface_defn_t *ifd, execfn *exec) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 341 | { |
| 342 | char *out; |
| 343 | int ret; |
| 344 | |
| 345 | out = parse(command, ifd); |
Denis Vlasenko | 8cd1a28 | 2006-12-19 23:01:33 +0000 | [diff] [blame] | 346 | if (!out) { |
Denis Vlasenko | 2375d75 | 2006-12-19 23:15:46 +0000 | [diff] [blame] | 347 | /* parse error? */ |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 348 | return 0; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 349 | } |
Denis Vlasenko | 2375d75 | 2006-12-19 23:15:46 +0000 | [diff] [blame] | 350 | /* out == "": parsed ok but not all needed variables known, skip */ |
| 351 | ret = out[0] ? (*exec)(out) : 1; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 352 | |
| 353 | free(out); |
Glenn L McGrath | 0177ce1 | 2004-07-21 23:56:31 +0000 | [diff] [blame] | 354 | if (ret != 1) { |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 355 | return 0; |
Glenn L McGrath | 0177ce1 | 2004-07-21 23:56:31 +0000 | [diff] [blame] | 356 | } |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 357 | return 1; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 358 | } |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 359 | |
| 360 | #endif /* FEATURE_IFUPDOWN_IPV4 || FEATURE_IFUPDOWN_IPV6 */ |
| 361 | |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 362 | |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 363 | #if ENABLE_FEATURE_IFUPDOWN_IPV6 |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 364 | |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 365 | static int FAST_FUNC loopback_up6(struct interface_defn_t *ifd, execfn *exec) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 366 | { |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 367 | # if ENABLE_FEATURE_IFUPDOWN_IP |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 368 | int result; |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 369 | result = execute("ip addr add ::1 dev %iface%", ifd, exec); |
Eric Andersen | 8a93179 | 2003-07-03 10:20:29 +0000 | [diff] [blame] | 370 | result += execute("ip link set %iface% up", ifd, exec); |
Glenn L McGrath | 0177ce1 | 2004-07-21 23:56:31 +0000 | [diff] [blame] | 371 | return ((result == 2) ? 2 : 0); |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 372 | # else |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 373 | return execute("ifconfig %iface% add ::1", ifd, exec); |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 374 | # endif |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 377 | static int FAST_FUNC loopback_down6(struct interface_defn_t *ifd, execfn *exec) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 378 | { |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 379 | # if ENABLE_FEATURE_IFUPDOWN_IP |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 380 | return execute("ip link set %iface% down", ifd, exec); |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 381 | # else |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 382 | return execute("ifconfig %iface% del ::1", ifd, exec); |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 383 | # endif |
| 384 | } |
| 385 | |
| 386 | static int FAST_FUNC manual_up_down6(struct interface_defn_t *ifd UNUSED_PARAM, execfn *exec UNUSED_PARAM) |
| 387 | { |
| 388 | return 1; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 389 | } |
| 390 | |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 391 | static int FAST_FUNC static_up6(struct interface_defn_t *ifd, execfn *exec) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 392 | { |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 393 | int result; |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 394 | # if ENABLE_FEATURE_IFUPDOWN_IP |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 395 | result = execute("ip addr add %address%/%netmask% dev %iface%[[ label %label%]]", ifd, exec); |
Denis Vlasenko | 44d5dce | 2008-11-01 00:10:51 +0000 | [diff] [blame] | 396 | result += execute("ip link set[[ mtu %mtu%]][[ addr %hwaddress%]] %iface% up", ifd, exec); |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 397 | /* Was: "[[ ip ....%gateway% ]]". Removed extra spaces w/o checking */ |
Natanael Copa | cfcb1da | 2012-02-17 19:36:26 +0000 | [diff] [blame] | 398 | result += execute("[[ip route add ::/0 via %gateway%]][[ prio %metric%]]", ifd, exec); |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 399 | # else |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 400 | result = execute("ifconfig %iface%[[ media %media%]][[ hw %hwaddress%]][[ mtu %mtu%]] up", ifd, exec); |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 401 | result += execute("ifconfig %iface% add %address%/%netmask%", ifd, exec); |
Natanael Copa | cfcb1da | 2012-02-17 19:36:26 +0000 | [diff] [blame] | 402 | result += execute("[[route -A inet6 add ::/0 gw %gateway%[[ metric %metric%]]]]", ifd, exec); |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 403 | # endif |
Glenn L McGrath | 0177ce1 | 2004-07-21 23:56:31 +0000 | [diff] [blame] | 404 | return ((result == 3) ? 3 : 0); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 405 | } |
| 406 | |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 407 | static int FAST_FUNC static_down6(struct interface_defn_t *ifd, execfn *exec) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 408 | { |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 409 | # if ENABLE_FEATURE_IFUPDOWN_IP |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 410 | return execute("ip link set %iface% down", ifd, exec); |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 411 | # else |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 412 | return execute("ifconfig %iface% down", ifd, exec); |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 413 | # endif |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 414 | } |
| 415 | |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 416 | # if ENABLE_FEATURE_IFUPDOWN_IP |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 417 | static int FAST_FUNC v4tunnel_up(struct interface_defn_t *ifd, execfn *exec) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 418 | { |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 419 | int result; |
| 420 | result = execute("ip tunnel add %iface% mode sit remote " |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 421 | "%endpoint%[[ local %local%]][[ ttl %ttl%]]", ifd, exec); |
Eric Andersen | 8a93179 | 2003-07-03 10:20:29 +0000 | [diff] [blame] | 422 | result += execute("ip link set %iface% up", ifd, exec); |
Glenn L McGrath | 62b031f | 2003-08-29 07:47:52 +0000 | [diff] [blame] | 423 | result += execute("ip addr add %address%/%netmask% dev %iface%", ifd, exec); |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 424 | result += execute("[[ip route add ::/0 via %gateway%]]", ifd, exec); |
Glenn L McGrath | 0177ce1 | 2004-07-21 23:56:31 +0000 | [diff] [blame] | 425 | return ((result == 4) ? 4 : 0); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 428 | static int FAST_FUNC v4tunnel_down(struct interface_defn_t * ifd, execfn * exec) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 429 | { |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 430 | return execute("ip tunnel del %iface%", ifd, exec); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 431 | } |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 432 | # endif |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 433 | |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 434 | static const struct method_t methods6[] = { |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 435 | # if ENABLE_FEATURE_IFUPDOWN_IP |
| 436 | { "v4tunnel" , v4tunnel_up , v4tunnel_down , }, |
| 437 | # endif |
| 438 | { "static" , static_up6 , static_down6 , }, |
| 439 | { "manual" , manual_up_down6 , manual_up_down6 , }, |
| 440 | { "loopback" , loopback_up6 , loopback_down6 , }, |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 441 | }; |
| 442 | |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 443 | static const struct address_family_t addr_inet6 = { |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 444 | "inet6", |
Denis Vlasenko | 80b8b39 | 2007-06-25 10:55:35 +0000 | [diff] [blame] | 445 | ARRAY_SIZE(methods6), |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 446 | methods6 |
| 447 | }; |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 448 | |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 449 | #endif /* FEATURE_IFUPDOWN_IPV6 */ |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 450 | |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 451 | |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 452 | #if ENABLE_FEATURE_IFUPDOWN_IPV4 |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 453 | |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 454 | static int FAST_FUNC loopback_up(struct interface_defn_t *ifd, execfn *exec) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 455 | { |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 456 | # if ENABLE_FEATURE_IFUPDOWN_IP |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 457 | int result; |
Eric Andersen | fdd2a0f | 2003-08-06 09:23:44 +0000 | [diff] [blame] | 458 | result = execute("ip addr add 127.0.0.1/8 dev %iface%", ifd, exec); |
Eric Andersen | 8a93179 | 2003-07-03 10:20:29 +0000 | [diff] [blame] | 459 | result += execute("ip link set %iface% up", ifd, exec); |
Glenn L McGrath | 0177ce1 | 2004-07-21 23:56:31 +0000 | [diff] [blame] | 460 | return ((result == 2) ? 2 : 0); |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 461 | # else |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 462 | return execute("ifconfig %iface% 127.0.0.1 up", ifd, exec); |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 463 | # endif |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 466 | static int FAST_FUNC loopback_down(struct interface_defn_t *ifd, execfn *exec) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 467 | { |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 468 | # if ENABLE_FEATURE_IFUPDOWN_IP |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 469 | int result; |
| 470 | result = execute("ip addr flush dev %iface%", ifd, exec); |
| 471 | result += execute("ip link set %iface% down", ifd, exec); |
Glenn L McGrath | 0177ce1 | 2004-07-21 23:56:31 +0000 | [diff] [blame] | 472 | return ((result == 2) ? 2 : 0); |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 473 | # else |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 474 | return execute("ifconfig %iface% 127.0.0.1 down", ifd, exec); |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 475 | # endif |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 476 | } |
| 477 | |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 478 | static int FAST_FUNC static_up(struct interface_defn_t *ifd, execfn *exec) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 479 | { |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 480 | int result; |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 481 | # if ENABLE_FEATURE_IFUPDOWN_IP |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 482 | result = execute("ip addr add %address%/%bnmask%[[ broadcast %broadcast%]] " |
| 483 | "dev %iface%[[ peer %pointopoint%]][[ label %label%]]", ifd, exec); |
Denis Vlasenko | 44d5dce | 2008-11-01 00:10:51 +0000 | [diff] [blame] | 484 | result += execute("ip link set[[ mtu %mtu%]][[ addr %hwaddress%]] %iface% up", ifd, exec); |
Natanael Copa | cfcb1da | 2012-02-17 19:36:26 +0000 | [diff] [blame] | 485 | result += execute("[[ip route add default via %gateway% dev %iface%[[ prio %metric%]]]]", ifd, exec); |
Glenn L McGrath | 0177ce1 | 2004-07-21 23:56:31 +0000 | [diff] [blame] | 486 | return ((result == 3) ? 3 : 0); |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 487 | # else |
Denis Vlasenko | a741b77 | 2006-11-23 15:08:37 +0000 | [diff] [blame] | 488 | /* ifconfig said to set iface up before it processes hw %hwaddress%, |
| 489 | * which then of course fails. Thus we run two separate ifconfig */ |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 490 | result = execute("ifconfig %iface%[[ hw %hwaddress%]][[ media %media%]][[ mtu %mtu%]] up", |
Denis Vlasenko | a741b77 | 2006-11-23 15:08:37 +0000 | [diff] [blame] | 491 | ifd, exec); |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 492 | result += execute("ifconfig %iface% %address% netmask %netmask%" |
| 493 | "[[ broadcast %broadcast%]][[ pointopoint %pointopoint%]] ", |
Denis Vlasenko | a741b77 | 2006-11-23 15:08:37 +0000 | [diff] [blame] | 494 | ifd, exec); |
Natanael Copa | cfcb1da | 2012-02-17 19:36:26 +0000 | [diff] [blame] | 495 | result += execute("[[route add default gw %gateway%[[ metric %metric%]] %iface%]]", ifd, exec); |
Denis Vlasenko | a741b77 | 2006-11-23 15:08:37 +0000 | [diff] [blame] | 496 | return ((result == 3) ? 3 : 0); |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 497 | # endif |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 498 | } |
| 499 | |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 500 | static int FAST_FUNC static_down(struct interface_defn_t *ifd, execfn *exec) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 501 | { |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 502 | int result; |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 503 | # if ENABLE_FEATURE_IFUPDOWN_IP |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 504 | result = execute("ip addr flush dev %iface%", ifd, exec); |
| 505 | result += execute("ip link set %iface% down", ifd, exec); |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 506 | # else |
Denis Vlasenko | 6c4eb44 | 2008-08-19 23:02:23 +0000 | [diff] [blame] | 507 | /* result = execute("[[route del default gw %gateway% %iface%]]", ifd, exec); */ |
| 508 | /* Bringing the interface down deletes the routes in itself. |
| 509 | Otherwise this fails if we reference 'gateway' when using this from dhcp_down */ |
| 510 | result = 1; |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 511 | result += execute("ifconfig %iface% down", ifd, exec); |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 512 | # endif |
Glenn L McGrath | 0177ce1 | 2004-07-21 23:56:31 +0000 | [diff] [blame] | 513 | return ((result == 2) ? 2 : 0); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 514 | } |
| 515 | |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 516 | # if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 517 | struct dhcp_client_t { |
Denis Vlasenko | f6f43df | 2006-10-11 22:16:56 +0000 | [diff] [blame] | 518 | const char *name; |
| 519 | const char *startcmd; |
| 520 | const char *stopcmd; |
| 521 | }; |
| 522 | |
| 523 | static const struct dhcp_client_t ext_dhcp_clients[] = { |
Denis Vlasenko | eda43d7 | 2007-05-02 22:04:38 +0000 | [diff] [blame] | 524 | { "dhcpcd", |
Denys Vlasenko | 2ab3acb | 2010-09-03 16:58:37 +0200 | [diff] [blame] | 525 | "dhcpcd[[ -h %hostname%]][[ -i %vendor%]][[ -I %client%]][[ -l %leasetime%]] %iface%", |
Denis Vlasenko | eda43d7 | 2007-05-02 22:04:38 +0000 | [diff] [blame] | 526 | "dhcpcd -k %iface%", |
Denis Vlasenko | f6f43df | 2006-10-11 22:16:56 +0000 | [diff] [blame] | 527 | }, |
| 528 | { "dhclient", |
| 529 | "dhclient -pf /var/run/dhclient.%iface%.pid %iface%", |
| 530 | "kill -9 `cat /var/run/dhclient.%iface%.pid` 2>/dev/null", |
| 531 | }, |
Denis Vlasenko | eda43d7 | 2007-05-02 22:04:38 +0000 | [diff] [blame] | 532 | { "pump", |
| 533 | "pump -i %iface%[[ -h %hostname%]][[ -l %leasehours%]]", |
| 534 | "pump -i %iface% -k", |
| 535 | }, |
| 536 | { "udhcpc", |
Denys Vlasenko | 2ab3acb | 2010-09-03 16:58:37 +0200 | [diff] [blame] | 537 | "udhcpc " UDHCPC_CMD_OPTIONS " -p /var/run/udhcpc.%iface%.pid -i %iface%[[ -H %hostname%]][[ -c %client%]]" |
Denis Vlasenko | 2e4c3c4 | 2008-04-02 13:04:19 +0000 | [diff] [blame] | 538 | "[[ -s %script%]][[ %udhcpc_opts%]]", |
Denis Vlasenko | a483691 | 2007-07-03 08:26:24 +0000 | [diff] [blame] | 539 | "kill `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", |
Denis Vlasenko | f6f43df | 2006-10-11 22:16:56 +0000 | [diff] [blame] | 540 | }, |
| 541 | }; |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 542 | # endif /* FEATURE_IFUPDOWN_EXTERNAL_DHCPC */ |
Denis Vlasenko | f6f43df | 2006-10-11 22:16:56 +0000 | [diff] [blame] | 543 | |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 544 | # if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 545 | static int FAST_FUNC dhcp_up(struct interface_defn_t *ifd, execfn *exec) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 546 | { |
Denis Vlasenko | 6b06cb8 | 2008-05-15 21:30:45 +0000 | [diff] [blame] | 547 | unsigned i; |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 548 | # if ENABLE_FEATURE_IFUPDOWN_IP |
Denis Vlasenko | 6cd84da | 2007-07-21 14:57:54 +0000 | [diff] [blame] | 549 | /* ip doesn't up iface when it configures it (unlike ifconfig) */ |
Denis Vlasenko | 44d5dce | 2008-11-01 00:10:51 +0000 | [diff] [blame] | 550 | if (!execute("ip link set[[ addr %hwaddress%]] %iface% up", ifd, exec)) |
Denis Vlasenko | ee777c4 | 2008-08-12 01:35:34 +0000 | [diff] [blame] | 551 | return 0; |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 552 | # else |
Denis Vlasenko | ee777c4 | 2008-08-12 01:35:34 +0000 | [diff] [blame] | 553 | /* needed if we have hwaddress on dhcp iface */ |
| 554 | if (!execute("ifconfig %iface%[[ hw %hwaddress%]] up", ifd, exec)) |
Denis Vlasenko | 6cd84da | 2007-07-21 14:57:54 +0000 | [diff] [blame] | 555 | return 0; |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 556 | # endif |
Denis Vlasenko | 80b8b39 | 2007-06-25 10:55:35 +0000 | [diff] [blame] | 557 | for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) { |
Denis Vlasenko | f6f43df | 2006-10-11 22:16:56 +0000 | [diff] [blame] | 558 | if (exists_execable(ext_dhcp_clients[i].name)) |
| 559 | return execute(ext_dhcp_clients[i].startcmd, ifd, exec); |
| 560 | } |
| 561 | bb_error_msg("no dhcp clients found"); |
Denis Vlasenko | 2f4399c | 2006-09-27 14:14:51 +0000 | [diff] [blame] | 562 | return 0; |
Denis Vlasenko | 85c2471 | 2008-03-17 09:04:04 +0000 | [diff] [blame] | 563 | } |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 564 | # elif ENABLE_UDHCPC |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 565 | static int FAST_FUNC dhcp_up(struct interface_defn_t *ifd, execfn *exec) |
Denis Vlasenko | 85c2471 | 2008-03-17 09:04:04 +0000 | [diff] [blame] | 566 | { |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 567 | # if ENABLE_FEATURE_IFUPDOWN_IP |
Denis Vlasenko | 6cd84da | 2007-07-21 14:57:54 +0000 | [diff] [blame] | 568 | /* ip doesn't up iface when it configures it (unlike ifconfig) */ |
Denis Vlasenko | 44d5dce | 2008-11-01 00:10:51 +0000 | [diff] [blame] | 569 | if (!execute("ip link set[[ addr %hwaddress%]] %iface% up", ifd, exec)) |
Denis Vlasenko | ee777c4 | 2008-08-12 01:35:34 +0000 | [diff] [blame] | 570 | return 0; |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 571 | # else |
Denis Vlasenko | ee777c4 | 2008-08-12 01:35:34 +0000 | [diff] [blame] | 572 | /* needed if we have hwaddress on dhcp iface */ |
| 573 | if (!execute("ifconfig %iface%[[ hw %hwaddress%]] up", ifd, exec)) |
Denis Vlasenko | 6cd84da | 2007-07-21 14:57:54 +0000 | [diff] [blame] | 574 | return 0; |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 575 | # endif |
Wade Berrier | 142c5cb | 2008-11-14 21:18:45 +0000 | [diff] [blame] | 576 | return execute("udhcpc " UDHCPC_CMD_OPTIONS " -p /var/run/udhcpc.%iface%.pid " |
Denys Vlasenko | 2ab3acb | 2010-09-03 16:58:37 +0200 | [diff] [blame] | 577 | "-i %iface%[[ -H %hostname%]][[ -c %client%]][[ -s %script%]][[ %udhcpc_opts%]]", |
Denis Vlasenko | eda43d7 | 2007-05-02 22:04:38 +0000 | [diff] [blame] | 578 | ifd, exec); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 579 | } |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 580 | # else |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 581 | static int FAST_FUNC dhcp_up(struct interface_defn_t *ifd UNUSED_PARAM, |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 582 | execfn *exec UNUSED_PARAM) |
Denis Vlasenko | 85c2471 | 2008-03-17 09:04:04 +0000 | [diff] [blame] | 583 | { |
| 584 | return 0; /* no dhcp support */ |
| 585 | } |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 586 | # endif |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 587 | |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 588 | # if ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCP |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 589 | static int FAST_FUNC dhcp_down(struct interface_defn_t *ifd, execfn *exec) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 590 | { |
Denis Vlasenko | 6c4eb44 | 2008-08-19 23:02:23 +0000 | [diff] [blame] | 591 | int result = 0; |
Denis Vlasenko | 6b06cb8 | 2008-05-15 21:30:45 +0000 | [diff] [blame] | 592 | unsigned i; |
Denis Vlasenko | 6c4eb44 | 2008-08-19 23:02:23 +0000 | [diff] [blame] | 593 | |
Denis Vlasenko | 80b8b39 | 2007-06-25 10:55:35 +0000 | [diff] [blame] | 594 | for (i = 0; i < ARRAY_SIZE(ext_dhcp_clients); i++) { |
Denis Vlasenko | 6c4eb44 | 2008-08-19 23:02:23 +0000 | [diff] [blame] | 595 | if (exists_execable(ext_dhcp_clients[i].name)) { |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 596 | result = execute(ext_dhcp_clients[i].stopcmd, ifd, exec); |
Denis Vlasenko | 6c4eb44 | 2008-08-19 23:02:23 +0000 | [diff] [blame] | 597 | if (result) |
| 598 | break; |
| 599 | } |
Denis Vlasenko | f6f43df | 2006-10-11 22:16:56 +0000 | [diff] [blame] | 600 | } |
Denis Vlasenko | 6c4eb44 | 2008-08-19 23:02:23 +0000 | [diff] [blame] | 601 | |
| 602 | if (!result) |
| 603 | bb_error_msg("warning: no dhcp clients found and stopped"); |
| 604 | |
| 605 | /* Sleep a bit, otherwise static_down tries to bring down interface too soon, |
| 606 | and it may come back up because udhcpc is still shutting down */ |
| 607 | usleep(100000); |
| 608 | result += static_down(ifd, exec); |
| 609 | return ((result == 3) ? 3 : 0); |
Denis Vlasenko | 85c2471 | 2008-03-17 09:04:04 +0000 | [diff] [blame] | 610 | } |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 611 | # elif ENABLE_UDHCPC |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 612 | static int FAST_FUNC dhcp_down(struct interface_defn_t *ifd, execfn *exec) |
Denis Vlasenko | 85c2471 | 2008-03-17 09:04:04 +0000 | [diff] [blame] | 613 | { |
Denis Vlasenko | 6c4eb44 | 2008-08-19 23:02:23 +0000 | [diff] [blame] | 614 | int result; |
Denys Vlasenko | 78abf88 | 2010-05-02 20:30:28 +0200 | [diff] [blame] | 615 | result = execute( |
| 616 | "test -f /var/run/udhcpc.%iface%.pid && " |
| 617 | "kill `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", |
| 618 | ifd, exec); |
Denis Vlasenko | 6c4eb44 | 2008-08-19 23:02:23 +0000 | [diff] [blame] | 619 | /* Also bring the hardware interface down since |
| 620 | killing the dhcp client alone doesn't do it. |
| 621 | This enables consecutive ifup->ifdown->ifup */ |
| 622 | /* Sleep a bit, otherwise static_down tries to bring down interface too soon, |
| 623 | and it may come back up because udhcpc is still shutting down */ |
| 624 | usleep(100000); |
| 625 | result += static_down(ifd, exec); |
| 626 | return ((result == 3) ? 3 : 0); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 627 | } |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 628 | # else |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 629 | static int FAST_FUNC dhcp_down(struct interface_defn_t *ifd UNUSED_PARAM, |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 630 | execfn *exec UNUSED_PARAM) |
Denis Vlasenko | 85c2471 | 2008-03-17 09:04:04 +0000 | [diff] [blame] | 631 | { |
| 632 | return 0; /* no dhcp support */ |
| 633 | } |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 634 | # endif |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 635 | |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 636 | static int FAST_FUNC manual_up_down(struct interface_defn_t *ifd UNUSED_PARAM, execfn *exec UNUSED_PARAM) |
Denis Vlasenko | 1c3577f | 2006-10-02 20:57:10 +0000 | [diff] [blame] | 637 | { |
| 638 | return 1; |
| 639 | } |
| 640 | |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 641 | static int FAST_FUNC bootp_up(struct interface_defn_t *ifd, execfn *exec) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 642 | { |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 643 | return execute("bootpc[[ --bootfile %bootfile%]] --dev %iface%" |
Denis Vlasenko | 1caca34 | 2007-08-02 10:14:29 +0000 | [diff] [blame] | 644 | "[[ --server %server%]][[ --hwaddr %hwaddr%]]" |
| 645 | " --returniffail --serverbcast", ifd, exec); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 646 | } |
| 647 | |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 648 | static int FAST_FUNC ppp_up(struct interface_defn_t *ifd, execfn *exec) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 649 | { |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 650 | return execute("pon[[ %provider%]]", ifd, exec); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 651 | } |
| 652 | |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 653 | static int FAST_FUNC ppp_down(struct interface_defn_t *ifd, execfn *exec) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 654 | { |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 655 | return execute("poff[[ %provider%]]", ifd, exec); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 656 | } |
| 657 | |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 658 | static int FAST_FUNC wvdial_up(struct interface_defn_t *ifd, execfn *exec) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 659 | { |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 660 | return execute("start-stop-daemon --start -x wvdial " |
| 661 | "-p /var/run/wvdial.%iface% -b -m --[[ %provider%]]", ifd, exec); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 662 | } |
| 663 | |
Denys Vlasenko | d5f1b1b | 2009-06-05 12:06:05 +0200 | [diff] [blame] | 664 | static int FAST_FUNC wvdial_down(struct interface_defn_t *ifd, execfn *exec) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 665 | { |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 666 | return execute("start-stop-daemon --stop -x wvdial " |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 667 | "-p /var/run/wvdial.%iface% -s 2", ifd, exec); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 670 | static const struct method_t methods[] = { |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 671 | { "manual" , manual_up_down, manual_up_down, }, |
| 672 | { "wvdial" , wvdial_up , wvdial_down , }, |
| 673 | { "ppp" , ppp_up , ppp_down , }, |
| 674 | { "static" , static_up , static_down , }, |
| 675 | { "bootp" , bootp_up , static_down , }, |
| 676 | { "dhcp" , dhcp_up , dhcp_down , }, |
| 677 | { "loopback", loopback_up , loopback_down , }, |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 678 | }; |
| 679 | |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 680 | static const struct address_family_t addr_inet = { |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 681 | "inet", |
Denis Vlasenko | 80b8b39 | 2007-06-25 10:55:35 +0000 | [diff] [blame] | 682 | ARRAY_SIZE(methods), |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 683 | methods |
| 684 | }; |
| 685 | |
Denys Vlasenko | 66cb7be | 2010-10-29 02:42:20 +0200 | [diff] [blame] | 686 | #endif /* FEATURE_IFUPDOWN_IPV4 */ |
| 687 | |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 688 | |
Denys Vlasenko | 2ace0ad | 2009-10-16 23:56:10 +0200 | [diff] [blame] | 689 | /* Returns pointer to the next word, or NULL. |
| 690 | * In 1st case, advances *buf to the word after this one. |
| 691 | */ |
Glenn L McGrath | 8573704 | 2003-01-14 23:26:57 +0000 | [diff] [blame] | 692 | static char *next_word(char **buf) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 693 | { |
Denis Vlasenko | cd5c61c | 2008-02-15 16:20:26 +0000 | [diff] [blame] | 694 | unsigned length; |
Glenn L McGrath | 8573704 | 2003-01-14 23:26:57 +0000 | [diff] [blame] | 695 | char *word; |
| 696 | |
Glenn L McGrath | 8573704 | 2003-01-14 23:26:57 +0000 | [diff] [blame] | 697 | /* Skip over leading whitespace */ |
Denis Vlasenko | d18a3a2 | 2006-10-25 12:46:03 +0000 | [diff] [blame] | 698 | word = skip_whitespace(*buf); |
Eric Andersen | 3c8bca3 | 2003-06-20 10:02:29 +0000 | [diff] [blame] | 699 | |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 700 | /* Stop on EOL */ |
| 701 | if (*word == '\0') |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 702 | return NULL; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 703 | |
Denis Vlasenko | cd5c61c | 2008-02-15 16:20:26 +0000 | [diff] [blame] | 704 | /* Find the length of this word (can't be 0) */ |
Glenn L McGrath | 8573704 | 2003-01-14 23:26:57 +0000 | [diff] [blame] | 705 | length = strcspn(word, " \t\n"); |
Denis Vlasenko | cd5c61c | 2008-02-15 16:20:26 +0000 | [diff] [blame] | 706 | |
| 707 | /* Unless we are already at NUL, store NUL and advance */ |
| 708 | if (word[length] != '\0') |
| 709 | word[length++] = '\0'; |
| 710 | |
Denys Vlasenko | 2ace0ad | 2009-10-16 23:56:10 +0200 | [diff] [blame] | 711 | *buf = skip_whitespace(word + length); |
Glenn L McGrath | 8573704 | 2003-01-14 23:26:57 +0000 | [diff] [blame] | 712 | |
| 713 | return word; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 714 | } |
| 715 | |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 716 | static const struct address_family_t *get_address_family(const struct address_family_t *const af[], char *name) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 717 | { |
| 718 | int i; |
| 719 | |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 720 | if (!name) |
| 721 | return NULL; |
| 722 | |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 723 | for (i = 0; af[i]; i++) { |
| 724 | if (strcmp(af[i]->name, name) == 0) { |
| 725 | return af[i]; |
| 726 | } |
| 727 | } |
| 728 | return NULL; |
| 729 | } |
| 730 | |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 731 | static const struct method_t *get_method(const struct address_family_t *af, char *name) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 732 | { |
| 733 | int i; |
| 734 | |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 735 | if (!name) |
| 736 | return NULL; |
Bernhard Reutner-Fischer | e747f62 | 2007-10-06 20:47:53 +0000 | [diff] [blame] | 737 | /* TODO: use index_in_str_array() */ |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 738 | for (i = 0; i < af->n_methods; i++) { |
| 739 | if (strcmp(af->method[i].name, name) == 0) { |
| 740 | return &af->method[i]; |
| 741 | } |
| 742 | } |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 743 | return NULL; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 744 | } |
| 745 | |
Glenn L McGrath | d4004ee | 2004-09-14 17:24:59 +0000 | [diff] [blame] | 746 | static struct interfaces_file_t *read_interfaces(const char *filename) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 747 | { |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 748 | /* Let's try to be compatible. |
| 749 | * |
| 750 | * "man 5 interfaces" says: |
| 751 | * Lines starting with "#" are ignored. Note that end-of-line |
| 752 | * comments are NOT supported, comments must be on a line of their own. |
| 753 | * A line may be extended across multiple lines by making |
| 754 | * the last character a backslash. |
| 755 | * |
| 756 | * Seen elsewhere in example config file: |
Denis Vlasenko | 4938292 | 2008-07-08 03:25:25 +0000 | [diff] [blame] | 757 | * A first non-blank "#" character makes the rest of the line |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 758 | * be ignored. Blank lines are ignored. Lines may be indented freely. |
| 759 | * A "\" character at the very end of the line indicates the next line |
| 760 | * should be treated as a continuation of the current one. |
| 761 | */ |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 762 | #if ENABLE_FEATURE_IFUPDOWN_MAPPING |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 763 | struct mapping_defn_t *currmap = NULL; |
Glenn L McGrath | cdbe5e5 | 2002-12-06 08:35:55 +0000 | [diff] [blame] | 764 | #endif |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 765 | struct interface_defn_t *currif = NULL; |
| 766 | struct interfaces_file_t *defn; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 767 | FILE *f; |
Glenn L McGrath | 8573704 | 2003-01-14 23:26:57 +0000 | [diff] [blame] | 768 | char *buf; |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 769 | char *first_word; |
| 770 | char *rest_of_line; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 771 | enum { NONE, IFACE, MAPPING } currently_processing = NONE; |
| 772 | |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 773 | defn = xzalloc(sizeof(*defn)); |
Denis Vlasenko | 5415c85 | 2008-07-21 23:05:26 +0000 | [diff] [blame] | 774 | f = xfopen_for_read(filename); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 775 | |
Denis Vlasenko | 8ee649a | 2008-03-26 20:04:27 +0000 | [diff] [blame] | 776 | while ((buf = xmalloc_fgetline(f)) != NULL) { |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 777 | #if ENABLE_DESKTOP |
| 778 | /* Trailing "\" concatenates lines */ |
| 779 | char *p; |
| 780 | while ((p = last_char_is(buf, '\\')) != NULL) { |
| 781 | *p = '\0'; |
Denis Vlasenko | 8ee649a | 2008-03-26 20:04:27 +0000 | [diff] [blame] | 782 | rest_of_line = xmalloc_fgetline(f); |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 783 | if (!rest_of_line) |
| 784 | break; |
| 785 | p = xasprintf("%s%s", buf, rest_of_line); |
Eric Andersen | 3c8bca3 | 2003-06-20 10:02:29 +0000 | [diff] [blame] | 786 | free(buf); |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 787 | free(rest_of_line); |
| 788 | buf = p; |
| 789 | } |
| 790 | #endif |
| 791 | rest_of_line = buf; |
| 792 | first_word = next_word(&rest_of_line); |
Denis Vlasenko | 4938292 | 2008-07-08 03:25:25 +0000 | [diff] [blame] | 793 | if (!first_word || *first_word == '#') { |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 794 | free(buf); |
| 795 | continue; /* blank/comment line */ |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 796 | } |
| 797 | |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 798 | if (strcmp(first_word, "mapping") == 0) { |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 799 | #if ENABLE_FEATURE_IFUPDOWN_MAPPING |
Denis Vlasenko | cd5c61c | 2008-02-15 16:20:26 +0000 | [diff] [blame] | 800 | currmap = xzalloc(sizeof(*currmap)); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 801 | |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 802 | while ((first_word = next_word(&rest_of_line)) != NULL) { |
Denis Vlasenko | deeed59 | 2008-07-08 05:14:36 +0000 | [diff] [blame] | 803 | currmap->match = xrealloc_vector(currmap->match, 4, currmap->n_matches); |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 804 | currmap->match[currmap->n_matches++] = xstrdup(first_word); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 805 | } |
Denis Vlasenko | cd5c61c | 2008-02-15 16:20:26 +0000 | [diff] [blame] | 806 | /*currmap->n_mappings = 0;*/ |
| 807 | /*currmap->mapping = NULL;*/ |
| 808 | /*currmap->script = NULL;*/ |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 809 | { |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 810 | struct mapping_defn_t **where = &defn->mappings; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 811 | while (*where != NULL) { |
| 812 | where = &(*where)->next; |
| 813 | } |
| 814 | *where = currmap; |
Denis Vlasenko | cd5c61c | 2008-02-15 16:20:26 +0000 | [diff] [blame] | 815 | /*currmap->next = NULL;*/ |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 816 | } |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 817 | debug_noise("Added mapping\n"); |
Glenn L McGrath | cdbe5e5 | 2002-12-06 08:35:55 +0000 | [diff] [blame] | 818 | #endif |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 819 | currently_processing = MAPPING; |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 820 | } else if (strcmp(first_word, "iface") == 0) { |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 821 | static const struct address_family_t *const addr_fams[] = { |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 822 | #if ENABLE_FEATURE_IFUPDOWN_IPV4 |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 823 | &addr_inet, |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 824 | #endif |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 825 | #if ENABLE_FEATURE_IFUPDOWN_IPV6 |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 826 | &addr_inet6, |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 827 | #endif |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 828 | NULL |
| 829 | }; |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 830 | char *iface_name; |
| 831 | char *address_family_name; |
| 832 | char *method_name; |
| 833 | llist_t *iface_list; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 834 | |
Denis Vlasenko | cd5c61c | 2008-02-15 16:20:26 +0000 | [diff] [blame] | 835 | currif = xzalloc(sizeof(*currif)); |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 836 | iface_name = next_word(&rest_of_line); |
| 837 | address_family_name = next_word(&rest_of_line); |
| 838 | method_name = next_word(&rest_of_line); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 839 | |
Denis Vlasenko | cd5c61c | 2008-02-15 16:20:26 +0000 | [diff] [blame] | 840 | if (method_name == NULL) |
| 841 | bb_error_msg_and_die("too few parameters for line \"%s\"", buf); |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 842 | |
| 843 | /* ship any trailing whitespace */ |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 844 | rest_of_line = skip_whitespace(rest_of_line); |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 845 | |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 846 | if (rest_of_line[0] != '\0' /* && rest_of_line[0] != '#' */) |
Denis Vlasenko | cd5c61c | 2008-02-15 16:20:26 +0000 | [diff] [blame] | 847 | bb_error_msg_and_die("too many parameters \"%s\"", buf); |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 848 | |
| 849 | currif->iface = xstrdup(iface_name); |
| 850 | |
| 851 | currif->address_family = get_address_family(addr_fams, address_family_name); |
Denis Vlasenko | cd5c61c | 2008-02-15 16:20:26 +0000 | [diff] [blame] | 852 | if (!currif->address_family) |
| 853 | bb_error_msg_and_die("unknown address type \"%s\"", address_family_name); |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 854 | |
| 855 | currif->method = get_method(currif->address_family, method_name); |
Denis Vlasenko | cd5c61c | 2008-02-15 16:20:26 +0000 | [diff] [blame] | 856 | if (!currif->method) |
| 857 | bb_error_msg_and_die("unknown method \"%s\"", method_name); |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 858 | |
| 859 | for (iface_list = defn->ifaces; iface_list; iface_list = iface_list->link) { |
| 860 | struct interface_defn_t *tmp = (struct interface_defn_t *) iface_list->data; |
Denis Vlasenko | cd5c61c | 2008-02-15 16:20:26 +0000 | [diff] [blame] | 861 | if ((strcmp(tmp->iface, currif->iface) == 0) |
| 862 | && (tmp->address_family == currif->address_family) |
| 863 | ) { |
| 864 | bb_error_msg_and_die("duplicate interface \"%s\"", tmp->iface); |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 865 | } |
| 866 | } |
| 867 | llist_add_to_end(&(defn->ifaces), (char*)currif); |
| 868 | |
| 869 | debug_noise("iface %s %s %s\n", currif->iface, address_family_name, method_name); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 870 | currently_processing = IFACE; |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 871 | } else if (strcmp(first_word, "auto") == 0) { |
| 872 | while ((first_word = next_word(&rest_of_line)) != NULL) { |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 873 | |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 874 | /* Check the interface isnt already listed */ |
Denis Vlasenko | 0b791d9 | 2009-04-13 20:52:00 +0000 | [diff] [blame] | 875 | if (llist_find_str(defn->autointerfaces, first_word)) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 876 | bb_perror_msg_and_die("interface declared auto twice \"%s\"", buf); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 877 | } |
| 878 | |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 879 | /* Add the interface to the list */ |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 880 | llist_add_to_end(&(defn->autointerfaces), xstrdup(first_word)); |
| 881 | debug_noise("\nauto %s\n", first_word); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 882 | } |
| 883 | currently_processing = NONE; |
| 884 | } else { |
| 885 | switch (currently_processing) { |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 886 | case IFACE: |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 887 | if (rest_of_line[0] == '\0') |
Denis Vlasenko | cd5c61c | 2008-02-15 16:20:26 +0000 | [diff] [blame] | 888 | bb_error_msg_and_die("option with empty value \"%s\"", buf); |
| 889 | |
Andreas Oberritter | 3a9365e | 2012-04-23 22:08:39 +0200 | [diff] [blame] | 890 | if (strcmp(first_word, "post-up") == 0) |
| 891 | first_word += 5; /* "up" */ |
| 892 | else if (strcmp(first_word, "pre-down") == 0) |
| 893 | first_word += 4; /* "down" */ |
| 894 | |
Denys Vlasenko | 9c28fb8 | 2011-10-19 02:37:08 +0200 | [diff] [blame] | 895 | /* If not one of "up", "down",... words... */ |
| 896 | if (index_in_strings(keywords_up_down, first_word) < 0) { |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 897 | int i; |
Denis Vlasenko | cd5c61c | 2008-02-15 16:20:26 +0000 | [diff] [blame] | 898 | for (i = 0; i < currif->n_options; i++) { |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 899 | if (strcmp(currif->option[i].name, first_word) == 0) |
Denis Vlasenko | cd5c61c | 2008-02-15 16:20:26 +0000 | [diff] [blame] | 900 | bb_error_msg_and_die("duplicate option \"%s\"", buf); |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 901 | } |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 902 | } |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 903 | debug_noise("\t%s=%s\n", first_word, rest_of_line); |
Denys Vlasenko | 9c28fb8 | 2011-10-19 02:37:08 +0200 | [diff] [blame] | 904 | currif->option = xrealloc_vector(currif->option, 4, currif->n_options); |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 905 | currif->option[currif->n_options].name = xstrdup(first_word); |
| 906 | currif->option[currif->n_options].value = xstrdup(rest_of_line); |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 907 | currif->n_options++; |
| 908 | break; |
| 909 | case MAPPING: |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 910 | #if ENABLE_FEATURE_IFUPDOWN_MAPPING |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 911 | if (strcmp(first_word, "script") == 0) { |
Denis Vlasenko | cd5c61c | 2008-02-15 16:20:26 +0000 | [diff] [blame] | 912 | if (currmap->script != NULL) |
| 913 | bb_error_msg_and_die("duplicate script in mapping \"%s\"", buf); |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 914 | currmap->script = xstrdup(next_word(&rest_of_line)); |
| 915 | } else if (strcmp(first_word, "map") == 0) { |
Denys Vlasenko | 9c28fb8 | 2011-10-19 02:37:08 +0200 | [diff] [blame] | 916 | currmap->mapping = xrealloc_vector(currmap->mapping, 2, currmap->n_mappings); |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 917 | currmap->mapping[currmap->n_mappings] = xstrdup(next_word(&rest_of_line)); |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 918 | currmap->n_mappings++; |
| 919 | } else { |
Denis Vlasenko | cd5c61c | 2008-02-15 16:20:26 +0000 | [diff] [blame] | 920 | bb_error_msg_and_die("misplaced option \"%s\"", buf); |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 921 | } |
| 922 | #endif |
| 923 | break; |
| 924 | case NONE: |
| 925 | default: |
Denis Vlasenko | cd5c61c | 2008-02-15 16:20:26 +0000 | [diff] [blame] | 926 | bb_error_msg_and_die("misplaced option \"%s\"", buf); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 927 | } |
| 928 | } |
Glenn L McGrath | 8573704 | 2003-01-14 23:26:57 +0000 | [diff] [blame] | 929 | free(buf); |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 930 | } /* while (fgets) */ |
| 931 | |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 932 | if (ferror(f) != 0) { |
Denis Vlasenko | a483691 | 2007-07-03 08:26:24 +0000 | [diff] [blame] | 933 | /* ferror does NOT set errno! */ |
| 934 | bb_error_msg_and_die("%s: I/O error", filename); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 935 | } |
| 936 | fclose(f); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 937 | |
| 938 | return defn; |
| 939 | } |
| 940 | |
Denis Vlasenko | ab2aea4 | 2007-01-29 22:51:58 +0000 | [diff] [blame] | 941 | static char *setlocalenv(const char *format, const char *name, const char *value) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 942 | { |
| 943 | char *result; |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 944 | char *dst; |
| 945 | char *src; |
| 946 | char c; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 947 | |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 948 | result = xasprintf(format, name, value); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 949 | |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 950 | for (dst = src = result; (c = *src) != '=' && c; src++) { |
| 951 | if (c == '-') |
| 952 | c = '_'; |
| 953 | if (c >= 'a' && c <= 'z') |
| 954 | c -= ('a' - 'A'); |
| 955 | if (isalnum(c) || c == '_') |
| 956 | *dst++ = c; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 957 | } |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 958 | overlapping_strcpy(dst, src); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 959 | |
| 960 | return result; |
| 961 | } |
| 962 | |
Andreas Oberritter | 3a9365e | 2012-04-23 22:08:39 +0200 | [diff] [blame] | 963 | static void set_environ(struct interface_defn_t *iface, const char *mode, const char *opt) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 964 | { |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 965 | int i; |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 966 | char **pp; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 967 | |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 968 | if (G.my_environ != NULL) { |
| 969 | for (pp = G.my_environ; *pp; pp++) { |
| 970 | free(*pp); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 971 | } |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 972 | free(G.my_environ); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 973 | } |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 974 | |
| 975 | /* note: last element will stay NULL: */ |
Andreas Oberritter | 3a9365e | 2012-04-23 22:08:39 +0200 | [diff] [blame] | 976 | G.my_environ = xzalloc(sizeof(char *) * (iface->n_options + 7)); |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 977 | pp = G.my_environ; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 978 | |
| 979 | for (i = 0; i < iface->n_options; i++) { |
Denys Vlasenko | 9c28fb8 | 2011-10-19 02:37:08 +0200 | [diff] [blame] | 980 | if (index_in_strings(keywords_up_down, iface->option[i].name) >= 0) { |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 981 | continue; |
| 982 | } |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 983 | *pp++ = setlocalenv("IF_%s=%s", iface->option[i].name, iface->option[i].value); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 984 | } |
| 985 | |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 986 | *pp++ = setlocalenv("%s=%s", "IFACE", iface->iface); |
| 987 | *pp++ = setlocalenv("%s=%s", "ADDRFAM", iface->address_family->name); |
| 988 | *pp++ = setlocalenv("%s=%s", "METHOD", iface->method->name); |
| 989 | *pp++ = setlocalenv("%s=%s", "MODE", mode); |
Andreas Oberritter | 3a9365e | 2012-04-23 22:08:39 +0200 | [diff] [blame] | 990 | *pp++ = setlocalenv("%s=%s", "PHASE", opt); |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 991 | if (G.startup_PATH) |
| 992 | *pp++ = setlocalenv("%s=%s", "PATH", G.startup_PATH); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | static int doit(char *str) |
| 996 | { |
Denis Vlasenko | c12f530 | 2006-10-06 09:49:47 +0000 | [diff] [blame] | 997 | if (option_mask32 & (OPT_no_act|OPT_verbose)) { |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 998 | puts(str); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 999 | } |
Denis Vlasenko | c12f530 | 2006-10-06 09:49:47 +0000 | [diff] [blame] | 1000 | if (!(option_mask32 & OPT_no_act)) { |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1001 | pid_t child; |
| 1002 | int status; |
| 1003 | |
Denys Vlasenko | 8131eea | 2009-11-02 14:19:51 +0100 | [diff] [blame] | 1004 | fflush_all(); |
Denis Vlasenko | 0764a7f | 2008-03-19 16:24:17 +0000 | [diff] [blame] | 1005 | child = vfork(); |
Denys Vlasenko | 681efe2 | 2011-03-08 21:00:36 +0100 | [diff] [blame] | 1006 | if (child < 0) /* failure */ |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 1007 | return 0; |
Denys Vlasenko | 681efe2 | 2011-03-08 21:00:36 +0100 | [diff] [blame] | 1008 | if (child == 0) { /* child */ |
| 1009 | execle(G.shell, G.shell, "-c", str, (char *) NULL, G.my_environ); |
Denis Vlasenko | 0764a7f | 2008-03-19 16:24:17 +0000 | [diff] [blame] | 1010 | _exit(127); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1011 | } |
Denis Vlasenko | fb0eba7 | 2008-01-02 19:55:04 +0000 | [diff] [blame] | 1012 | safe_waitpid(child, &status, 0); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1013 | if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { |
| 1014 | return 0; |
| 1015 | } |
| 1016 | } |
Denis Vlasenko | 7f1f5b0 | 2006-09-23 12:49:01 +0000 | [diff] [blame] | 1017 | return 1; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
Rob Landley | e813ddb | 2006-02-28 03:53:14 +0000 | [diff] [blame] | 1020 | static int execute_all(struct interface_defn_t *ifd, const char *opt) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1021 | { |
| 1022 | int i; |
Eric Andersen | eb213bd | 2003-09-12 08:39:05 +0000 | [diff] [blame] | 1023 | char *buf; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1024 | for (i = 0; i < ifd->n_options; i++) { |
| 1025 | if (strcmp(ifd->option[i].name, opt) == 0) { |
Rob Landley | e813ddb | 2006-02-28 03:53:14 +0000 | [diff] [blame] | 1026 | if (!doit(ifd->option[i].value)) { |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1027 | return 0; |
| 1028 | } |
| 1029 | } |
| 1030 | } |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 1031 | |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 1032 | buf = xasprintf("run-parts /etc/network/if-%s.d", opt); |
Denis Vlasenko | 2375d75 | 2006-12-19 23:15:46 +0000 | [diff] [blame] | 1033 | /* heh, we don't bother free'ing it */ |
| 1034 | return doit(buf); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 1037 | static int check(char *str) |
| 1038 | { |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 1039 | return str != NULL; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 1042 | static int iface_up(struct interface_defn_t *iface) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1043 | { |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 1044 | if (!iface->method->up(iface, check)) return -1; |
Andreas Oberritter | 3a9365e | 2012-04-23 22:08:39 +0200 | [diff] [blame] | 1045 | set_environ(iface, "start", "pre-up"); |
Rob Landley | e813ddb | 2006-02-28 03:53:14 +0000 | [diff] [blame] | 1046 | if (!execute_all(iface, "pre-up")) return 0; |
Eric Andersen | 658f8b1 | 2003-12-19 10:46:00 +0000 | [diff] [blame] | 1047 | if (!iface->method->up(iface, doit)) return 0; |
Andreas Oberritter | 3a9365e | 2012-04-23 22:08:39 +0200 | [diff] [blame] | 1048 | set_environ(iface, "start", "post-up"); |
Rob Landley | e813ddb | 2006-02-28 03:53:14 +0000 | [diff] [blame] | 1049 | if (!execute_all(iface, "up")) return 0; |
Eric Andersen | 658f8b1 | 2003-12-19 10:46:00 +0000 | [diff] [blame] | 1050 | return 1; |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | static int iface_down(struct interface_defn_t *iface) |
| 1054 | { |
Denys Vlasenko | a0fd4a7 | 2012-09-02 14:29:14 +0200 | [diff] [blame] | 1055 | if (!iface->method->down(iface, check)) return -1; |
Andreas Oberritter | 3a9365e | 2012-04-23 22:08:39 +0200 | [diff] [blame] | 1056 | set_environ(iface, "stop", "pre-down"); |
Rob Landley | e813ddb | 2006-02-28 03:53:14 +0000 | [diff] [blame] | 1057 | if (!execute_all(iface, "down")) return 0; |
Eric Andersen | 658f8b1 | 2003-12-19 10:46:00 +0000 | [diff] [blame] | 1058 | if (!iface->method->down(iface, doit)) return 0; |
Andreas Oberritter | 3a9365e | 2012-04-23 22:08:39 +0200 | [diff] [blame] | 1059 | set_environ(iface, "stop", "post-down"); |
Rob Landley | e813ddb | 2006-02-28 03:53:14 +0000 | [diff] [blame] | 1060 | if (!execute_all(iface, "post-down")) return 0; |
Eric Andersen | 658f8b1 | 2003-12-19 10:46:00 +0000 | [diff] [blame] | 1061 | return 1; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 1064 | #if ENABLE_FEATURE_IFUPDOWN_MAPPING |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 1065 | static int popen2(FILE **in, FILE **out, char *command, char *param) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1066 | { |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 1067 | char *argv[3] = { command, param, NULL }; |
Denis Vlasenko | 3718832 | 2008-02-16 13:20:56 +0000 | [diff] [blame] | 1068 | struct fd_pair infd, outfd; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1069 | pid_t pid; |
| 1070 | |
Denis Vlasenko | 3718832 | 2008-02-16 13:20:56 +0000 | [diff] [blame] | 1071 | xpiped_pair(infd); |
| 1072 | xpiped_pair(outfd); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1073 | |
Denys Vlasenko | 8131eea | 2009-11-02 14:19:51 +0100 | [diff] [blame] | 1074 | fflush_all(); |
Pascal Bellard | 926031b | 2010-07-04 15:32:38 +0200 | [diff] [blame] | 1075 | pid = xvfork(); |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 1076 | |
Pascal Bellard | 926031b | 2010-07-04 15:32:38 +0200 | [diff] [blame] | 1077 | if (pid == 0) { |
| 1078 | /* Child */ |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 1079 | /* NB: close _first_, then move fds! */ |
Denis Vlasenko | 3718832 | 2008-02-16 13:20:56 +0000 | [diff] [blame] | 1080 | close(infd.wr); |
| 1081 | close(outfd.rd); |
| 1082 | xmove_fd(infd.rd, 0); |
| 1083 | xmove_fd(outfd.wr, 1); |
Pascal Bellard | 21e8e8d | 2010-07-04 00:57:03 +0200 | [diff] [blame] | 1084 | BB_EXECVP_or_die(argv); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1085 | } |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 1086 | /* parent */ |
Denis Vlasenko | 3718832 | 2008-02-16 13:20:56 +0000 | [diff] [blame] | 1087 | close(infd.rd); |
| 1088 | close(outfd.wr); |
Denys Vlasenko | a7ccdee | 2009-11-15 23:28:11 +0100 | [diff] [blame] | 1089 | *in = xfdopen_for_write(infd.wr); |
| 1090 | *out = xfdopen_for_read(outfd.rd); |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 1091 | return pid; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 1094 | static char *run_mapping(char *physical, struct mapping_defn_t *map) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1095 | { |
| 1096 | FILE *in, *out; |
| 1097 | int i, status; |
| 1098 | pid_t pid; |
| 1099 | |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 1100 | char *logical = xstrdup(physical); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1101 | |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 1102 | /* Run the mapping script. Never fails. */ |
| 1103 | pid = popen2(&in, &out, map->script, physical); |
Eric Andersen | 8a93179 | 2003-07-03 10:20:29 +0000 | [diff] [blame] | 1104 | |
| 1105 | /* Write mappings to stdin of mapping script. */ |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1106 | for (i = 0; i < map->n_mappings; i++) { |
| 1107 | fprintf(in, "%s\n", map->mapping[i]); |
| 1108 | } |
| 1109 | fclose(in); |
Denis Vlasenko | fb0eba7 | 2008-01-02 19:55:04 +0000 | [diff] [blame] | 1110 | safe_waitpid(pid, &status, 0); |
Eric Andersen | 8a93179 | 2003-07-03 10:20:29 +0000 | [diff] [blame] | 1111 | |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1112 | if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { |
Eric Andersen | 8a93179 | 2003-07-03 10:20:29 +0000 | [diff] [blame] | 1113 | /* If the mapping script exited successfully, try to |
| 1114 | * grab a line of output and use that as the name of the |
| 1115 | * logical interface. */ |
Denis Vlasenko | 8ee649a | 2008-03-26 20:04:27 +0000 | [diff] [blame] | 1116 | char *new_logical = xmalloc_fgetline(out); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1117 | |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 1118 | if (new_logical) { |
Eric Andersen | 8a93179 | 2003-07-03 10:20:29 +0000 | [diff] [blame] | 1119 | /* If we are able to read a line of output from the script, |
| 1120 | * remove any trailing whitespace and use this value |
| 1121 | * as the name of the logical interface. */ |
Rob Landley | a389651 | 2006-05-07 20:20:34 +0000 | [diff] [blame] | 1122 | char *pch = new_logical + strlen(new_logical) - 1; |
Eric Andersen | 233b170 | 2003-06-05 19:37:01 +0000 | [diff] [blame] | 1123 | |
| 1124 | while (pch >= new_logical && isspace(*pch)) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1125 | *(pch--) = '\0'; |
Eric Andersen | 8a93179 | 2003-07-03 10:20:29 +0000 | [diff] [blame] | 1126 | |
| 1127 | free(logical); |
| 1128 | logical = new_logical; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1129 | } |
| 1130 | } |
Eric Andersen | 8a93179 | 2003-07-03 10:20:29 +0000 | [diff] [blame] | 1131 | |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1132 | fclose(out); |
| 1133 | |
Eric Andersen | 8a93179 | 2003-07-03 10:20:29 +0000 | [diff] [blame] | 1134 | return logical; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1135 | } |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 1136 | #endif /* FEATURE_IFUPDOWN_MAPPING */ |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1137 | |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 1138 | static llist_t *find_iface_state(llist_t *state_list, const char *iface) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1139 | { |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 1140 | unsigned iface_len = strlen(iface); |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 1141 | llist_t *search = state_list; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1142 | |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 1143 | while (search) { |
Denis Vlasenko | eda43d7 | 2007-05-02 22:04:38 +0000 | [diff] [blame] | 1144 | if ((strncmp(search->data, iface, iface_len) == 0) |
Denis Vlasenko | 1e18f1b | 2008-02-16 13:19:19 +0000 | [diff] [blame] | 1145 | && (search->data[iface_len] == '=') |
| 1146 | ) { |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 1147 | return search; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1148 | } |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 1149 | search = search->link; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1150 | } |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 1151 | return NULL; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
Denis Vlasenko | bd100b7 | 2007-05-02 21:38:44 +0000 | [diff] [blame] | 1154 | /* read the previous state from the state file */ |
| 1155 | static llist_t *read_iface_state(void) |
| 1156 | { |
| 1157 | llist_t *state_list = NULL; |
Denis Vlasenko | 5415c85 | 2008-07-21 23:05:26 +0000 | [diff] [blame] | 1158 | FILE *state_fp = fopen_for_read(CONFIG_IFUPDOWN_IFSTATE_PATH); |
Denis Vlasenko | bd100b7 | 2007-05-02 21:38:44 +0000 | [diff] [blame] | 1159 | |
| 1160 | if (state_fp) { |
| 1161 | char *start, *end_ptr; |
| 1162 | while ((start = xmalloc_fgets(state_fp)) != NULL) { |
| 1163 | /* We should only need to check for a single character */ |
| 1164 | end_ptr = start + strcspn(start, " \t\n"); |
| 1165 | *end_ptr = '\0'; |
| 1166 | llist_add_to(&state_list, start); |
| 1167 | } |
| 1168 | fclose(state_fp); |
| 1169 | } |
| 1170 | return state_list; |
| 1171 | } |
| 1172 | |
| 1173 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 1174 | int ifupdown_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denys Vlasenko | 2ec91ae | 2010-01-04 14:15:38 +0100 | [diff] [blame] | 1175 | int ifupdown_main(int argc UNUSED_PARAM, char **argv) |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1176 | { |
Denis Vlasenko | cd5c61c | 2008-02-15 16:20:26 +0000 | [diff] [blame] | 1177 | int (*cmds)(struct interface_defn_t *); |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 1178 | struct interfaces_file_t *defn; |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 1179 | llist_t *target_list = NULL; |
Glenn L McGrath | d4004ee | 2004-09-14 17:24:59 +0000 | [diff] [blame] | 1180 | const char *interfaces = "/etc/network/interfaces"; |
Bernhard Reutner-Fischer | 16deb86 | 2007-03-19 19:54:56 +0000 | [diff] [blame] | 1181 | bool any_failures = 0; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1182 | |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 1183 | INIT_G(); |
| 1184 | |
| 1185 | G.startup_PATH = getenv("PATH"); |
Denys Vlasenko | 681efe2 | 2011-03-08 21:00:36 +0100 | [diff] [blame] | 1186 | G.shell = xstrdup(get_shell_name()); |
Denys Vlasenko | 62152da | 2009-06-05 21:53:11 +0200 | [diff] [blame] | 1187 | |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 1188 | cmds = iface_down; |
Denis Vlasenko | 8f8f268 | 2006-10-03 21:00:43 +0000 | [diff] [blame] | 1189 | if (applet_name[2] == 'u') { |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1190 | /* ifup command */ |
| 1191 | cmds = iface_up; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1192 | } |
| 1193 | |
Denis Vlasenko | fe7cd64 | 2007-08-18 15:32:12 +0000 | [diff] [blame] | 1194 | getopt32(argv, OPTION_STR, &interfaces); |
Denys Vlasenko | 2ec91ae | 2010-01-04 14:15:38 +0100 | [diff] [blame] | 1195 | argv += optind; |
| 1196 | if (argv[0]) { |
Denis Vlasenko | 7f1f5b0 | 2006-09-23 12:49:01 +0000 | [diff] [blame] | 1197 | if (DO_ALL) bb_show_usage(); |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 1198 | } else { |
Denis Vlasenko | 7f1f5b0 | 2006-09-23 12:49:01 +0000 | [diff] [blame] | 1199 | if (!DO_ALL) bb_show_usage(); |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 1200 | } |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1201 | |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 1202 | debug_noise("reading %s file:\n", interfaces); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1203 | defn = read_interfaces(interfaces); |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 1204 | debug_noise("\ndone reading %s\n\n", interfaces); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1205 | |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 1206 | /* Create a list of interfaces to work on */ |
Denis Vlasenko | 7f1f5b0 | 2006-09-23 12:49:01 +0000 | [diff] [blame] | 1207 | if (DO_ALL) { |
Denis Vlasenko | bd100b7 | 2007-05-02 21:38:44 +0000 | [diff] [blame] | 1208 | target_list = defn->autointerfaces; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1209 | } else { |
Denys Vlasenko | 2ec91ae | 2010-01-04 14:15:38 +0100 | [diff] [blame] | 1210 | llist_add_to_end(&target_list, argv[0]); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 1213 | /* Update the interfaces */ |
| 1214 | while (target_list) { |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 1215 | llist_t *iface_list; |
| 1216 | struct interface_defn_t *currif; |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 1217 | char *iface; |
| 1218 | char *liface; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1219 | char *pch; |
Bernhard Reutner-Fischer | 16deb86 | 2007-03-19 19:54:56 +0000 | [diff] [blame] | 1220 | bool okay = 0; |
Denis Vlasenko | 6b06cb8 | 2008-05-15 21:30:45 +0000 | [diff] [blame] | 1221 | int cmds_ret; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1222 | |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 1223 | iface = xstrdup(target_list->data); |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 1224 | target_list = target_list->link; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1225 | |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 1226 | pch = strchr(iface, '='); |
| 1227 | if (pch) { |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1228 | *pch = '\0'; |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 1229 | liface = xstrdup(pch + 1); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1230 | } else { |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 1231 | liface = xstrdup(iface); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1232 | } |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 1233 | |
Denis Vlasenko | 7f1f5b0 | 2006-09-23 12:49:01 +0000 | [diff] [blame] | 1234 | if (!FORCE) { |
Denis Vlasenko | bd100b7 | 2007-05-02 21:38:44 +0000 | [diff] [blame] | 1235 | llist_t *state_list = read_iface_state(); |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 1236 | const llist_t *iface_state = find_iface_state(state_list, iface); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1237 | |
| 1238 | if (cmds == iface_up) { |
| 1239 | /* ifup */ |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 1240 | if (iface_state) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1241 | bb_error_msg("interface %s already configured", iface); |
Alexey Fomenko | 1df0af7 | 2011-03-02 04:13:21 +0100 | [diff] [blame] | 1242 | goto next; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1243 | } |
| 1244 | } else { |
| 1245 | /* ifdown */ |
Denis Vlasenko | c115fdb | 2007-03-06 22:53:10 +0000 | [diff] [blame] | 1246 | if (!iface_state) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1247 | bb_error_msg("interface %s not configured", iface); |
Alexey Fomenko | 1df0af7 | 2011-03-02 04:13:21 +0100 | [diff] [blame] | 1248 | goto next; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1249 | } |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1250 | } |
Denis Vlasenko | bd100b7 | 2007-05-02 21:38:44 +0000 | [diff] [blame] | 1251 | llist_free(state_list, free); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1252 | } |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 1253 | |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 1254 | #if ENABLE_FEATURE_IFUPDOWN_MAPPING |
Denis Vlasenko | 7f1f5b0 | 2006-09-23 12:49:01 +0000 | [diff] [blame] | 1255 | if ((cmds == iface_up) && !NO_MAPPINGS) { |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 1256 | struct mapping_defn_t *currmap; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1257 | |
| 1258 | for (currmap = defn->mappings; currmap; currmap = currmap->next) { |
Denis Vlasenko | 4e33e07 | 2006-10-16 18:24:57 +0000 | [diff] [blame] | 1259 | int i; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1260 | for (i = 0; i < currmap->n_matches; i++) { |
| 1261 | if (fnmatch(currmap->match[i], liface, 0) != 0) |
| 1262 | continue; |
Denis Vlasenko | 7f1f5b0 | 2006-09-23 12:49:01 +0000 | [diff] [blame] | 1263 | if (VERBOSE) { |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 1264 | printf("Running mapping script %s on %s\n", currmap->script, liface); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1265 | } |
Eric Andersen | 8a93179 | 2003-07-03 10:20:29 +0000 | [diff] [blame] | 1266 | liface = run_mapping(iface, currmap); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1267 | break; |
| 1268 | } |
| 1269 | } |
| 1270 | } |
Glenn L McGrath | cdbe5e5 | 2002-12-06 08:35:55 +0000 | [diff] [blame] | 1271 | #endif |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1272 | |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 1273 | iface_list = defn->ifaces; |
| 1274 | while (iface_list) { |
| 1275 | currif = (struct interface_defn_t *) iface_list->data; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1276 | if (strcmp(liface, currif->iface) == 0) { |
| 1277 | char *oldiface = currif->iface; |
| 1278 | |
| 1279 | okay = 1; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1280 | currif->iface = iface; |
| 1281 | |
Denis Vlasenko | 8cd1a28 | 2006-12-19 23:01:33 +0000 | [diff] [blame] | 1282 | debug_noise("\nConfiguring interface %s (%s)\n", liface, currif->address_family->name); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1283 | |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 1284 | /* Call the cmds function pointer, does either iface_up() or iface_down() */ |
Glenn L McGrath | 0177ce1 | 2004-07-21 23:56:31 +0000 | [diff] [blame] | 1285 | cmds_ret = cmds(currif); |
| 1286 | if (cmds_ret == -1) { |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 1287 | bb_error_msg("don't seem to have all the variables for %s/%s", |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 1288 | liface, currif->address_family->name); |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 1289 | any_failures = 1; |
Glenn L McGrath | 0177ce1 | 2004-07-21 23:56:31 +0000 | [diff] [blame] | 1290 | } else if (cmds_ret == 0) { |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 1291 | any_failures = 1; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1292 | } |
Glenn L McGrath | cdbe5e5 | 2002-12-06 08:35:55 +0000 | [diff] [blame] | 1293 | |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1294 | currif->iface = oldiface; |
| 1295 | } |
Eric Andersen | 8320b42 | 2003-04-02 10:13:26 +0000 | [diff] [blame] | 1296 | iface_list = iface_list->link; |
| 1297 | } |
Denis Vlasenko | 7f1f5b0 | 2006-09-23 12:49:01 +0000 | [diff] [blame] | 1298 | if (VERBOSE) { |
Denis Vlasenko | 4daad90 | 2007-09-27 10:20:47 +0000 | [diff] [blame] | 1299 | bb_putchar('\n'); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1300 | } |
| 1301 | |
Denis Vlasenko | 7f1f5b0 | 2006-09-23 12:49:01 +0000 | [diff] [blame] | 1302 | if (!okay && !FORCE) { |
Denis Vlasenko | 0534125 | 2006-09-26 20:35:30 +0000 | [diff] [blame] | 1303 | bb_error_msg("ignoring unknown interface %s", liface); |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 1304 | any_failures = 1; |
Denis Vlasenko | f92df58 | 2007-05-02 22:22:23 +0000 | [diff] [blame] | 1305 | } else if (!NO_ACT) { |
Denis Vlasenko | bd100b7 | 2007-05-02 21:38:44 +0000 | [diff] [blame] | 1306 | /* update the state file */ |
Denis Vlasenko | f92df58 | 2007-05-02 22:22:23 +0000 | [diff] [blame] | 1307 | FILE *state_fp; |
| 1308 | llist_t *state; |
Denis Vlasenko | bd100b7 | 2007-05-02 21:38:44 +0000 | [diff] [blame] | 1309 | llist_t *state_list = read_iface_state(); |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 1310 | llist_t *iface_state = find_iface_state(state_list, iface); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1311 | |
Lauri Hintsala | 454fe29 | 2011-12-14 16:49:58 +0200 | [diff] [blame] | 1312 | if (cmds == iface_up && !any_failures) { |
Denys Vlasenko | d6f5000 | 2011-12-15 12:39:25 +0100 | [diff] [blame] | 1313 | char *newiface = xasprintf("%s=%s", iface, liface); |
| 1314 | if (!iface_state) { |
Rob Landley | 8bb5078 | 2006-05-26 23:44:51 +0000 | [diff] [blame] | 1315 | llist_add_to_end(&state_list, newiface); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1316 | } else { |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 1317 | free(iface_state->data); |
| 1318 | iface_state->data = newiface; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1319 | } |
Rob Landley | e813ddb | 2006-02-28 03:53:14 +0000 | [diff] [blame] | 1320 | } else { |
Denis Vlasenko | c115fdb | 2007-03-06 22:53:10 +0000 | [diff] [blame] | 1321 | /* Remove an interface from state_list */ |
| 1322 | llist_unlink(&state_list, iface_state); |
Rob Landley | a6e131d | 2006-05-29 06:43:55 +0000 | [diff] [blame] | 1323 | free(llist_pop(&iface_state)); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1324 | } |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1325 | |
Denis Vlasenko | bd100b7 | 2007-05-02 21:38:44 +0000 | [diff] [blame] | 1326 | /* Actually write the new state */ |
Denis Vlasenko | 5415c85 | 2008-07-21 23:05:26 +0000 | [diff] [blame] | 1327 | state_fp = xfopen_for_write(CONFIG_IFUPDOWN_IFSTATE_PATH); |
Denis Vlasenko | f92df58 | 2007-05-02 22:22:23 +0000 | [diff] [blame] | 1328 | state = state_list; |
| 1329 | while (state) { |
| 1330 | if (state->data) { |
| 1331 | fprintf(state_fp, "%s\n", state->data); |
Denis Vlasenko | bd100b7 | 2007-05-02 21:38:44 +0000 | [diff] [blame] | 1332 | } |
Denis Vlasenko | f92df58 | 2007-05-02 22:22:23 +0000 | [diff] [blame] | 1333 | state = state->link; |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 1334 | } |
Denis Vlasenko | f92df58 | 2007-05-02 22:22:23 +0000 | [diff] [blame] | 1335 | fclose(state_fp); |
Denis Vlasenko | bd100b7 | 2007-05-02 21:38:44 +0000 | [diff] [blame] | 1336 | llist_free(state_list, free); |
Glenn L McGrath | 8e49caa | 2002-12-08 01:23:39 +0000 | [diff] [blame] | 1337 | } |
Alexey Fomenko | 1df0af7 | 2011-03-02 04:13:21 +0100 | [diff] [blame] | 1338 | next: |
| 1339 | free(iface); |
| 1340 | free(liface); |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1341 | } |
| 1342 | |
Denis Vlasenko | fcfe834 | 2006-12-18 21:02:00 +0000 | [diff] [blame] | 1343 | return any_failures; |
Glenn L McGrath | 021fa7d | 2002-11-09 09:34:15 +0000 | [diff] [blame] | 1344 | } |