287
287
next) included at some point.
289
289
<<output dependency info for [[$chunk]]>>=
290
printf "%s : %s\n" "$chunk" "$FILE"
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"
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"
302
echo -e "$chunk : $FILE"
303
echo -e "\tnotangle -L -R\$@ $< | cpif \$@"
301
printf "\tnotangle -L -R\$@ \$< | cpif \$@\n"
306
echo -e "$chunk : $FILE"
307
echo -e "\tnotangle -t8 -R\$@ $< >\$@"
304
printf "\tnotangle -t8 -R\$@ $< >\$@\n"
1075
1072
<<structure definitions>>=
1076
1073
struct interfaces_file {
1077
int max_autointerfaces;
1078
int n_autointerfaces;
1079
char **autointerfaces;
1074
allowup_defn *allowups;
1081
1075
interface_defn *ifaces;
1082
1076
mapping_defn *mappings;
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:
1084
<<type definitions>>=
1085
typedef struct allowup_defn allowup_defn;
1088
<<structure definitions>>=
1089
struct allowup_defn {
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
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.
1091
1103
<<type definitions>>=
1092
1104
typedef struct interface_defn interface_defn;
1864
\subsubsection{Auto Line}
1890
\subsubsection{Auto and Allow Lines}
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.
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>>
1876
<<check [[firstword]] isn't already an auto interface or die>>=
1898
allowup_defn *auto_ups = get_allowup(&defn->allowups, "auto");
1900
<<report internal error and die>>
1902
while((rest = next_word(rest, firstword, 80))) {
1903
if (!add_allow_up(filename, line, auto_ups, firstword))
1907
<<process [[allow-]] line>>=
1908
allowup_defn *allow_ups = get_allowup(&defn->allowups, firstword + 6);
1910
<<report internal error and die>>
1912
while((rest = next_word(rest, firstword, 80))) {
1913
if (!add_allow_up(filename, line, allow_ups, firstword))
1918
<<config function declarations>>=
1919
allowup_defn *get_allowup(allowup_defn **allowups, char *name);
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;
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;
1939
We'll want to export a little helper function to make finding the appropriate
1942
<<exported symbols>>=
1943
allowup_defn *find_allowup(interfaces_file *defn, char *name);
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;
1956
<<config function declarations>>=
1957
allowup_defn *add_allow_up(char *filename, int line,
1958
allowup_defn *allow_up, char *iface_name);
1961
<<config functions>>=
1962
allowup_defn *add_allow_up(char *filename, int line,
1963
allowup_defn *allow_up, char *iface_name)
1965
<<check [[iface_name]] isn't already an [[allow_up]] interface or die>>
1966
<<add [[iface_name]] as an [[allow_up]] interface or die>>
1971
<<check [[iface_name]] isn't already an [[allow_up]] interface or die>>=
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>>
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) {
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>>
1898
defn->autointerfaces = tmp;
1993
allow_up->interfaces = tmp;
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++;
1905
2000
\subsection{Error Handling}
2970
3091
(cmds == iface_down)
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:
3099
<<we're limiting to [[--allow]]ed interfaces>>=
3100
(allow_class != NULL)
3102
<<find [[iface]] in [[allow_class]] or [[continue]]>>=
3105
allowup_defn *allowup = find_allowup(defn, allow_class);
3106
if (allowup == NULL)
3109
for (i = 0; i < allowup->n_interfaces; i++) {
3110
if (strcmp(allowup->interfaces[i], iface) == 0)
3113
if (i >= allowup->n_interfaces)
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:
2979
<<check if we exclude this interface>>=
3124
<<we're [[--exclude]]ing this interface>>=
2980
3125
(excludeint != NULL && strstr(iface,excludeint) != NULL)
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'},
3323
3478
/* successful */
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);
3328
3483
/* what happened here? */
3330
currif->iface = oldiface;
3333
<<run commands for [[currif]]>>=
3335
char *oldiface = currif->iface;
3336
currif->iface = iface;
3339
fprintf(stderr, "Configuring interface %s=%s (%s)\n",
3340
iface, liface, currif->address_family->name);
3343
switch(cmds(currif)) {
3345
printf("Don't seem to be have all the variables for %s/%s.\n",
3346
liface, currif->address_family->name);
3349
/* not entirely successful */
3354
currif->iface = oldiface;
3485
currif->real_iface = NULL;