1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00

cleanup and some documentation

Ticket: CM-1438
Reviewed By:
Testing Done:
This commit is contained in:
roopa
2014-02-13 21:37:26 -08:00
parent f321512771
commit f802fe3ccb
6 changed files with 157 additions and 316 deletions

2
TODO
View File

@ -1,5 +1,7 @@
TODO: TODO:
==== ====
- support old ifupdown state file /run/network/ifstate. B
- support -i interfaces file
- support for debian ifupdown methods: tunnel, v4tunnel, 6to4, ppp, wvdial, ipv4ll - support for debian ifupdown methods: tunnel, v4tunnel, 6to4, ppp, wvdial, ipv4ll
- support for debian ifupdown ipv6 auto method - support for debian ifupdown ipv6 auto method
- support for debian ifupdown CAN address family - support for debian ifupdown CAN address family

View File

@ -1 +0,0 @@
.so ifup.8

View File

@ -1 +0,0 @@
.so ifup.8

View File

@ -1,232 +0,0 @@
.TH ifup 8 "22 May 2004" IFUPDOWN ""
.SH NAME
ifup \- bring a network interface up
.PP
ifdown \- take a network interface down
.PP
ifquery \- parse interface configuration
.SH SYNOPSIS
.B ifup
[\fB\-nv\fR]
[\fB\-\-no\-act\fR]
[\fB\-\-verbose\fR]
[\fB\-i\fR \fIFILE\fR|\fB\-\-interfaces=\fR\fIFILE\fR]
[\fB\-\-allow\fR \fICLASS\fR]
\fB\-a\fR|\fIIFACE\fR...
.br
.B ifup
\fB\-h\fR|\fB\-\-help\fR
.br
.B ifup
\fB\-V\fR|\fB\-\-version\fR
.PP
.B ifdown
[\fB\-nv\fR]
[\fB\-\-no\-act\fR]
[\fB\-\-verbose\fR]
[\fB\-i\fR \fIFILE\fR|\fB\-\-interfaces=\fR\fIFILE\fR]
[\fB\-\-allow\fR \fICLASS\fR]
\fB\-a\fR|\fIIFACE\fR...
.PP
.B ifquery
[\fB\-nv\fR]
[\fB\-\-no\-act\fR]
[\fB\-\-verbose\fR]
[\fB\-i\fR \fIFILE\fR|\fB\-\-interfaces=\fR\fIFILE\fR]
[\fB\-\-allow\fR \fICLASS\fR]
\fB\-a\fR|\fIIFACE\fR...
.PP
.B ifquery
\fB\-l\fR|\fB\-\-list\fR
[\fB\-nv\fR]
[\fB\-\-no\-act\fR]
[\fB\-\-verbose\fR]
[\fB\-i\fR \fIFILE\fR|\fB\-\-interfaces=\fR\fIFILE\fR]
[\fB\-\-allow\fR \fICLASS\fR]
\fB\-a\fR|\fIIFACE\fR...
.SH DESCRIPTION
The
.BR ifup " and " ifdown
commands may be used to configure (or, respectively, deconfigure) network
interfaces based on interface definitions in the file
.IR /etc/network/interfaces ". "
.BR ifquery " command may be used to parse interfaces configuration."
.SH OPTIONS
A summary of options is included below.
.TP
.BR \-a ", " \-\-all
If given to \fBifup\fP, affect all interfaces marked \fBauto\fP.
Interfaces are brought up in the order in which they are defined
in
.IR /etc/network/interfaces .
Combined with \fB-\-allow\fP, acts on all interfaces of a specified class
instead.
If given to \fBifdown\fP, affect all defined interfaces.
Interfaces are brought down in the order in which they are
currently listed in the state file. Only interfaces defined
in
.I /etc/network/interfaces
will be brought down.
.TP
.B \-\-force
Force configuration or deconfiguration of the interface.
.TP
.BR \-h ", " \-\-help
Show summary of options.
.TP
\fB\-\-allow=\fR\fICLASS\fR
Only allow interfaces listed in an
.I allow\-CLASS
line in
.IR /etc/network/interfaces " to be acted upon."
.TP
\fB\-i\fR \fIFILE\fR, \fB\-\-interfaces=\fR\fIFILE\fR
Read interface definitions from
.I FILE
instead of from
.IR /etc/network/interfaces "."
.TP
.BI \-X " PATTERN\fR, " "\-\-exclude=" PATTERN
Exclude interfaces from the list of interfaces to operate on by the \fIPATTERN\fR.
\fIPATTERN\fR uses a usual shell glob syntax. If shell wildcards are not used, it
must match the exact interface name. This option may be specified multiple times
resulting in more than one pattern being excluded.
.TP
.BI \-o " OPTION" "\fB=" VALUE
Set \fIOPTION\fR to \fIVALUE\fR as though it were in
.IR /etc/network/interfaces .
.TP
.BR \-n ", " \-\-no\-act
Don't configure any interfaces or run any "up" or "down" commands.
.TP
.B \-\-no\-mappings
Don't run any mappings. See
.BR interfaces (5)
for more information about the mapping feature.
.TP
.B \-\-no\-scripts
Don't run any scripts under /etc/network/if-*.d/
.TP
.BR \-V ", " \-\-version
Show copyright and version information.
.TP
.BR \-v ", " \-\-verbose
Show commands as they are executed.
.TP
.BR \-l ", " \-\-list
For \fBifquery\fR, list all the interfaces which match the specified class.
If no class specified, prints all the interfaces listed as \fBauto\fR.
.SH EXAMPLES
.TP
.B ifup -a
Bring up all the interfaces defined with
.I auto
in
.I /etc/network/interfaces
.TP
.B ifup eth0
Bring up interface
.B eth0
.TP
.B ifup eth0=home
Bring up interface
.B eth0
as logical interface
.B home
.TP
.B ifdown -a
Bring down all interfaces that are currently up.
.TP
.B ifquery -l
Print names of all interfaces specified with the \fBauto\fR keyword.
.TP
.B ifquery -l --allow=hotplug
Print names of all interfaces specified with the \fBallow-hotplug\fR keyword.
.TP
.B ifquery eth0
Display the interface options as specified in the \fBifupdown\fR
configuration. Each key-value pair is printed out on individual
line using "\fB: \fR" as separator.
.SH NOTES
.BR ifup ,
.BR ifdown ,
and
.BR ifquery
are actually the same program called by different names.
.P
The program does not configure network interfaces directly;
it runs low level utilities such as
.BR ip
to do its dirty work.
.P
When invoked,
.B ifdown
checks if
.B ifup
is still running. In that case,
.B SIGTERM
is sent to ifup.
.SH FILES
.TP
.I /etc/network/interfaces
definitions of network interfaces
See
.BR interfaces (5)
for more information.
.TP
.I /run/network/ifstate
current state of network interfaces
.SH KNOWN BUGS/LIMITATIONS
The program keeps records of whether network interfaces are up or down.
Under exceptional circumstances these records can become
inconsistent with the real states of the interfaces.
For example, an interface that was brought up using
.B ifup
and later deconfigured using
.B ifconfig
will still be recorded as up.
To fix this you can use the
.B \-\-force
option to force
.B ifup
or
.B ifdown
to run configuration or deconfiguration commands despite what
it considers the current state of the interface to be.
.P
The file
.I /run/network/ifstate
must be writable for
.B ifup
or
.B ifdown
to work properly.
If that location is not writable
(for example, because the root filesystem is mounted read-only
for system recovery)
then
.I /run/network/ifstate
should be made a symbolic link to a writable location.
If that is not possible then you can use the
.B \-\-force
option to run configuration or deconfiguration commands
without updating the file.
.P
Note that the program does not run automatically:
.B ifup
alone does not bring up interfaces
that appear as a result of hardware being installed and
.B ifdown
alone does not bring down interfaces
that disappear as a result of hardware being removed.
To automate the configuration of network interfaces you need to
install other packages such as
.BR udev (7)
or
.BR ifplugd (8).
.SH AUTHOR
The ifupdown suite was written by Anthony Towns <aj@azure.humbug.org.au>.
.SH SEE ALSO
.BR interfaces (5),
.BR ip (8),
.BR ifconfig (8).

