示例#1
0
	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)
示例#2
0
文件: link.py 项目: xxxGARUxxx/libnl
    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)
示例#3
0
文件: link.py 项目: xxxGARUxxx/libnl
    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)
示例#4
0
	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)
示例#5
0
	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)
示例#6
0
文件: route.py 项目: teto/libnl_old
    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 
示例#7
0
    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
示例#8
0
文件: link.py 项目: xxxGARUxxx/libnl
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)
示例#9
0
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)
示例#10
0
文件: route.py 项目: teto/libnl_old
    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)
示例#11
0
    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)
示例#12
0
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)