]>
git.proxmox.com Git - mirror_ifupdown2.git/blob - ifupdown2/addons/tunnel.py
9ea3ea4d38a8255d1c412676b71a5e51a12add1d
3 # Maximilian Wilhelm <max@rfc2324.org>
4 # -- Mon 10 Oct 2016 10:53:13 PM CEST
7 from ifupdown
.iface
import *
8 from ifupdownaddons
.modulebase
import moduleBase
9 from ifupdownaddons
.iproute2
import iproute2
10 import ifupdown
.ifupdownflags
as ifupdownflags
14 # TODO: Add checks for ipip tunnels.
16 class tunnel (moduleBase
):
17 _modinfo
= { 'mhelp' : 'create/configure GRE/IPIP/SIT tunnel interfaces',
20 { 'help' : 'type of tunnel as in \'ip link\' command.',
21 'validvals' : ['gre', 'ipip', 'sit'],
23 'example' : ['mode gre']},
25 { 'help' : 'IP of local tunnel endpoint',
26 'validvals' : ['<ipv4>', '<ipv6>'],
28 'example' : ['local 192.2.0.42']},
30 { 'help' : 'IP of remote tunnel endpoint',
31 'validvals' : ['<ipv4>', '<ipv6>'],
33 'example' : ['endpoint 192.2.0.23']},
35 { 'help' : 'TTL for tunnel packets',
36 'validvals' : ['<number>'],
38 'example' : ['ttl 64']},
40 { 'help' : 'Physical underlay device to use for tunnel packets',
41 'validvals' : ['<interface>'],
43 'example' : ['tunnel-physdev eth1']},
48 def __init__ (self
, *args
, **kargs
):
49 moduleBase
.__init
__ (self
, *args
, **kargs
)
53 def _is_my_interface (self
, ifaceobj
):
54 if ifaceobj
.addr_method
== "tunnel" and ifaceobj
.get_attr_value_first ('mode'):
59 def _up (self
, ifaceobj
):
61 # attr_name -> ip route param name
63 'endpoint' : 'remote',
65 'tunnel-physdev' : 'dev',
68 mode
= ifaceobj
.get_attr_value_first ('mode')
71 # Only include attributes which have been set and map ifupdown2 names
72 # to attribute names expected by iproute
73 for attr
, iproute_attr
in attr_map
.items ():
74 attr_val
= ifaceobj
.get_attr_value_first (attr
)
76 attrs
[iproute_attr
] = attr_val
78 self
.ipcmd
.link_create (ifaceobj
.name
, mode
, attrs
)
81 def _down (self
, ifaceobj
):
82 if not ifupdownflags
.flags
.PERFMODE
and not self
.ipcmd
.link_exists (ifaceobj
.name
):
85 self
.ipcmd
.link_delete (ifaceobj
.name
)
87 self
.log_warn (str (e
))
90 def _query_check_n_update (self
, ifaceobj
, ifaceobjcurr
, attrname
, attrval
,
92 if not ifaceobj
.get_attr_value_first (attrname
):
95 if running_attrval
and attrval
== running_attrval
:
96 ifaceobjcurr
.update_config_with_status (attrname
, attrval
, 0)
98 ifaceobjcurr
.update_config_with_status (attrname
, running_attrval
, 1)
101 def _query_check (self
, ifaceobj
, ifaceobjcurr
):
102 if not self
.ipcmd
.link_exists (ifaceobj
.name
):
105 tunattrs
= self
.ipcmd
.link_get_linkinfo_attrs (ifaceobj
.name
)
107 ifaceobjcurr
.check_n_update_config_with_status_many (ifaceobj
, self
.get_mod_attrs (), -1)
110 for attr
in self
.get_mod_attrs ():
111 if not ifaceobj
.get_attr_value_first (attr
):
114 # Validate all interface attributes set in the config.
115 # Remote any leading 'tunnel-' prefix in front of the attr name
116 # when accessing tunattrs parsed from 'ip -d link'.
117 self
._query
_check
_n
_update
(ifaceobj
, ifaceobjcurr
, attr
,
118 ifaceobj
.get_attr_value_first (attr
),
119 tunattrs
.get (attr
.replace ("tunnel-", "")))
122 # Operations supported by this addon (yet).
126 'query-checkcurr' : _query_check
131 return self
._run
_ops
.keys()
134 def _init_command_handlers (self
):
136 self
.ipcmd
= iproute2 ()
139 def run (self
, ifaceobj
, operation
, query_ifaceobj
= None, **extra_args
):
140 op_handler
= self
._run
_ops
.get (operation
)
144 if operation
!= 'query-running' and not self
._is
_my
_interface
(ifaceobj
):
147 self
._init
_command
_handlers
()
148 if operation
== 'query-checkcurr':
149 op_handler (self
, ifaceobj
, query_ifaceobj
)
151 op_handler (self
, ifaceobj
)