~ubuntu-branches/ubuntu/jaunty/ifupdown/jaunty-201309120846

« back to all changes in this revision

Viewing changes to ifupdown.nw

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-05-27 06:43:06 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050527064306-mmu0c9p8os37l3bq
Tags: 0.6.7ubuntu1
* Resynchronise with Debian, resolving merge conflicts.
* Remove the initscripts dependency, since we now use our own readlink.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
\let\nwdocspar=\relax
12
12
 
13
13
\title{ Interface Tools\thanks{
14
 
Copyright \copyright\ 1999,2000 Anthony Towns. This program is free
 
14
Copyright \copyright\ 1999--2005 Anthony Towns. This program is free
15
15
software; you can redistribute it and/or modify it under the terms of
16
16
the GNU General Public License as published by the Free Software
17
17
Foundation; either version 2 of the License, or (at your option) any
222
222
of compiling source code.
223
223
 
224
224
<<make options>>=
225
 
CFLAGS := -Wall -W -g -O2 -D'IFUPDOWN_VERSION="0.6.4"'
 
225
CFLAGS := -Wall -W -g -O2 -D'IFUPDOWN_VERSION="0.6.5"'
226
226
CC := gcc
227
227
228
228
 
287
287
next) included at some point.
288
288
 
289
289
<<output dependency info for [[$chunk]]>>=
 
290
printf "%s : %s\n" "$chunk" "$FILE"
290
291
case $chunk in
291
292
        *.pl|*.sh)
292
 
                echo -e "$chunk : $FILE"
293
 
                echo -e "\tnotangle -R\$@ $< >\$@"
294
 
                echo -e "\tchmod 755 $chunk"
 
293
                printf "\tnotangle -R\$@ \$< >\$@\n"
 
294
                printf "\tchmod 755 %s\n" "$chunk"
295
295
                ;;
296
296
        *.c)
297
 
                echo -e "$chunk : $FILE"
298
 
                echo -e "\tnotangle -L -R\$@ $< | cpif \$@"
299
 
                echo -e "include ${chunk%.c}.d"
 
297
                printf "\tnotangle -L -R\$@ \$< | cpif \$@\n"
 
298
                printf "include ${chunk%.c}.d\n"
300
299
                ;;
301
300
        *.h)
302
 
                echo -e "$chunk : $FILE"
303
 
                echo -e "\tnotangle -L -R\$@ $< | cpif \$@"
 
301
                printf "\tnotangle -L -R\$@ \$< | cpif \$@\n"
304
302
                ;;
305
303
        *)
306
 
                echo -e "$chunk : $FILE"
307
 
                echo -e "\tnotangle -t8 -R\$@ $< >\$@"
 
304
                printf "\tnotangle -t8 -R\$@ $< >\$@\n"
308
305
                ;;
309
306
esac
310
307
1074
1071
 
1075
1072
<<structure definitions>>=
1076
1073
struct interfaces_file {
1077
 
        int max_autointerfaces;
1078
 
        int n_autointerfaces;
1079
 
        char **autointerfaces;
1080
 
 
 
1074
        allowup_defn *allowups;
1081
1075
        interface_defn *ifaces;
1082
1076
        mapping_defn *mappings;
1083
1077
};
 
1078
@
 
1079
 
 
1080
So, at run-time, we first need a way of dealing with the [[auto]] and
 
1081
[[allow-*]] lines. We'll treat [[allow-auto]] and [[auto]] as equivalent,
 
1082
making that pretty straightforward:
 
1083
 
 
1084
<<type definitions>>=
 
1085
typedef struct allowup_defn allowup_defn;
 
1086
@
 
1087
 
 
1088
<<structure definitions>>=
 
1089
struct allowup_defn {
 
1090
        allowup_defn *next;
 
1091
 
 
1092
        char *when;
 
1093
        int max_interfaces;
 
1094
        int n_interfaces;
 
1095
        char **interfaces;
 
1096
};
1084
1097
1085
1098
 
1086
 
So, at run-time, we require a way of representing each interface
1087
 
listed in the configuration file. This naturally needs to reference an
1088
 
address family and method, and all the options a user may specify
1089
 
about an interface.
 
1099
We also require a way of representing each interface listed in the
 
1100
configuration file. This naturally needs to reference an address family
 
1101
and method, and all the options a user may specify about an interface.
1090
1102
 
