def delete(self, socket=None): """Attempt to delete this link in the kernel""" if not socket: socket = netlink.lookup_socket(netlink.NETLINK_ROUTE) ret = capi.rtnl_link_delete(socket._sock, self._rtnl_link) if ret < 0: raise netlink.KernelError(ret)
def add(self, socket=None, flags=None): if not socket: socket = netlink.lookup_socket(netlink.NETLINK_ROUTE) if not flags: flags = netlink.NLM_F_CREATE ret = capi.rtnl_link_add(socket._sock, self._rtnl_link, flags) if ret < 0: raise netlink.KernelError(ret)
def add(self, socket=None, flags=None): if not socket: socket = netlink.lookup_socket(netlink.NETLINK_ROUTE) if not flags: flags = netlink.NLM_F_CREATE ret = capi.rtnl_addr_add(socket._sock, self._rtnl_addr, flags) if ret < 0: raise netlink.KernelError(ret)
def change(self, socket=None, flags=0): """Commit changes made to the link object""" if not socket: socket = netlink.lookup_socket(netlink.NETLINK_ROUTE) if not self._orig: raise NetlinkError("Original link not available") ret = capi.rtnl_link_change(socket._sock, self._orig, self._rtnl_link, flags) if ret < 0: raise netlink.KernelError(ret)
def delEntry(self, route,sock=None): if not sock: sock = netlink.lookup_socket( netlink.NETLINK_ROUTE) ret = capir.rtnl_route_delete(self._sock._sock, route._nl_route, 0) if ret < 0: raise netlink.NetlinkError(ret) return ret
def delEntry(self, route, sock=None): if not sock: sock = netlink.lookup_socket(netlink.NETLINK_ROUTE) ret = capir.rtnl_route_delete(self._sock._sock, route._nl_route, 0) if ret < 0: raise netlink.NetlinkError(ret) return ret
def get(name, socket=None): """Lookup Link object directly from kernel""" if not name: raise ValueError() if not socket: socket = netlink.lookup_socket(netlink.NETLINK_ROUTE) link = capi.get_from_kernel(socket._sock, 0, name) if not link: return None return Link.from_capi(link)
def add( self, route, sock=None ): if not isinstance(route,RoutingEntry): raise ValueError("Wrong argument. Expecting RoutingEntry") if not sock: sock = netlink.lookup_socket( netlink.NETLINK_ROUTE) print ("Setting table to %d"%self._tableId) capir.rtnl_route_set_table( route._nl_route, self._tableId ) # Set table ret = capir.rtnl_route_add(sock._sock, route._nl_route, 0) print("Ret value %d"%ret ) if ret < 0: raise nl.NetlinkError(ret)
def add(self, route, sock=None): if not isinstance(route, RoutingEntry): raise ValueError("Wrong argument. Expecting RoutingEntry") if not sock: sock = netlink.lookup_socket(netlink.NETLINK_ROUTE) print("Setting table to %d" % self._tableId) capir.rtnl_route_set_table(route._nl_route, self._tableId) # Set table ret = capir.rtnl_route_add(sock._sock, route._nl_route, 0) print("Ret value %d" % ret) if ret < 0: raise nl.NetlinkError(ret)
import netlink.core as netlink import netlink.route.capi as capi import netlink.route.link as link sock = netlink.lookup_socket(netlink.NETLINK_ROUTE) cache = link.LinkCache() cache.refill(sock) testtap1 = cache['testtap1'] print testtap1 lbr = link.Link() lbr.type = 'bridge' lbr.name = 'testbridge' print lbr lbr.add() cache.refill(sock) lbr = cache['testbridge'] print lbr lbr.enslave(testtap1) cache.refill(sock) testtap1 = cache['testtap1'] print capi.rtnl_link_is_bridge(lbr._rtnl_link) print capi.rtnl_link_get_master(testtap1._rtnl_link)