-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Virtual Router Implementation (#129)
This is the implementation of virtual routers using Linux network namespaces, iptables, Linux bridges and veth interfaces. Signed-off-by: gabrik <gabriele.baldoni@gmail.com>
- Loading branch information
Showing
13 changed files
with
1,028 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (c) 2014,2018 ADLINK Technology Inc. | ||
# | ||
# See the NOTICE file(s) distributed with this work for additional | ||
# information regarding copyright ownership. | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Eclipse Public License 2.0 which is available at | ||
# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
# which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
# | ||
# Contributors: Gabriele Baldoni, ADLINK Technology Inc. - LinuxBridge plugin | ||
|
||
import sys | ||
import netifaces | ||
import socket | ||
|
||
|
||
def get_net_size(netmask): | ||
binary_str = '' | ||
for octet in netmask: | ||
binary_str += bin(int(octet))[2:].zfill(8) | ||
return str(len(binary_str.rstrip('0'))) | ||
|
||
def ip_mask_to_cird(ip, mask): | ||
|
||
try: | ||
socket.inet_aton(ip) | ||
socket.inet_aton(mask) | ||
except: | ||
return "0.0.0.0/0" | ||
|
||
ip = ip.split('.') | ||
mask = mask.split('.') | ||
net_start = [str(int(ip[x])) for x in range(0, 4)] | ||
return '.'.join(net_start) + '/' + get_net_size(mask) | ||
|
||
def main(face): | ||
try: | ||
addr = netifaces.ifaddresses(face)[2][0]['addr'] | ||
mask = netifaces.ifaddresses(face)[2][0]['netmask'] | ||
addr = ip_mask_to_cird(addr, mask) | ||
|
||
except: | ||
addr = '0.0.0.0/0' | ||
print(addr) | ||
|
||
|
||
if __name__ == '__main__': | ||
main(sys.argv[1]) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.