@@ -109,6 +109,12 @@ def __intermediate_interface(self, interface, uci_name):
109109 del interface ['wireless' ]
110110 if 'addresses' in interface :
111111 del interface ['addresses' ]
112+ # specific transformation
113+ type_ = self ._get_uci_name (interface ["type" ])
114+ method = getattr (self , f'_intermediate_{ type_ } ' , None )
115+ if method :
116+ interface = method (interface )
117+ return interface
112118 return interface
113119
114120 _address_keys = ['address' , 'mask' , 'family' , 'gateway' ]
@@ -225,6 +231,10 @@ def __netjson_interface(self, interface):
225231 interface ['mac' ] = interface .pop ('macaddr' )
226232 if interface ['network' ] == self ._get_uci_name (interface ['name' ]):
227233 del interface ['network' ]
234+ # specific transformation
235+ method = getattr (self , f'_netjson_{ interface .get ("proto" )} ' , None )
236+ if method :
237+ interface = method (interface )
228238 return interface
229239
230240 def __netjson_type (self , interface ):
@@ -243,13 +253,17 @@ def __netjson_type(self, interface):
243253 return 'ethernet'
244254
245255 def __netjson_addresses (self , interface ):
246- proto = interface .pop ('proto' , 'none' )
256+ proto = interface .get ('proto' , 'none' )
257+ address_protos = ['static' , 'dhcp' , 'dhcpv6' , 'none' ]
258+ if 'proto' in interface and proto in address_protos :
259+ del interface ['proto' ]
247260 if 'ipaddr' not in interface and 'ip6addr' not in interface and proto == 'none' :
248261 return interface
249- if proto not in [ 'static' , 'dhcp' , 'dhcpv6' , 'none' ] :
250- interface ['proto ' ] = proto
251- interface [ 'type' ] = self .__get_special_interface_type (interface )
262+ if proto not in address_protos :
263+ interface ['type ' ] = 'other'
264+ return self ._add_netjson_addresses (interface , proto )
252265
266+ def _add_netjson_addresses (self , interface , proto ):
253267 addresses = []
254268 ipv4 = interface .pop ('ipaddr' , [])
255269 ipv6 = interface .pop ('ip6addr' , [])
@@ -273,14 +287,9 @@ def __netjson_addresses(self, interface):
273287 interface ['addresses' ] = addresses
274288 return interface
275289
276- def __get_special_interface_type (self , interface ):
277- username = interface .get ('username' , False )
278- password = interface .get ('password' , False )
279-
280- if username and password :
281- return 'dialup'
282-
283- return 'other'
290+ def _netjson_dialup (self , interface ):
291+ interface ['type' ] = 'dialup'
292+ return interface
284293
285294 def __netjson_address (self , address , interface ):
286295 ip = ip_interface (address )
@@ -308,7 +317,7 @@ def __netjson_parse_ip(self, ip, netmask=32):
308317 if ip and netmask :
309318 return '{0}/{1}' .format (ip , netmask )
310319 else :
311- None
320+ return None
312321
313322 def __netjson_dns (self , interface , result ):
314323 key_mapping = {'dns' : 'dns_servers' , 'dns_search' : 'dns_search' }
@@ -320,3 +329,19 @@ def __netjson_dns(self, interface, result):
320329 items = items .split ()
321330 result .setdefault (netjson_key , [])
322331 result [netjson_key ] += items
332+
333+
334+ for proto in [
335+ '3g' ,
336+ '6in4' ,
337+ 'aiccu' ,
338+ 'l2tp' ,
339+ 'ncm' ,
340+ 'ppp' ,
341+ 'pppoa' ,
342+ 'pppoe' ,
343+ 'pptp' ,
344+ 'qmi' ,
345+ 'wwan' ,
346+ ]:
347+ setattr (Interfaces , f'_netjson_{ proto } ' , Interfaces ._netjson_dialup )
0 commit comments