Commit graph

825 commits

Author SHA1 Message Date
Cong Wang
678753ba84 factor out rtnl_link_info_parse()
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-11-06 09:55:04 +01:00
Cong Wang
760bfabad8 add link netns support
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-11-06 09:55:03 +01:00
Cong Wang
4263106728 add veth link support
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-11-06 09:55:02 +01:00
Cong Wang
1f3511c1d1 factor out rtnl_link_fill_info()
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-11-06 09:55:01 +01:00
Cong Wang
43e9438d9a add ingress qdisc
This patch adds ingress qdisc to libnl.

Cc: Thomas Graf <tgraf@suug.ch>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-31 00:28:04 +01:00
Thomas Graf
60ceeef964 3.2.23 release 2013-10-31 00:11:18 +01:00
Cong Wang
ac344b9b6a tests: fix make test-create-vxlan
Cc: Thomas Graf <tgraf@suug.ch>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-31 00:02:03 +01:00
Thomas Graf
f44b82fa13 libnl-3.2.23-rc2 release
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-23 11:06:50 +02:00
Thomas Graf
71ad234b48 include: Provide <netlink/route/link/vxlan.h> in distribution
Reported-by: Jeroen Roovers <jer@gentoo.org>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-23 09:32:12 +02:00
Thomas Graf
7f066d0049 Fix up -rc1 versioning to not be included in libnl_micro_version
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-22 16:45:21 +02:00
Thomas Graf
3151eda89a doc: Add instructions on how to build docs
Reported-by: Teto <mattator@gmail.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-22 16:33:27 +02:00
Thomas Graf
72bf363654 doxygen-link: Be python3 compatible
Reported-by: Teto <mattator@gmail.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-22 16:32:23 +02:00
Thomas Graf
74db300236 libnl-3.2.23-rc1 release 2013-10-22 15:26:12 +02:00
Thomas Haller
549010c52a rtnl-addr: set ifa_flags when creating/updating address
Set the address flags when creating/updating an address with
rtnl_addr_add/rtnl_addr_build_add_request. Before, the flags
were not passed on.

As of now, the flags except IFA_F_NODAD|IFA_F_HOMEADDRESS are ignored by
the kernel. Still pass them on without filtering.

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-22 14:24:56 +02:00
Thomas Graf
d976e2e62b obj: Check for NULL pointer in nl_object_clone()
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-22 14:20:41 +02:00
Nicolas PLANEL
978bb85c7a python: add bridge flags API
Add flags set/get methods aim to change bridge flags :
 o hairpin_mode
 o bpdu_guard
 o root_block
 o fast_leave

Signed-off-by: Nicolas PLANEL <nicolas.planel@enovance.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-22 14:20:41 +02:00
Nicolas PLANEL
07669b0b80 test: add python bridge testing sample
New test sample file, test-create-bridge.py
Create an bridge (testbrige) and attach an already setup interface (testtap1) to it.

Signed-off-by: Nicolas PLANEL <nicolas.planel@enovance.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-22 14:20:41 +02:00
Nicolas PLANEL
defebe30c6 python: add basic netlink protocol bridge interface support
Implements basic bridge interface support using netlink protocol

Signed-off-by: Nicolas PLANEL <nicolas.planel@enovance.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-22 14:20:41 +02:00
Nicolas PLANEL
cb034e12a4 test: add bridge creation sample
New test sample file, test-create-bridge.c
Create an bridge (testbrige) and attach an already setup interface (testtap1) to it.

Signed-off-by: Nicolas PLANEL <nicolas.planel@enovance.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-22 14:20:41 +02:00
Nicolas PLANEL
fdd1ba220d route/link: fixup link->l_af_ops must be set for some kind of links
Lookup on IFLA_INFO_KIND information to setup the right link->l_af_ops callbacks
For example, if you setup a bridge this is avoid to trig IS_BRIDGE_LINK_ASSERT() on rtnl_link_bridge_get_flags() call.

    line=<optimized out>, function=<optimized out>) at assert.c:94
    0x7ffff5dc39a0 "rtnl_link_bridge_get_flags") at assert.c:103

Signed-off-by: Nicolas PLANEL <nicolas.planel@enovance.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-22 14:20:41 +02:00
Julien BERNARD
27019c5671 nl-link-set: Add --state option
I modified the nl-link-set.c file to be able to set the interface up or
down. I joined the patch.
With the new nl-link-set binary I can set the tap interface down.
I am working with Ubuntu 12.04 LTS 64bits and the libnl and libnl-route
packages built from libnl3-3.2.3 from ubuntu reprositories.

