Allow the flags to be specified in remove_xdp()
authorGary Lin <glin@suse.com>
Fri, 18 Aug 2017 09:42:08 +0000 (17:42 +0800)
committerBrenden Blanco <bblanco@gmail.com>
Tue, 22 Aug 2017 18:37:30 +0000 (11:37 -0700)
When detaching a generic XDP program to an interface without native XDP
support, remove_xdp() showed the following message:

   bpf: nlmsg error Operation not supported

Add the flags parameter to notify the kernel that it's a generic XDP
program.

examples/networking/xdp/xdp_drop_count.py
src/python/bcc/__init__.py

index 0a5c740..ff0af0f 100755 (executable)
@@ -160,7 +160,7 @@ while 1:
         break;
 
 if mode == BPF.XDP:
-    b.remove_xdp(device)
+    b.remove_xdp(device, flags)
 else:
     ip.tc("del", "clsact", idx)
     ipdb.release()
index 5488f52..dcfa83f 100644 (file)
@@ -591,12 +591,12 @@ class BPF(object):
                             % (dev, errstr))
 
     @staticmethod
-    def remove_xdp(dev):
+    def remove_xdp(dev, flags=0):
         '''
             This function removes any BPF function from a device on the
             device driver level (XDP)
         '''
-        res = lib.bpf_attach_xdp(dev.encode("ascii"), -1, 0)
+        res = lib.bpf_attach_xdp(dev.encode("ascii"), -1, flags)
         if res < 0:
             errstr = os.strerror(ct.get_errno())
             raise Exception("Failed to detach BPF from device %s: %s"