1091
1103
<<type definitions>>=
1092
1104
typedef struct interface_defn interface_defn;
1096
1108
struct interface_defn {
1097
1109
        interface_defn *next;
1098
1110
 
1099
 
        char *iface;
 
1111
        char *logical_iface;
 
1112
        char *real_iface;
 
1113
 
1100
1114
        address_family *address_family;
1101
1115
        method *method;
1102
1116
 
1182
1196
if (defn == NULL) {
1183
1197
        return NULL;
1184
1198
}
1185
 
defn->max_autointerfaces = defn->n_autointerfaces = 0;
1186
 
defn->autointerfaces = NULL;
 
1199
defn->allowups = NULL;
1187
1200
defn->mappings = NULL;
1188
1201
defn->ifaces = NULL;
1189
1202
1490
1503
} else if (strcmp(firstword, "auto") == 0) {
1491
1504
        <<process [[auto]] line>>
1492
1505
        currently_processing = NONE;
 
1506
} else if (strncmp(firstword, "allow-", 6) == 0 && strlen(firstword) > 6) {
 
1507
        <<process [[allow-]] line>>
 
1508
        currently_processing = NONE;
1493
1509
} else {
1494
1510
        <<process option line>>
1495
1511
}
1671
1687
We then want to store the interface name.
1672
1688
 
1673
1689
<<set iface name>>=
1674
 
currif->iface = strdup(iface_name);
1675
 