--
Julien BERNARD

Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-22 14:20:41 +02:00
Thomas Graf
20ab3bfa78 Merge branch 'recvmsgs-comment-typo' of git://github.com/olafhering/libnl into olafhering-recvmsgs-comment-typo 2013-10-07 11:40:13 +02:00
Teto
a4e588d04a Fixed ObjIterator for python3, fixed output of _color and added missing parameter to nl_cache_resync
Here are a few things I fixed and that provoked a  python error.

I canno't answer to this thread but one solution I found while using
the python binding is to iterate over all and filter via python
http://list-archives.org/2013/09/09/libnl-lists-infradead-org/missing-feature-for-retrieving-cached-
address-objects/f/5031600704

Example:
cache = nlrta.AddressCache()
cache.resync()

for i in cache:
    print ("item", i ) # then you can filter here

Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-07 09:52:08 +02:00
Nicolas PLANEL
f2e6f502eb python: fixup VLANLink() initialization
The varialble name should be link._rtnl_link
instead of link._link to get rid of the AttributeError.

Traceback (most recent call last):
File "examples/test.py", line 11, in <module>
 eth0 = link.resolve('eth0.800')
...
File
"/home/ubuntu/libnl/python/build/lib.linux-x86_64-2.7/netlink/route/link.py",
line 151, in __init__
 self._module_lookup('netlink.route.links.' + self.type)
...
File
"/home/ubuntu/libnl/python/build/lib.linux-x86_64-2.7/netlink/route/links/vlan.py",
line 70, in init
 link.vlan = VLANLink(link._link)
AttributeError: 'Link' object has no attribute '_link'

Signed-off-by: Nicolas PLANEL <nicolas.planel@enovance.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-07 09:50:11 +02:00
Arend van Spriel
ae7f8cc988 python: remove use of PyArg_ParseTuple() for callback result
The message receive callback handler in the netlink api processes
the result object from the python callback. It used PyArg_ParseTuple()
to get the value, but this does not work as intended (see ref [1]).
Instead check the type and convert it accordingly.

refs:
[1] http://stackoverflow.com/questions/13636711/what-is-the-proper-usage-of-pyarg-parsetuple

Reported-by: Teto <mattator@gmail.com>
Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-10-07 09:45:56 +02:00
Olaf Hering
1daa48c48d nl: Fix comment typo on recvmsgs
Signed-off-by: Olaf Hering <olaf@aepfle.de>
2013-10-01 18:23:54 +02:00
Arend van Spriel
b9284bcded python: add send and receive functions to Socket class
Adding class methods send_auto_complete() and recvmsgs()
that call their swig capi equivalent function.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-09-05 17:46:00 +02:00
Arend van Spriel
6726895133 python: fix typo in Socket::__str__() function
The property name used in __str__ should be local_port
instead of localPort to get rid of the AttributeError.