View File

@ -139,7 +139,6 @@ class ifupdownMain():
return self.ifaceobjdict return self.ifaceobjdict
def set_ifaceobjdict(self, ifaceobjdict): def set_ifaceobjdict(self, ifaceobjdict):
del self.ifaceobjdict
self.ifaceobjdict = ifaceobjdict self.ifaceobjdict = ifaceobjdict
def set_dependency_graph(self, dependency_graph): def set_dependency_graph(self, dependency_graph):
@ -511,7 +510,8 @@ class ifupdownMain():
self.operations_compat[op].append( self.operations_compat[op].append(
msubdir + '/' + module) msubdir + '/' + module)
except: except:
raise # continue reading
pass
def conv_iface_namelist_to_objlist(self, intf_list): def conv_iface_namelist_to_objlist(self, intf_list):
for intf in intf_list: for intf in intf_list:
@ -912,14 +912,8 @@ class ifupdownMain():
%str(ifacedownlist)) %str(ifacedownlist))
# Generate dependency info for old config # Generate dependency info for old config
self.populate_dependency_info(ifacedownlist, downops) self.populate_dependency_info(ifacedownlist, downops)
if len(ifacedownlist) == len(self.ifaceobjdict): self.run_with_dependents(downops, ifacedownlist)
# if you are downing all interfaces, its better run
# with dependents
self.run_with_dependents(downops, ifacedownlist)
else:
# if not, down only the interfaces that we have in the
# down list
self.run_without_dependents(downops, ifacedownlist)
# Update persistant iface states # Update persistant iface states
try: try:
if self.ALL: if self.ALL:

