Page MenuHomePhabricator

Create generic abstraction for configuring interfaces e.g. IP address
Closed, ResolvedPublicFEATURE REQUEST

Description

Right now there is no generic way in configuring an interface IP address from within a Python script.

The only occurance right now is in https://github.com/vyos/vyos-1x/blob/current/src/conf_mode/wireguard.py

def add_addr(intf, addr):
  # see https://phabricator.vyos.net/T949
  ret = subprocess.call(['ip a a dev ' + intf + ' ' + addr + ' &>/dev/null'], shell=True)
  sl.syslog(sl.LOG_NOTICE, "ip a a dev " + intf + " " + addr)

def del_addr(intf, addr):
  ret = subprocess.call(['ip a d dev ' + intf + ' ' + addr + ' &>/dev/null'], shell=True)
  sl.syslog(sl.LOG_NOTICE, "ip a d dev " + intf + " " + addr)

We need to make this available in the generic vyos python library or a proper 3rd party library to be reusable from within multiple scripts.

Requirements:

  • add IPv4/IPv6 interface address
  • remove IPv4/IPv6 interface address
  • add DHCP/DHCPv6 interface address
  • remove DHCP/DHCPv6 interface address
  • add interface description /sys/class/net/eth0/ifalias

Details

Difficulty level
Hard (possibly days)
Version
-
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Behavior change

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes

moved get functions into properties, for ifalias, macaddr and mtu to see how it works. If the old get_ function is being used, it prints a message to the console but still works. Will see how well that works.
https://github.com/vyos/vyos-1x/commit/0b9c894fcece6df553a89e42147768ce6efaf372

c-po added a comment.Aug 26 2019, 11:22 AM

pyroute2 has been added to our debian repo http://dev.packages.vyos.net/repositories/current/vyos/pool/main/p/pyroute2/

looks like it does what we need and no own implementation is required

Perfect, I think the dummy interface would be one which needs to be corrected before I can remove the class file entirely.

Dmitry added a subscriber: Dmitry.Aug 26 2019, 6:49 PM
c-po added a comment.Aug 28 2019, 8:53 AM

Pyroute2 states:

One of the major issues with IPDB is its memory footprint. It proved not to be suitable for environments with thousands of routes or neighbours. Being a design issue, it could not be fixed, so a new module was started, NDB, that aims to replace IPDB. IPDB is still more feature rich, but NDB is already more fast and stable.

IPDB is the yet most feature complete interface. NDB (which is only available in recent versions installed through e.g. pip) is only supported for "developers" as it lacks a lot of features and the documentation is not really a helper.

Which way to go? Continue on our own abstraction?

Out own implementation should at least support:

  • a general interface class
    • capable of talking to sysfs for ARP manipulation stuff
    • add interface addresses, dhcp and dhcpv6
    • pass options to dhcp client
    • create vif-s and vif interfaces
    • support transactions (less system I/O and configuration changes)
  • a derived bridge class from the generic interface class
    • to add/delete bridges
    • add/remove bridge members
    • change bridge port stp values
    • configure bridge parameters
  • a derived bond class from the generic interface class
    • to add/delete bonds
    • add remove bond members
    • change bond modes/hash
c-po added a comment.Aug 28 2019, 9:00 AM

@hagbard during some tests with the bridge interface (https://github.com/vyos/vyos-1x/commit/71f7a947539963112c61fef2a5f278d524d71198) I noticed the following:

  • Interface.add_dhcpv4() works (I would call it dhcp anyway as this is the standard)
  • Interface.del_dhcpv4() does not remove the dhclient process
  • Interface.add_dhcpv6() does not spawn a new dhclientv6 process.

I tend to not spawn processes by hand as you do I rather use start-stop-daemon for it and also for removal see:

c-po added a comment.Aug 31 2019, 11:14 AM

DHCP + DHCPv6 working now in bridge interface.

c-po claimed this task.Aug 31 2019, 11:14 AM
c-po raised the priority of this task from Normal to High.
c-po set Is it a breaking change? to Behavior change.

@c-po sorry was camping in a remote area without cell coverage. What's the way we go then? I'll look tomorrow, eventually Tuesday next week into the dhcp stuff.

c-po added a comment.Sep 1 2019, 8:03 AM

@hagbard not a problem. Looks like we now go the "our own lib" way as pyroute2 has some flaws. DHCP is already fix and I continue improve the script and remove redundant code before it will be extended to support VLAN/bonding.

c-po closed this task as Resolved.Sep 4 2019, 2:39 PM
c-po moved this task from Need Triage to Finished on the VyOS 1.3 Equuleus board.Sun, Oct 13, 3:08 PM