>>> str(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../netlink/core.py", line 172, in __str__
    return 'nlsock<{0}>'.format(self.localPort)
AttributeError: 'Socket' object has no attribute 'localPort'

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-09-05 17:46:00 +02:00
Arend van Spriel
fa23414013 python: remove unnecessary callback type definitions
Copied the typedefs when adding callback support, but they serve
no actual use in the swig input file.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-09-05 17:46:00 +02:00
Arend van Spriel
522cf98fc2 python: allow callback function to be a class method
The callback functionality only worked for regular Python
functions. With this patch it also allows the callback
to be a class method (bounded or unbounded) as show in
example below.

class test_class(object):
	def my_callback(self, msg, arg):
		print('handling %s' % str(msg))

s = netlink.core.Socket()
testobj = test_class()
netlink.capi.py_nl_cb_set(cb, netlink.capi.NL_CB_VALID,
			  netlink.capi.NL_CB_CUSTOM,
			  test_class.my_callback, testobj)
netlink.capi.py_nl_cb_err(cb, netlink.capi.NL_CB_CUSTOM,
                          test_class.my_callback, s)

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-09-05 17:46:00 +02:00
Arend van Spriel
2d55872fb1 use Callback object constructing Socket
Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-09-05 17:46:00 +02:00
Arend van Spriel
86207d47ab python: rework netlink callback handling
The initial commit adding netlink callback handling also introduced
memory leak issue. The python callback info was stored in an allocated
structure, but that was never freed.

Only exposing nl_cb_alloc() as is. nl_cb_get() is removed as it is
not very useful to use reference counting mechanism. Python uses
that itself internally. To deal properly with Python callback info
the function nl_cb_put() and nl_cb_clone() have a custom wrapper
taking care of Python reference counting.

This commit also adds a Callback python class using the netlink
callback functions.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-09-05 17:46:00 +02:00
Arend van Spriel
934626903c nl_cb: store nl_cb_type in struct nl_cb
The application could use the same handler for multiple
nl_cb_type events. This patch stores the nl_cb_type in
the nl_cb struct during the callback. This allows the
application to obtain that information using the new
nl_cb_active_type() function. This way the callback
signature remains as is so existing applications are
not affected.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-09-05 17:46:00 +02:00
Arend van Spriel
9828326c7f add python examples using swig provided api
using the nl80211 family to show use of generic netlink api and
attribute parsing.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-09-05 17:46:00 +02:00
Holger Eitzenberger
db08ef44af netfilter/ct: support optional CTA_ZONE attribute
Newer kernels support conntrack zones, which help to partition the
conntrack table into virtual conntrack tables.

This patch is for adding support for the optional attribute, adds
setters and getters, and adds support for the zone ID in the conntrack
dumper.

An example entry in NL_DUMP_LINE format looks like:

  tcp SYN_SENT 10.128.128.99:43354 <-> 10.128.129.20:22 zone 1

Signed-off-by: Holger Eitzenberger <holger@eitzenberger.org>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-09-05 17:39:03 +02:00
Holger Eitzenberger
56d2bbe173 netfilter/ct: support optional CTA_TIMESTAMP attribute
Recent kernels support conntrack time stamping, which is a helpful
feature to determine the duration of a flow without building a flow
cache in your user space application, just to keep the 'start' time of
your flow.

Timestamps are recorded with nanosecond resolution once this feature
is enabled.

This patch adds optional support for the CTA_TIMESTAMP, then
modifies the dump routine to write that info in a format similar
to /proc/net/nf_conntrack.  This is an example output when using
NL_DUMP_LINE:

  udp 10.128.128.28:56836 <-> 10.128.129.255:8612 delta-time 30

Signed-off-by: Holger Eitzenberger <holger@eitzenberger.org>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-09-05 17:38:59 +02:00
chantra
8a4f16b5bf Call to_msg_fill_raw when defined to_msg_fill is NULL
netem qdisc uses to_msg_fill_raw to build netlink packet. So far, this
was not called from anywhere.

Example creating a netem qdisc before and after the change:

[root@testbox libnl]# NLCB=debug ./netem
-- Debug: Sent Message:
--------------------------   BEGIN NETLINK MESSAGE ---------------------------
  [NETLINK HEADER] 16 octets
    .nlmsg_len = 48
    .type = 36 <route/qdisc::new>
    .flags = 1029 <REQUEST,ACK,ATOMIC>
    .seq = 1376894544
    .port = 17877
  [PAYLOAD] 20 octets
    00 00 00 00 02 00 00 00 00 00 01 80 01 00 01 00 ................
    00 00 00 00                                     ....
  [ATTR 01] 6 octets
    6e 65 74 65 6d 00                               netem.
  [PADDING] 2 octets
    00 00                                           ..
---------------------------  END NETLINK MESSAGE ---------------------------
-- Debug: Received Message:
--------------------------   BEGIN NETLINK MESSAGE ---------------------------
  [NETLINK HEADER] 16 octets
    .nlmsg_len = 68
    .type = 2 <ERROR>
    .flags = 0 <>
    .seq = 1376894544
    .port = 17877
  [ERRORMSG] 20 octets
    .error = -22 "Invalid argument"
  [ORIGINAL MESSAGE] 16 octets
    .nlmsg_len = 16
    .type = 36 <0x24>
    .flags = 1029 <REQUEST,ACK,ATOMIC>
    .seq = 1376894544
    .port = 17877
---------------------------  END NETLINK MESSAGE ---------------------------
-- Error received: Invalid argument
-- Original message: type=0x24 length=48 flags=<REQUEST,ACK,ATOMIC>
sequence-nr=1376894544 pid=17877
RC -7
[root@testbox libnl]# NLCB=debug ./netem
-- Debug: Sent Message:
--------------------------   BEGIN NETLINK MESSAGE ---------------------------
  [NETLINK HEADER] 16 octets
    .nlmsg_len = 76
    .type = 36 <route/qdisc::new>
    .flags = 1029 <REQUEST,ACK,ATOMIC>
    .seq = 1376895147
    .port = 26541
  [PAYLOAD] 20 octets
    00 00 00 00 02 00 00 00 00 00 01 80 01 00 01 00 ................
    00 00 00 00                                     ....
  [ATTR 01] 6 octets
    6e 65 74 65 6d 00                               netem.
  [PADDING] 2 octets
    00 00                                           ..
  [ATTR 02] 24 octets
    00 00 00 00 a0 86 01 00 00 00 00 80 00 00 00 00 ................
    00 00 00 00 00 00 00 00                         ........
---------------------------  END NETLINK MESSAGE ---------------------------
-- Debug: Received Message:
--------------------------   BEGIN NETLINK MESSAGE ---------------------------
  [NETLINK HEADER] 16 octets
    .nlmsg_len = 36
    .type = 2 <ERROR>
    .flags = 0 <>
    .seq = 1376895147
    .port = 26541
  [ERRORMSG] 20 octets
    .error = 0 "Success"
  [ORIGINAL MESSAGE] 16 octets
    .nlmsg_len = 16
    .type = 36 <0x24>
    .flags = 1029 <REQUEST,ACK,ATOMIC>
    .seq = 1376895147
    .port = 26541
---------------------------  END NETLINK MESSAGE  ---------------------------
RC 0
[root@testbox libnl]# tc qdisc show
qdisc htb 1: dev eth0 root refcnt 2 r2q 10 default 0 direct_packets_stat 21115
qdisc netem 8001: dev eth0 parent 1:1 limit 100000 loss 50%
qdisc htb 1: dev eth1 root refcnt 2 r2q 10 default 0 direct_packets_stat 0

Signed-off-by: chantra <chantra@fb.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-08-26 10:11:12 +02:00
maksqwe
c31467e0a4 Priority of the '<' operator is higher than that of the '=' operator
Signed-off-by: maksqwe <maksqwe1@ukr.net>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-08-26 10:06:30 +02:00
Jiri Pirko
6f37b439af fix double free caused by freeing link af_data in rtnl_link_set_family()
Introduced by commit 8026fe2e3a ("link:
Free and realloc af specific data upon rtnl_link_set_family()")

link->l_af_data[link->l_af_ops->ao_family] is freed here but not set to
zero. That leads to double free made by link_free_data->do_foreach_af.

Fix this by setting link->l_af_data[link->l_af_ops->ao_family] to zero
rigth after free.

Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-08-21 14:46:42 +02:00
Thomas Graf
0eb665c693 Enable linker versioning
Reported-by: Ian Stakenvicius
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-08-07 14:51:03 +02:00
Thomas Graf
8443c7e9f1 Merge pull request #44 from sassanosystems/idiag
Idiag
2013-08-04 23:10:42 -07:00
Jiri Pirko
57f1d9f03a link: add support for IFLA_PHYS_PORT_ID
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-08-05 08:08:55 +02:00
Thomas Graf
f0b1a4e66b Merge pull request #45 from chibacchie/vxlan
Add VXLAN support
2013-08-04 23:06:19 -07:00
Yasunobu Chiba
162c906bf2 Add VXLAN support. 2013-08-04 15:43:54 +09:00
Joe Damato
2ef91dac26 More safely parse vegas info and mem info. 2013-07-25 17:59:56 -07:00
Joe Damato
c97c8c2bfd Add idiag-socket-details
This small program lists all sockets on the system seen by netlink and serves
as a simple example showing how to alloc an idiag msg cache and dump the
objects in it.
2013-07-25 16:36:16 -07:00
Joe Damato
b3fb89f445 Handle the case where nl_msec2str is passed 0 msecs 2013-07-19 02:06:27 -07:00
Joe Damato
81d2b1d509 Add support for inet diag Netlink protocol.
- Inet diag allows users to gather low-level socket information.
- This library provides a higher-level API for creating inetdiag requests (via
  idiagnl_connect and idiagnl_send_simple) and parsing the replies (via
  idiagnl_msg_parse). A cache is also provided (via idiagnl_msg_alloc_cache).
- Request and message objects provide APIs for accessing and setting the
  various properties of each.
- This library also allows the user to parse the inetdiag response attributes
  which contain information about traffic class, TOS, congestion, socket
  memory info, and more depending on the kernel version used.
- Includes doxygen documentation.
2013-07-19 02:06:21 -07:00
Arend van Spriel
89b00119f2 add generic netlink functions to swig
Provide wrapper function for generic netlink library functions. The
genlmsg_parse() function is handled similar to nla_parse_nested() so
it returns tuple with error code and dictionary of parsed attributes.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-07-18 23:22:18 +02:00
Arend van Spriel
7dc033f5cc add python module for generic netlink library
This commit adds creation of the netlink.genl package. The actual
capi.i will be filled in upcoming commits so the module is rather
dumb for now.

Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
2013-07-18 23:22:18 +02:00