View File

@ -11,7 +11,7 @@ import logging
lockfile="/run/network/.lock" lockfile="/run/network/.lock"
logger = None logger = None
def run(args, op): def run_up(args):
logger.debug('args = %s' %str(args)) logger.debug('args = %s' %str(args))
try: try:
@ -19,62 +19,100 @@ def run(args, op):
if len(args.iflist) == 0: if len(args.iflist) == 0:
iflist = None iflist = None
logger.debug('creating ifupdown object ..') logger.debug('creating ifupdown object ..')
if op == 'up' or op == 'down' or op == 'reload': cachearg=(False if (iflist or args.nocache or
cachearg=(False if (iflist or args.nocache or
args.perfmode or args.noact) args.perfmode or args.noact)
else True) else True)
ifupdown_handle = ifupdownMain(force=args.force, ifupdown_handle = ifupdownMain(force=args.force,
withdepends=args.withdepends, withdepends=args.withdepends,
perfmode=args.perfmode, perfmode=args.perfmode,
njobs=args.jobs, njobs=args.jobs,
dryrun=args.noact, dryrun=args.noact,
cache=cachearg) cache=cachearg)
elif op == 'query':
cachearg=(False if (iflist or args.nocache or
args.perfmode or args.syntaxhelp) else True)
ifupdown_handle = ifupdownMain(withdepends=args.withdepends,
perfmode=args.perfmode,
njobs=args.jobs,
cache=cachearg)
logger.debug('calling \'%s\'' %op + ' for all interfaces ..') ifupdown_handle.up(['pre-up', 'up', 'post-up'],
if op == 'up':
ifupdown_handle.up(['pre-up', 'up', 'post-up'],
args.all, args.CLASS, iflist, args.all, args.CLASS, iflist,
excludepats=args.excludepats, excludepats=args.excludepats,
printdependency=args.printdependency) printdependency=args.printdependency)
elif op == 'down': except:
ifupdown_handle.down(['pre-down', 'down', 'post-down'], raise
args.all, args.CLASS, iflist,
excludepats=args.excludepats,
printdependency=args.printdependency)
elif op == 'query':
if args.checkcurr:
qop='query-checkcurr'
elif args.running:
if iflist is None:
iflist = [i for i in os.listdir('/sys/class/net/')
if os.path.isdir('/sys/class/net/%s' %i)]
qop='query-running'
elif args.raw:
qop='query-raw'
elif args.syntaxhelp:
qop = 'query-syntax'
elif args.printdependency:
qop = 'query-dependency'
else:
qop='query'
ifupdown_handle.query([qop], args.all, args.CLASS, iflist, def run_down(args):
excludepats=args.excludepats, logger.debug('args = %s' %str(args))
printdependency=args.printdependency,
format=args.format) try:
elif op == 'reload': iflist = args.iflist
if iflist is not None: if len(args.iflist) == 0:
raise Exception('iflist is currently not supported with reload') iflist = None
ifupdown_handle.reload(args.all, args.CLASS, iflist, logger.debug('creating ifupdown object ..')
excludepats=args.excludepats, cachearg=(False if (iflist or args.nocache or
downchangediface=args.downchangediface) args.perfmode or args.noact)
else True)
ifupdown_handle = ifupdownMain(force=args.force,
withdepends=args.withdepends,
perfmode=args.perfmode,
njobs=args.jobs,
dryrun=args.noact,
cache=cachearg)
ifupdown_handle.down(['pre-down', 'down', 'post-down'],
args.all, args.CLASS, iflist,
excludepats=args.excludepats,
printdependency=args.printdependency)
except:
raise
def run_query(args):
logger.debug('args = %s' %str(args))
try:
iflist = args.iflist
if len(args.iflist) == 0:
iflist = None
logger.debug('creating ifupdown object ..')
cachearg=(False if (iflist or args.nocache or
args.perfmode or args.syntaxhelp) else True)
ifupdown_handle = ifupdownMain(withdepends=args.withdepends,
perfmode=args.perfmode,
njobs=args.jobs,
cache=cachearg)
if args.checkcurr:
qop='query-checkcurr'
elif args.running:
if iflist is None:
iflist = [i for i in os.listdir('/sys/class/net/')
if os.path.isdir('/sys/class/net/%s' %i)]
qop='query-running'
elif args.raw:
qop='query-raw'
elif args.syntaxhelp:
qop = 'query-syntax'
elif args.printdependency:
qop = 'query-dependency'
else:
qop='query'
ifupdown_handle.query([qop], args.all, args.CLASS, iflist,
excludepats=args.excludepats,
printdependency=args.printdependency,
format=args.format)
except:
raise
def run_reload(args):
logger.debug('args = %s' %str(args))
try:
logger.debug('creating ifupdown object ..')
cachearg=(False if (args.nocache or
args.perfmode or args.noact) else True)
ifupdown_handle = ifupdownMain(withdepends=args.withdepends,
perfmode=args.perfmode,
njobs=args.jobs,
cache=cachearg)
ifupdown_handle.reload(args.all, None, None,
excludepats=args.excludepats,
downchangediface=args.downchangediface)
except: except:
raise raise
@ -106,8 +144,8 @@ def update_argparser(argparser):
argparser.add_argument('-a', '--all', action='store_true', required=False, argparser.add_argument('-a', '--all', action='store_true', required=False,
help='process all interfaces marked \"auto\"') help='process all interfaces marked \"auto\"')
argparser.add_argument('iflist', metavar='IFACE', argparser.add_argument('iflist', metavar='IFACE',
nargs='*', help='interface list separated by spaces') nargs='*', help='interface list separated by spaces. ' +
'IFACE list is mutually exclusive with -a option.')
argparser.add_argument('-v', '--verbose', dest='verbose', argparser.add_argument('-v', '--verbose', dest='verbose',
action='store_true', help='verbose') action='store_true', help='verbose')
argparser.add_argument('-d', '--debug', dest='debug', argparser.add_argument('-d', '--debug', dest='debug',
@ -119,7 +157,9 @@ def update_argparser(argparser):
argparser.add_argument('--allow', dest='CLASS', argparser.add_argument('--allow', dest='CLASS',
help='ignore non-\"allow-CLASS\" interfaces') help='ignore non-\"allow-CLASS\" interfaces')
argparser.add_argument('--with-depends', dest='withdepends', argparser.add_argument('--with-depends', dest='withdepends',
action='store_true', help='run with all dependent interfaces') action='store_true', help='run with all dependent interfaces.'+
' This option is redundant when \'-a\' is specified. With ' +
'\'-a\' interfaces are always executed in dependency order')
argparser.add_argument('--perfmode', dest='perfmode', argparser.add_argument('--perfmode', dest='perfmode',
action='store_true', help=argparse.SUPPRESS) action='store_true', help=argparse.SUPPRESS)
argparser.add_argument('-j', '--jobs', dest='jobs', type=int, argparser.add_argument('-j', '--jobs', dest='jobs', type=int,
@ -129,7 +169,7 @@ def update_argparser(argparser):
argparser.add_argument('-X', '--exclude', dest='excludepats', argparser.add_argument('-X', '--exclude', dest='excludepats',
action='append', action='append',
help='Exclude interfaces from the list of interfaces' + help='Exclude interfaces from the list of interfaces' +
' to operate on') ' to operate on. Can be specified multiple times.')
def update_ifupdown_argparser(argparser): def update_ifupdown_argparser(argparser):
""" common arg parser for ifup and ifdown """ """ common arg parser for ifup and ifdown """
@ -175,10 +215,33 @@ def update_ifquery_argparser(argparser):
help='print supported interface config syntax') help='print supported interface config syntax')
def update_ifreload_argparser(argparser): def update_ifreload_argparser(argparser):
update_ifupdown_argparser(argparser) """ parser for ifreload """
argparser.add_argument('--down-changediface', dest='downchangediface', argparser.add_argument('-a', '--all', action='store_true', required=True,
help='process all interfaces marked \"auto\"')
argparser.add_argument('iflist', metavar='IFACE',
nargs='*', help=argparse.SUPPRESS)
argparser.add_argument('-n', '--no-act', dest='noact',
action='store_true', help=argparse.SUPPRESS)
argparser.add_argument('-v', '--verbose', dest='verbose',
action='store_true', help='verbose')
argparser.add_argument('-d', '--debug', dest='debug',
action='store_true', action='store_true',
help='down interfaces that have changed before bringing them up') help='output debug info')
argparser.add_argument('--with-depends', dest='withdepends',
action='store_true', help=argparse.SUPPRESS)
argparser.add_argument('--perfmode', dest='perfmode',
action='store_true', help=argparse.SUPPRESS)
argparser.add_argument('--nocache', dest='nocache', action='store_true',
help=argparse.SUPPRESS)
argparser.add_argument('-X', '--exclude', dest='excludepats',
action='append',
help=argparse.SUPPRESS)
argparser.add_argument('-j', '--jobs', dest='jobs', type=int,
default=-1, choices=range(1,12), help=argparse.SUPPRESS)
argparser.add_argument('--down-changediface', dest='downchangediface',
action='store_true', help='down interfaces whose ' +
'config have changed before bringing them up. By' +
' default all interfaces are brought up')
def parse_args(argsv, op): def parse_args(argsv, op):
if op == 'query': if op == 'query':
@ -186,19 +249,30 @@ def parse_args(argsv, op):
else: else:
descr = 'interface management' descr = 'interface management'
argparser = argparse.ArgumentParser(description=descr) argparser = argparse.ArgumentParser(description=descr)
update_argparser(argparser) if op == 'reload':
if op == 'up':
update_ifup_argparser(argparser)
elif op == 'down':
update_ifdown_argparser(argparser)
elif op == 'query':
update_ifquery_argparser(argparser)
elif op == 'reload':
update_ifreload_argparser(argparser) update_ifreload_argparser(argparser)
else:
update_argparser(argparser)
if op == 'up':
update_ifup_argparser(argparser)
elif op == 'down':
update_ifdown_argparser(argparser)
elif op == 'query':
update_ifquery_argparser(argparser)
elif op == 'reload':
update_ifreload_argparser(argparser)
return argparser.parse_args(argsv) return argparser.parse_args(argsv)
handlers = {'up' : run_up,
'down' : run_down,
'query' : run_query,
'reload' : run_reload }
def main(argv): def main(argv):
""" main function """ """ main function """
args = None
try: try:
op = None op = None
if re.search(r'ifup', argv[0]) != None: if re.search(r'ifup', argv[0]) != None:
@ -215,22 +289,27 @@ def main(argv):
exit(1) exit(1)
# Command line arg parser # Command line arg parser
args = parse_args(argv[1:], op) args = parse_args(argv[1:], op)
if not len(args.iflist) and not args.all and not args.syntaxhelp: if not len(args.iflist) and not args.all:
print '\'-a\' option or interface list are required' if op != 'query' or not args.syntaxhelp:
exit(1) print '\'-a\' option or interface list are required'
exit(1)
if len(args.iflist) and args.all: if len(args.iflist) and args.all:
print '\'-a\' option and interface list are mutually exclusive' print '\'-a\' option and interface list are mutually exclusive'
exit(1) exit(1)
init(args) init(args)
run(args, op) handlers.get(op)(args)
except Exception, e: except Exception, e:
if str(e) == '': if str(e) == '':
exit(1) exit(1)
if args.debug: if args and args.debug:
raise raise
else: else:
logger.error(str(e)) if logger:
if not args.debug: logger.error(str(e))
else:
print str(e)
if args and not args.debug:
print '\nRerun the command with \'-d\' for a detailed errormsg' print '\nRerun the command with \'-d\' for a detailed errormsg'
exit(1) exit(1)
finally: finally: