ftao / python-ifcfg

Python cross-platform network interface discovery (ifconfig/ipconfig/ip)
BSD 3-Clause "New" or "Revised" License
55 stars 37 forks source link

Support all properties (broadcase, netmask etc) for interfaces with multiple bindings #34

Open bendikro opened 6 years ago

bendikro commented 6 years ago

With a physical interface enp11s0, and a virtual interface created with ifconfig enp11s0:0 192.168.0.4, the output from ip addr show looks something like:

2: enp11s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 40:8d:5c:54:d1:91 brd ff:ff:ff:ff:ff:ff
    inet 172.16.0.196/22 brd 172.16.3.255 scope global dynamic noprefixroute enp11s0
       valid_lft 495075sec preferred_lft 495075sec
    inet 192.168.0.4/24 brd 192.168.0.255 scope global enp11s0:0
       valid_lft forever preferred_lft forever

I've removed inet6 output lines as well as localhost

Trying to parse this gives:

Traceback (most recent call last):
  File "/home/bro/programmer/pystuff/python-ifcfg/src/ifcfg/__init__.py", line 57, in get_parser
    return Parser(ifconfig=ifconfig)
  File "/home/bro/programmer/pystuff/python-ifcfg/src/ifcfg/parser.py", line 30, in __init__
    self.parse(self.ifconfig_data)
  File "/home/bro/programmer/pystuff/python-ifcfg/src/ifcfg/parser.py", line 92, in parse
    self._interfaces[cur][k]
RuntimeError: Tried to add broadcast=192.168.0.255 multiple times to enp11s0, it was already: 172.16.3.255
benjaoming commented 6 years ago

Ah yeah, after we added support for multiple IP addresses per interface, we didn't do anything about the remaining interface properties, that are also per IP binding.

benjaoming commented 6 years ago

I think this needs to be in a major release change, since basically we need to adapt the whole API to handle multiple bindings.

jamalex commented 4 years ago

I haven't been able to replicate this. When I ran sudo ifconfig wlp0s20f3:0 192.168.0.4 to create an alias, it ended up showing the alias and the primary interface separately in the output of ifcfg.interfaces(). Has this been resolved, or are additional steps needed to replicate?

...
  'wlp0s20f3': {'inet': '6.5.75.97',
  'inet4': ['6.5.75.97'],
  'ether': '0c:dd:24:37:a0:b8',
  'inet6': ['fe80::87a2:717e:18f:b687'],
  'netmask': '255.255.255.0',
  'device': 'wlp0s20f3',
  'flags': '4163<UP,BROADCAST,RUNNING,MULTICAST> ',
  'mtu': '1500',
  'broadcast': '6.5.75.255'},
 'wlp0s20f3:0': {'inet': '192.168.0.4',
  'inet4': ['192.168.0.4'],
  'ether': '0c:dd:24:37:a0:b8',
  'inet6': [],
  'netmask': '255.255.255.0',
  'device': 'wlp0s20f3:0',
  'flags': '4163<UP,BROADCAST,RUNNING,MULTICAST> ',
  'mtu': '1500',
  'broadcast': '192.168.0.255'}
...
benjaoming commented 4 years ago

@jamalex try on a system without net-tools (the package containing ifconfig). It's on default Unix-based systems for the past ~5 years that ifconfig hasn't been a standard utility.

Red Hat has made a nice cheat sheet for the new commands: https://access.redhat.com/sites/default/files/attachments/rh_ip_command_cheatsheet_1214_jcs_print.pdf