Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added vlan and bridge management #54

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ Goal of this utility is to provide compatible CLI with [iproute2](http://www.pol
* Set **Random MAC** address `ip link set en0 address random`
* Set **Factory default MAC** address `ip link set en0 address factory`
* Set MTU `ip link set dev en0 mtu 9000`
* Create VLAN inteface `ip link add link en0 name vlan111 type vlan id 111` (vlan interfaces must be named `vlan<n>`)
* Create a bridge interface `ip link add name bridge1 type bridge` (bridge interfaces must be named `bridge<n>`)
* Add an interface to a bridge `ip link set dev en2 master bridge1`
* Remove an interface from a bridge `ip link set dev en2 nomaster`
* Remove any virtual interface `ip link del vlan111`
* Neighbour module (ARP/NDP)
* Show all neighbours `ip neigh`
* Show all IPv4 (ARP) neighbours `ip -4 neigh`
Expand Down Expand Up @@ -95,6 +100,7 @@ Goal of this utility is to provide compatible CLI with [iproute2](http://www.pol
**v1.5.0**
* Added `-json` option (Issue #49)
* Added `bridge` command
* Added vlan management
* Internal reworking of `ip ... show` functions

**v1.4.2**
Expand Down
39 changes: 19 additions & 20 deletions src/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,15 @@ def randomMAC():


# Decode ifconfig output
def parse_ifconfig(res):
def parse_ifconfig():
status, res = subprocess.getstatusoutput(
IFCONFIG + " -v -a 2>/dev/null"
)
if status: # unix status
if res != "":
perror(res)
return None

links = []
count = 1

Expand Down Expand Up @@ -224,28 +232,19 @@ def do_link(argv, json_print, pretty_json):


def do_link_show(argv, json_print, pretty_json):
if len(argv) > 1:
if argv[0] != "dev":
return False
else:
argv.pop(0)
if len(argv) > 0:
dev = argv[0]
else:
dev = None

status, res = subprocess.getstatusoutput(
IFCONFIG + " -v -a 2>/dev/null"
)
if status: # unix status
if res == "":
perror(param + " not found")
else:
perror(res)
links = parse_ifconfig()
if links is None:
return False

dev = None
bridges = []
links = parse_ifconfig(res)

if len(argv) > 0 and argv[0] == "dev":
argv.pop(0)
if len(argv) > 0:
dev = argv[0]
if [l for l in links if l["ifname"] == dev] == []:
perror("Cannot find device \"{}\"".format(dev))

for master in [l for l in links if "bridge" in l]:
for slave in master["bridge"].get("members",[]):
Expand Down
Loading