if (!currif->iface) {
 
1690
currif->logical_iface = strdup(iface_name);
 
1691
if (!currif->logical_iface) {
1676
1692
        <<report internal error and die>>
1677
1693
}
1678
1694
1786
1802
 
1787
1803
<<config functions>>=
1788
1804
static int duplicate_if(interface_defn *ifa, interface_defn *ifb) {
1789
 
        if (strcmp(ifa->iface, ifb->iface) != 0) return 0;
 
1805
        if (strcmp(ifa->logical_iface, ifb->logical_iface) != 0) return 0;
1790
1806
        if (ifa->address_family != ifb->address_family) return 0;
1791
1807
        return 1;
1792
1808
}
1796
1812
with. 
1797
1813
 
1798
1814
<<process iface option line>>=
 
1815
<<convert [[post-up]] and [[pre-down]] aliases to [[up]] and [[down]]>>
1799
1816
<<check for duplicate options>>
1800
1817
<<add option>>
1801
 
 
1818
@
 
1819
 
 
1820
<<convert [[post-up]] and [[pre-down]] aliases to [[up]] and [[down]]>>=
 
1821
if (strcmp(firstword, "post-up") == 0) {
 
1822
        strcpy(firstword, "up");
 
1823
}
 
1824
if (strcmp(firstword, "pre-down") == 0) {
 
1825
        strcpy(firstword, "down");
 
1826
 
1827
@
1802
1828
 
1803
1829
<<check for duplicate options>>=
1804
1830
{
1808
1834
                <<report empty option and die>>
1809
1835
        }
1810
1836
 
1811
 
        if (strcmp(firstword, "up") != 0
 
1837
        if (strcmp(firstword, "pre-up") != 0 
 
1838
            && strcmp(firstword, "up") != 0
1812
1839
            && strcmp(firstword, "down") != 0
1813
 
            && strcmp(firstword, "pre-up") != 0
1814
1840
            && strcmp(firstword, "post-down") != 0)
1815
1841
        {
1816
1842
                for (i = 0; i < currif->n_options; i++) {
1861
1887
}
1862
1888
1863
1889
 
1864
 
\subsubsection{Auto Line}
 
1890
\subsubsection{Auto and Allow Lines}
1865
1891
 
1866
 
Processing an [[auto]] line is pretty straightforward after the above,
1867
 
we just need to add each parameter to the list and check for duplicates.
 
1892
Processing the [[auto]] and [[allow-]] lines is pretty straightforward
 
1893
after the above, we just need to add each parameter to the list and
 
1894
check for duplicates. Since we're doing essentially the same thing twice,
 
1895
we'll break the common part out into a function.
1868
1896
 
1869
1897
<<process [[auto]] line>>=
1870
 
while((rest = next_word(rest, firstword, 80))) {
1871
 
        <<check [[firstword]] isn't already an auto interface or die>>
1872
 
        <<add [[firstword]] as an auto interface or die>>
1873
 
}
1874
 
1875
 
 
1876
 
<<check [[firstword]] isn't already an auto interface or die>>=
 
1898
allowup_defn *auto_ups = get_allowup(&defn->allowups, "auto");
 
1899
if (!auto_ups) {
 
1900
        <<report internal error and die>>
 
1901
}
 
1902
while((rest = next_word(rest, firstword, 80))) {
 
1903
        if (!add_allow_up(filename, line, auto_ups, firstword))
 
1904
                return NULL;
 
1905
}
 
1906
 
1907
<<process [[allow-]] line>>=
 
1908
allowup_defn *allow_ups = get_allowup(&defn->allowups, firstword + 6);
 
1909
if (!allow_ups) {
 
1910
        <<report internal error and die>>
 
1911
}
 
1912
while((rest = next_word(rest, firstword, 80))) {
 
1913
        if (!add_allow_up(filename, line, allow_ups, firstword))
 
1914
                return NULL;
 
1915
}
 
1916
 
1917
 
 
1918
<<config function declarations>>=
 
1919
allowup_defn *get_allowup(allowup_defn **allowups, char *name);
 
1920
 
 
1921
<<config functions>>=
 
1922
allowup_defn *get_allowup(allowup_defn **allowups, char *name) {
 
1923
        for (; *allowups; allowups = &(*allowups)->next) {
 
1924
                if (strcmp((*allowups)->when, name) == 0) break;
 
1925
        }
 
1926
        if (*allowups == NULL) {
 
1927
                *allowups = malloc(sizeof(allowup_defn));
 
1928
                if (*allowups == NULL) return NULL;
 
1929
                (*allowups)->when = strdup(name);
 
1930
                (*allowups)->next = NULL;
 
1931
                (*allowups)->max_interfaces = 0;
 
1932
                (*allowups)->n_interfaces = 0;
 
1933
                (*allowups)->interfaces = NULL;
 
1934
        }
 
1935
        return *allowups;
 
1936
}
 
1937
@
 
1938
 
 
1939
We'll want to export a little helper function to make finding the appropriate
 
1940
allowup easier too:
 
1941
 
 
1942
<<exported symbols>>=
 
1943
allowup_defn *find_allowup(interfaces_file *defn, char *name);
 
1944
@
 
1945
 
 
1946
<<config functions>>=
 
1947
allowup_defn *find_allowup(interfaces_file *defn, char *name) {
 
1948
        allowup_defn *allowups = defn->allowups;
 
1949
        for (; allowups; allowups = allowups->next) {
 
1950
                if (strcmp(allowups->when, name) == 0) break;
 
1951
        }
 
1952
        return allowups;
 
1953
}
 
1954
@
 
1955
 
 
1956
<<config function declarations>>=
 
1957
allowup_defn *add_allow_up(char *filename, int line,
 
1958
         allowup_defn *allow_up, char *iface_name);
 
1959
@
 
1960
 
 
1961
<<config functions>>=
 
1962
allowup_defn *add_allow_up(char *filename, int line,
 
1963
        allowup_defn *allow_up, char *iface_name)
 
1964
{
 
1965
        <<check [[iface_name]] isn't already an [[allow_up]] interface or die>>
 
1966
        <<add [[iface_name]] as an [[allow_up]] interface or die>>
 
1967
        return allow_up;
 
1968
}
 
1969
@
 
1970
 
 
1971
<<check [[iface_name]] isn't already an [[allow_up]] interface or die>>=
1877
1972
{
1878
1973
        int i;
1879
1974
 
1880
 
        for (i = 0; i < defn->n_autointerfaces; i++) {
1881
 
                if (strcmp(firstword, defn->autointerfaces[i]) == 0) {
1882
 
                        <<report duplicate auto interface and die>>
 
1975
        for (i = 0; i < allow_up->n_interfaces; i++) {
 
1976
                if (strcmp(iface_name, allow_up->interfaces[i]) == 0) {
 
1977
                        <<report [[iface_name]] as [[allow_up]] duplicate, die>>
1883
1978
                }
1884
1979
        }
1885
1980
}
1886
1981
@
1887
1982
 
1888
 
<<add [[firstword]] as an auto interface or die>>=
1889
 
if (defn->n_autointerfaces == defn->max_autointerfaces) {
 
1983
<<add [[iface_name]] as an [[allow_up]] interface or die>>=
 
1984
if (allow_up->n_interfaces == allow_up->max_interfaces) {
1890
1985
        char **tmp;
1891
 
        defn->max_autointerfaces *= 2;
1892
 
        defn->max_autointerfaces++;
1893
 
        tmp = realloc(defn->autointerfaces, 
1894
 
                sizeof(*tmp) * defn->max_autointerfaces);
 
1986
        allow_up->max_interfaces *= 2;
 
1987
        allow_up->max_interfaces++;
 
1988
        tmp = realloc(allow_up->interfaces, 
 
1989
                sizeof(*tmp) * allow_up->max_interfaces);
1895
1990
        if (tmp == NULL) {
1896
1991
                <<report internal error and die>>
1897
1992
        }
1898
 
        defn->autointerfaces = tmp;
 
1993
        allow_up->interfaces = tmp;
1899
1994
}
1900
1995
 
1901
 
defn->autointerfaces[defn->n_autointerfaces] = strdup(firstword);
1902
 
defn->n_autointerfaces++;
 
1996
allow_up->interfaces[allow_up->n_interfaces] = strdup(iface_name);
 
1997
allow_up->n_interfaces++;
1903
1998
@
1904
1999
 
1905
2000
\subsection{Error Handling}
1939
2034
return NULL;
1940
2035
@
1941
2036
 
1942
 
<<report duplicate auto interface and die>>=
1943
 
fprintf(stderr, "%s:%d: interface declared auto twice\n", filename, line);
 
2037
<<report [[iface_name]] as [[allow_up]] duplicate, die>>=
 
2038
fprintf(stderr, "%s:%d: interface %s declared allow-%s twice\n", 
 
2039
        filename, line, iface_name, allow_up->when);
1944
2040
return NULL;
1945
2041
@
1946
2042
 
2068
2164
that is, a [[NULL]]-terminated array of strings of the form [[foo=bar]].
2069
2165
 
2070
2166
<<execute function declarations>>=
2071
 
static void set_environ(interface_defn *iface, char *mode);
 
2167
static void set_environ(interface_defn *iface, char *mode, char *phase);
2072
2168
@
2073
2169
 
2074
2170
Our function then will be:
2075
2171
 
2076
2172
<<execute functions>>=
2077
 
static void set_environ(interface_defn *iface, char *mode) {
 
2173
static void set_environ(interface_defn *iface, char *mode, char *phase) {
2078
2174
        <<variables local to set environ>>
2079
2175
        int i;
2080
 
        const int n_env_entries = iface->n_options + 5;
 
2176
        const int n_env_entries = iface->n_options + 8;
2081
2177
 
2082
2178
        <<initialise environ [[n_env_entries]]>>
2083
2179
 
2088
2184
        }
2089
2185
 
2090
2186
        <<add [[IFACE]] to environment>>
 
2187
        <<add [[LOGICAL]] to environment>>
2091
2188
        <<add [[ADDRFAM]] to environment>>
2092
2189
        <<add [[METHOD]] to environment>>
 
2190
 
2093
2191
        <<add [[MODE]] to environment>>
 
2192
        <<add [[PHASE]] to environment>>
 
2193
        <<add [[VERBOSITY]] to environment>>
2094
2194
        <<add [[PATH]] to environment>>
2095
2195
}
2096
2196
@
2112
2212
@
2113
2213
 
2114
2214
<<clear environ if necessary>>=
2115
 
{
 
2215
if (environ != NULL) {
2116
2216
        char **ppch;
2117
 
        if (environ != NULL) {
2118
 
                for (ppch = environ; *ppch; ppch++) {
2119
 
                        free(*ppch);
2120
 
                        *ppch = NULL;
2121
 
                }
2122
 
                free(environ);
2123
 
                environ = NULL;
 
2217
        for (ppch = environ; *ppch; ppch++) {
 
2218
                free(*ppch);
 
2219
                *ppch = NULL;
2124
2220
        }
 
2221
        free(environ);
 
2222
        environ = NULL;
2125
2223
}
2126
2224
@
2127
2225
 
2128
2226
Our continue chunk is also fairly straight forward:
2129
2227
 
2130
2228
<<[[continue]] if option is a command>>=
2131
 
if (strcmp(iface->option[i].name, "up") == 0
 
2229
if (strcmp(iface->option[i].name, "pre-up") == 0
 
2230
    || strcmp(iface->option[i].name, "up") == 0
2132
2231
    || strcmp(iface->option[i].name, "down") == 0
2133
 
    || strcmp(iface->option[i].name, "pre-up") == 0
2134
2232
    || strcmp(iface->option[i].name, "post-down") == 0)
2135
2233
{
2136
2234
        continue;
2156
2254
@
2157
2255
 
2158
2256
<<add [[IFACE]] to environment>>=
2159
 
*(environend++) = setlocalenv("%s=%s", "IFACE", iface->iface);
 
2257
*(environend++) = setlocalenv("%s=%s", "IFACE", iface->real_iface);
 
2258
*environend = NULL;
 
2259
@
 
2260
 
 
2261
<<add [[LOGICAL]] to environment>>=
 
2262
*(environend++) = setlocalenv("%s=%s", "LOGICAL", iface->logical_iface);
2160
2263
*environend = NULL;
2161
2264
@
2162
2265
 
2165
2268
*environend = NULL;
2166
2269
@
2167
2270
 
 
2271
<<add [[PHASE]] to environment>>=
 
2272
*(environend++) = setlocalenv("%s=%s", "PHASE", phase); 
 
2273
*environend = NULL;
 
2274
@
 
2275
 
2168
2276
<<add [[PATH]] to environment>>=
2169
2277
*(environend++) = setlocalenv("%s=%s", "PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin");
2170
2278
*environend = NULL;
2171
2279
@
2172
2280
 
 
2281
<<add [[VERBOSITY]] to environment>>=
 
2282
*(environend++) = setlocalenv("%s=%s", "VERBOSITY", verbose ? "1" : "0");
 
2283
*environend = NULL;
 
2284
@
 
2285
 
2173
2286
<<add [[ADDRFAM]] to environment>>=
2174
2287
*(environend++) = setlocalenv("%s=%s", "ADDRFAM", iface->address_family->name);
2175
2288
*environend = NULL;
2303
2416
                }
2304
2417
        }
2305
2418
 
2306
 
        sprintf(buf, "run-parts /etc/network/if-%s.d", opt);
 
2419
        snprintf(buf, sizeof(buf), "run-parts %s /etc/network/if-%s.d",
 
2420
                verbose ? "--verbose" : "", opt);
 
2421
 
2307
2422
        (*exec)(buf); 
2308
2423
 
2309
2424
        return 1;
2323
2438
int iface_up(interface_defn *iface) {
2324
2439
        if (!iface->method->up(iface,check)) return -1;
2325
2440
 
2326
 
        set_environ(iface, "start");
 
2441
        set_environ(iface, "start", "pre-up");
2327
2442
        if (!execute_all(iface,doit,"pre-up")) return 0;
 
2443
 
2328
2444
        if (!iface->method->up(iface,doit)) return 0;
 
2445
 
 
2446
        set_environ(iface, "start", "post-up");
2329
2447
        if (!execute_all(iface,doit,"up")) return 0;
2330
2448
 
2331
2449
        return 1;
2336
2454
int iface_down(interface_defn *iface) {
2337
2455
        if (!iface->method->down(iface,check)) return -1;
2338
2456
 
2339
 
        set_environ(iface, "stop");
 
2457
        set_environ(iface, "stop", "pre-down");
2340
2458
        if (!execute_all(iface,doit,"down")) return 0;
 
2459
 
2341
2460
        if (!iface->method->down(iface,doit)) return 0;
 
2461
 
 
2462
        set_environ(iface, "stop", "post-down");
2342
2463
        if (!execute_all(iface,doit,"post-down")) return 0;
2343
2464
 
2344
2465
        return 1;
2680
2801
        int i;
2681
2802
 
2682
2803
        if (strncmpz(id, "iface", idlen) == 0) {
2683
 
                return ifd->iface;
 
2804
                return ifd->real_iface;
2684
2805
        } else {
2685
2806
                for (i = 0; i < ifd->n_options; i++) {
2686
2807
                        if (strncmpz(id, ifd->option[i].name, idlen) == 0) {
2970
3091
(cmds == iface_down)
2971
3092
@
2972
3093
 
2973
 
Finally, since the behaviour might vary depending on whether we are 
2974
 
excluding this interface or not we'll define it. Notice that
 
3094
The [[--allow]] option lets us limit the interfaces ifupdown will act on.
 
3095
It's implemented by having an [[allow_class]] that tells us which class
 
3096
of interfaces we're working with, and skipping interfaces that aren't
 
3097
in that class, like so:
 
3098
 
 
3099
<<we're limiting to [[--allow]]ed interfaces>>=
 
3100
(allow_class != NULL)
 
3101
 
 
3102
<<find [[iface]] in [[allow_class]] or [[continue]]>>=
 
3103
{
 
3104
        int i;
 
3105
        allowup_defn *allowup = find_allowup(defn, allow_class);
 
3106
        if (allowup == NULL)
 
3107
                continue;
 
3108
 
 
3109
        for (i = 0; i < allowup->n_interfaces; i++) {
 
3110
                if (strcmp(allowup->interfaces[i], iface) == 0)
 
3111
                        break;
 
3112
        }
 
3113
        if (i >= allowup->n_interfaces)
 
3114
                continue;
 
3115
}
 
3116
@
 
3117
 
 
3118
Finally, the behaviour might vary depending on whether we are 
 
3119
excluding this interface or not. Notice that
2975
3120
the exclude option can use a full interface name or substrings that
2976
3121
match interfaces. A user could easily have unexpected behaviour
2977
3122
if he uses a small string to do the match:
2978
3123
 
2979
 
<<check if we exclude this interface>>=
 
3124
<<we're [[--exclude]]ing this interface>>=
2980
3125
(excludeint != NULL && strstr(iface,excludeint) != NULL)
2981
3126
@
2982
3127
 
2998
3143
        {"version",     no_argument,       NULL, 'V'},
2999
3144
        {"verbose",     no_argument,       NULL, 'v'},
3000
3145
        {"all",         no_argument,       NULL, 'a'},
 
3146
        {"allow",       required_argument, NULL,  3 },
3001
3147
        {"interfaces",  required_argument, NULL, 'i'},
3002
3148
        {"exclude",     required_argument, NULL, 'e'},
3003
3149
        {"no-act",      no_argument,       NULL, 'n'},
3025
3171
int do_all = 0;
3026
3172
int run_mappings = 1;
3027
3173
int force = 0;
 
3174
char *allow_class = NULL;
3028
3175
char *interfaces = "/etc/network/interfaces";
3029
 
char *statefile = "/etc/network/ifstate";
 
3176
char *statefile = "/etc/network/run/ifstate";
3030
3177
char *excludeint = NULL ;
3031
3178
3032
3179
 
3049
3196
<<main functions>>=
3050
3197
static void version(char *execname) {
3051
3198
        printf("%s version " IFUPDOWN_VERSION "\n", execname);
3052
 
        printf("Copyright (c) 1999,2000 Anthony Towns\n\n");
 
3199
        printf("Copyright (c) 1999-2005 Anthony Towns\n\n");
3053
3200
        printf(
3054
3201
 
3055
3202
"This program is free software; you can redistribute it and/or modify\n"
3069
3216
        printf("\t-h, --help\t\tthis help\n");
3070
3217
        printf("\t-V, --version\t\tcopyright and version information\n");
3071
3218
        printf("\t-a, --all\t\tde/configure all interfaces marked \"auto\"\n");
 
3219
        printf("\t--allow CLASS\t\tignore non-\"allow-CLASS\" interfaces\n");
3072
3220
        printf("\t-i, --interfaces FILE\tuse FILE for interface definitions\n");
3073
 
        printf("\t-e, --exclude IFACE\texclude a given interface from the operation\n");
3074
3221
        printf("\t-n, --no-act\t\tprint out what would happen, but don't do it\n");
3075
3222
        printf("\t\t\t\t(note that this option doesn't disable mappings)\n");
3076
3223
        printf("\t-v, --verbose\t\tprint out what would happen before doing it\n");
3117
3264
        break;
3118
3265
3119
3266
<<[[getopt]] possibilities>>=
 
3267
case 3:
 
3268
        allow_class = strdup(optarg);
 
3269
        break;
 
3270
 
3271
<<[[getopt]] possibilities>>=
3120
3272
case 'n':
3121
3273
        no_act = 1;
3122
3274
        break;
3212
3364
                        <<check ifupdown state (possibly [[continue]])>>
3213
3365
                }
3214
3366
 
3215
 
                if (<<check if we exclude this interface>>)  
 
3367
                if (<<we're limiting to [[--allow]]ed interfaces>>) {
 
3368
                        <<find [[iface]] in [[allow_class]] or [[continue]]>>
 
3369
                }
 
3370
 
 
3371
                if (<<we're [[--exclude]]ing this interface>>)  
3216
3372
                        continue;
3217
3373
 
3218
3374
                if (<<we're bringing interfaces up>> && run_mappings) {
3277
3433
        int okay = 0;
3278
3434
        int failed = 0; 
3279
3435
        for (currif = defn->ifaces; currif; currif = currif->next) {
3280
 
                if (strcmp(liface, currif->iface) == 0) {
 
3436
                if (strcmp(liface, currif->logical_iface) == 0) {
3281
3437
                        okay = 1;
3282
3438
 
3283
3439
                        <<run commands for [[currif]]; set [[failed]] on error>>
3299
3455
 
3300
3456
<<run commands for [[currif]]; set [[failed]] on error>>=
3301
3457
{
3302
 
        char *oldiface = currif->iface;
3303
 
        currif->iface = iface;
 
3458
        currif->real_iface = iface;
3304
3459
 
3305
3460
        if (verbose) {
3306
3461
                fprintf(stderr, "Configuring interface %s=%s (%s)\n", 
3322
3477
                break;
3323
3478
                /* successful */
3324
3479
            default:
3325
 
                printf("Unexpected value when configuring interface %s/%s considering it failed.\n", 
 
3480
                printf("Internal error while configuring interface %s/%s (assuming it failed)\n", 
3326
3481
                        liface, currif->address_family->name);
3327
3482
                failed = 1;
3328
3483
                /* what happened here? */
3329
3484
        }
3330
 
        currif->iface = oldiface;
3331
 
}
3332
 
3333
 
<<run commands for [[currif]]>>=
3334
 
{
3335
 
        char *oldiface = currif->iface;
3336
 
        currif->iface = iface;
3337
 
 
3338
 
        if (verbose) {
3339
 
                fprintf(stderr, "Configuring interface %s=%s (%s)\n", 
3340
 
                        iface, liface, currif->address_family->name);
3341
 
        }
3342
 
 
3343
 
        switch(cmds(currif)) {
3344
 
            case -1:
3345
 
                printf("Don't seem to be have all the variables for %s/%s.\n", 
3346
 
                        liface, currif->address_family->name);
3347
 
                break;
3348
 
            case 0:
3349
 
                /* not entirely successful */
3350
 
                 */
3351
 
            case 1:
3352
 
                /* successful */
3353
 
        }
3354
 
        currif->iface = oldiface;
 
3485
        currif->real_iface = NULL;
3355
3486
}
3356
3487
3357
3488
 
3376
3507
<<determine target interfaces>>=
3377
3508
if (do_all) {
3378
3509
        if (<<we're bringing interfaces up>>) {
3379
 
                target_iface = defn->autointerfaces;
3380
 
                n_target_ifaces = defn->n_autointerfaces;
 
3510
                allowup_defn *autos = find_allowup(defn, "auto");
 
3511
                target_iface = autos ? autos->interfaces : NULL;
 
3512
                n_target_ifaces = autos ? autos->n_interfaces : 0;
3381
3513
        } else if (<<we're taking interfaces down>>) {
3382
3514
                target_iface = state;
3383
3515
                n_target_ifaces = n_state;
3416
3548
were mapped to which logical ones. We ought to use 
3417
3549
[[/var/run/ifupdown.state]] or something similar for this, but [[/var]]
3418
3550
isn't guaranteed to be available until the network's up, so we'll use
3419
 
[[/etc/network/ifstate]] instead.
 
3551
[[/etc/network/run/ifstate]] instead.
3420
3552
 
3421
3553
<<variables local to main>>=
3422
3554
char **state = NULL; /* list of iface=liface */
3853
3985
method wvdial
3854
3986
  description
3855
3987
    This method uses wvdial to configure a PPP interface. See that command
3856
 
    for ore details.
 
3988
    for more details.
3857
3989
  options
3858
3990
    provider name  -- Use /name/ as the provider (from /etc/ppp/peers).
3859
3991
  up