├── m4 └── .gitignore ├── doc ├── api │ └── .gitignore ├── AUTHORS ├── stylesheets │ ├── flask-manpage.css │ ├── volnitsky-manpage.css │ ├── asciidoc-manpage.css │ ├── toc2.css │ └── xhtml11-quirks.css ├── autogen.sh ├── images │ ├── tc_obj.png │ ├── icons │ │ ├── tip.png │ │ ├── up.png │ │ ├── home.png │ │ ├── next.png │ │ ├── note.png │ │ ├── prev.png │ │ ├── caution.png │ │ ├── example.png │ │ ├── warning.png │ │ ├── callouts │ │ │ ├── 1.png │ │ │ ├── 2.png │ │ │ ├── 3.png │ │ │ ├── 4.png │ │ │ ├── 5.png │ │ │ ├── 6.png │ │ │ ├── 7.png │ │ │ ├── 8.png │ │ │ ├── 9.png │ │ │ ├── 10.png │ │ │ ├── 11.png │ │ │ ├── 12.png │ │ │ ├── 13.png │ │ │ ├── 14.png │ │ │ └── 15.png │ │ ├── important.png │ │ └── README │ ├── ifinfomsg.png │ ├── nlmsgerr.png │ ├── nlmsghdr.png │ ├── qdisc_mq.png │ ├── addressing.png │ ├── tc_overview.png │ ├── attribute_hdr.png │ ├── classful_qdisc.png │ ├── qdisc_default.png │ ├── classless_qdisc.png │ ├── library_overview.png │ └── classless_qdisc_nbands.png ├── README ├── gen-tags.sh ├── resolve-asciidoc-refs.py ├── index.txt ├── doxygen-link.py ├── src │ ├── hidden.c │ └── toc.c └── Makefile.am ├── python ├── lib │ ├── __init__.py │ └── generated │ │ └── __init__.py ├── netlink │ ├── __init__.py │ ├── genl │ │ └── __init__.py │ ├── route │ │ ├── __init__.py │ │ ├── links │ │ │ ├── __init__.py │ │ │ └── dummy.py │ │ └── qdisc │ │ │ └── __init__.py │ ├── fixes.h │ └── utils.h ├── py80211 │ ├── lib │ │ ├── __init__.py │ │ └── generated │ │ │ └── __init__.py │ ├── build │ │ ├── lib │ │ │ └── py80211 │ │ │ │ ├── __init__.py │ │ │ │ └── generated │ │ │ │ └── __init__.py │ │ └── lib.linux-x86_64-2.7 │ │ │ └── py80211 │ │ │ ├── generated │ │ │ └── __init__.py │ │ │ └── __init__.py │ ├── util │ │ ├── extract.d │ │ │ ├── nl80211_txattr_policy.py │ │ │ ├── nl80211_bss_select_policy.py │ │ │ └── nl80211_policy.py │ │ ├── extract.pyc │ │ ├── update.conf │ │ └── extract.h │ ├── examples │ │ ├── example04.py │ │ ├── example05.py │ │ ├── example02.py │ │ ├── example01.py │ │ ├── example10.py │ │ ├── example07.py │ │ ├── example03.py │ │ └── example06.py │ ├── README │ └── setup.py ├── doc │ ├── route.rst │ ├── index.rst │ └── route_addr.rst ├── examples │ └── __pycache__ │ │ └── nl80211.cpython-38.pyc ├── README ├── tests │ └── test-create-bridge.py └── setup.py.in ├── .indent.pro ├── man ├── nl-qdisc-list.8 ├── nl-qdisc-delete.8 ├── nl-classid-lookup.8 └── nl-pktloc-lookup.8 ├── .travis.yml ├── include ├── netlink-private │ ├── route │ │ ├── utils.h │ │ ├── mpls.h │ │ ├── link │ │ │ └── sriov.h │ │ └── nexthop-encap.h │ ├── genl.h │ ├── socket.h │ └── tc.h ├── linux-private │ └── linux │ │ ├── veth.h │ │ ├── netconf.h │ │ ├── tc_act │ │ ├── tc_gact.h │ │ ├── tc_mirred.h │ │ ├── tc_vlan.h │ │ └── tc_skbedit.h │ │ ├── socket.h │ │ ├── mpls_iptunnel.h │ │ ├── sock_diag.h │ │ ├── lwtunnel.h │ │ └── gen_stats.h └── netlink │ ├── object-api.h │ ├── cache-api.h │ ├── route │ ├── qdisc │ │ ├── red.h │ │ ├── fifo.h │ │ ├── cbq.h │ │ ├── plug.h │ │ ├── sfq.h │ │ ├── prio.h │ │ ├── dsmark.h │ │ ├── tbf.h │ │ ├── hfsc.h │ │ └── fq_codel.h │ ├── link │ │ ├── api.h │ │ ├── info-api.h │ │ ├── ppp.h │ │ ├── inet.h │ │ ├── vrf.h │ │ ├── veth.h │ │ ├── ipvlan.h │ │ ├── bonding.h │ │ ├── xfrmi.h │ │ ├── inet6.h │ │ ├── ipvti.h │ │ ├── macvtap.h │ │ ├── ipip.h │ │ └── vlan.h │ ├── tc-api.h │ ├── cls │ │ ├── police.h │ │ ├── fw.h │ │ ├── cgroup.h │ │ ├── ematch │ │ │ ├── cmp.h │ │ │ ├── nbyte.h │ │ │ ├── meta.h │ │ │ └── text.h │ │ ├── matchall.h │ │ └── basic.h │ ├── act │ │ ├── gact.h │ │ ├── mirred.h │ │ ├── skbedit.h │ │ └── vlan.h │ ├── pktloc.h │ ├── netconf.h │ ├── rtnl.h │ ├── action.h │ ├── classifier.h │ └── class.h │ ├── cli │ ├── class.h │ ├── rule.h │ ├── qdisc.h │ ├── cls.h │ ├── neigh.h │ ├── addr.h │ ├── link.h │ ├── tc.h │ ├── route.h │ ├── ct.h │ └── exp.h │ ├── netfilter │ ├── netfilter.h │ └── nfnl.h │ ├── genl │ ├── ctrl.h │ ├── family.h │ └── genl.h │ ├── version.h.in │ ├── data.h │ ├── netlink-compat.h │ ├── hashtable.h │ ├── fib_lookup │ ├── lookup.h │ └── request.h │ ├── idiag │ ├── meminfo.h │ └── vegasinfo.h │ └── errno.h ├── libnl-3.0.pc.in ├── tests ├── util.h ├── test-delete-link.c ├── test-create-ifb.c ├── test-create-bond.c ├── test-socket-creation.c ├── check-all.c ├── test-create-veth.c ├── test-create-vlan.c ├── test-create-xfrmi.c ├── test-create-ipvlan.c ├── test-create-vxlan.c ├── test-create-macsec.c ├── test-loopback-up-down.c ├── test-create-macvtap.c ├── test-create-macvlan.c ├── test-create-ipvti.c ├── test-create-ip6tnl.c ├── test-nf-cache-mngr.c ├── test-create-sit.c ├── test-create-ipgretap.c ├── test-create-ipip.c ├── test-create-ipgre.c ├── test-create-vrf.c ├── test-cache-mngr.c └── check-direct.c ├── libnl-genl-3.0.pc.in ├── libnl-nf-3.0.pc.in ├── libnl-xfrm-3.0.pc.in ├── libnl-route-3.0.pc.in ├── autogen.sh ├── libnl-idiag-3.0.pc.in ├── libnl-cli-3.0.pc.in ├── .travis └── run.sh ├── src ├── lib │ ├── qdisc.c │ ├── class.c │ ├── rule.c │ └── cls.c ├── nl-util-addr.c ├── nl-link-name2ifindex.c ├── nl-link-ifindex2name.c ├── nl-link-release.c ├── nl-list-sockets.c ├── nl-link-enslave.c ├── nl-neightbl-list.c └── genl-ctrl-list.c ├── lib ├── version.c ├── route │ ├── qdisc │ │ ├── blackhole.c │ │ └── ingress.c │ ├── link │ │ ├── dummy.c │ │ └── ifb.c │ ├── cls │ │ ├── ematch │ │ │ └── container.c │ │ └── police.c │ └── pktloc_grammar.l ├── cli │ ├── qdisc │ │ ├── ingress.c │ │ ├── blackhole.c │ │ ├── pfifo.c │ │ └── bfifo.c │ └── cls │ │ └── cgroup.c └── netfilter │ └── netfilter.c ├── libnl-genl-3.sym └── etc ├── classid └── pktloc /m4/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/api/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /python/lib/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /python/netlink/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /python/lib/generated/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /python/netlink/genl/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /python/netlink/route/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /python/py80211/lib/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /python/netlink/route/links/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /python/netlink/route/qdisc/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.indent.pro: -------------------------------------------------------------------------------- 1 | -linux -il0 -cs -lp -cbi0 2 | -------------------------------------------------------------------------------- /doc/AUTHORS: -------------------------------------------------------------------------------- 1 | Thomas Graf 2 | -------------------------------------------------------------------------------- /python/py80211/lib/generated/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /man/nl-qdisc-list.8: -------------------------------------------------------------------------------- 1 | .so man8/nl-qdisc-add.8 2 | -------------------------------------------------------------------------------- /python/netlink/fixes.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /python/py80211/build/lib/py80211/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /man/nl-qdisc-delete.8: -------------------------------------------------------------------------------- 1 | .so man8/nl-qdisc-add.8 2 | -------------------------------------------------------------------------------- /python/py80211/build/lib/py80211/generated/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/stylesheets/flask-manpage.css: -------------------------------------------------------------------------------- 1 | /* Empty placeholder file */ 2 | -------------------------------------------------------------------------------- /doc/stylesheets/volnitsky-manpage.css: -------------------------------------------------------------------------------- 1 | /* Empty placeholder file */ 2 | -------------------------------------------------------------------------------- /python/py80211/build/lib.linux-x86_64-2.7/py80211/generated/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | autoreconf -fi; 4 | rm -Rf autom4te.cache; 5 | -------------------------------------------------------------------------------- /python/doc/route.rst: -------------------------------------------------------------------------------- 1 | ********************** 2 | Routing 3 | ********************** 4 | -------------------------------------------------------------------------------- /doc/images/tc_obj.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/tc_obj.png -------------------------------------------------------------------------------- /doc/images/icons/tip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/tip.png -------------------------------------------------------------------------------- /doc/images/icons/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/up.png -------------------------------------------------------------------------------- /doc/images/ifinfomsg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/ifinfomsg.png -------------------------------------------------------------------------------- /doc/images/nlmsgerr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/nlmsgerr.png -------------------------------------------------------------------------------- /doc/images/nlmsghdr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/nlmsghdr.png -------------------------------------------------------------------------------- /doc/images/qdisc_mq.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/qdisc_mq.png -------------------------------------------------------------------------------- /doc/images/addressing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/addressing.png -------------------------------------------------------------------------------- /doc/images/icons/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/home.png -------------------------------------------------------------------------------- /doc/images/icons/next.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/next.png -------------------------------------------------------------------------------- /doc/images/icons/note.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/note.png -------------------------------------------------------------------------------- /doc/images/icons/prev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/prev.png -------------------------------------------------------------------------------- /doc/images/tc_overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/tc_overview.png -------------------------------------------------------------------------------- /python/py80211/util/extract.d/nl80211_txattr_policy.py: -------------------------------------------------------------------------------- 1 | nl80211_txattr_policy[TXRATE_VHT].min_len = 8 * 2 2 | -------------------------------------------------------------------------------- /doc/images/attribute_hdr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/attribute_hdr.png -------------------------------------------------------------------------------- /doc/images/classful_qdisc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/classful_qdisc.png -------------------------------------------------------------------------------- /doc/images/icons/caution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/caution.png -------------------------------------------------------------------------------- /doc/images/icons/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/example.png -------------------------------------------------------------------------------- /doc/images/icons/warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/warning.png -------------------------------------------------------------------------------- /doc/images/qdisc_default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/qdisc_default.png -------------------------------------------------------------------------------- /doc/images/classless_qdisc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/classless_qdisc.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/callouts/1.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/callouts/2.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/callouts/3.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/callouts/4.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/callouts/5.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/callouts/6.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/callouts/7.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/callouts/8.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/callouts/9.png -------------------------------------------------------------------------------- /doc/images/icons/important.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/important.png -------------------------------------------------------------------------------- /doc/images/library_overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/library_overview.png -------------------------------------------------------------------------------- /python/py80211/util/extract.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/python/py80211/util/extract.pyc -------------------------------------------------------------------------------- /doc/images/icons/callouts/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/callouts/10.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/callouts/11.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/callouts/12.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/callouts/13.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/callouts/14.png -------------------------------------------------------------------------------- /doc/images/icons/callouts/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/icons/callouts/15.png -------------------------------------------------------------------------------- /doc/images/classless_qdisc_nbands.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/doc/images/classless_qdisc_nbands.png -------------------------------------------------------------------------------- /python/py80211/util/extract.d/nl80211_bss_select_policy.py: -------------------------------------------------------------------------------- 1 | nl80211_bss_select_policy[BSS_SELECT_ATTR_RSSI_ADJUST].min_len = 2 2 | -------------------------------------------------------------------------------- /python/examples/__pycache__/nl80211.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ramonfontes/libnl/master/python/examples/__pycache__/nl80211.cpython-38.pyc -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | compiler: 3 | - gcc 4 | - clang 5 | 6 | addons: 7 | apt: 8 | packages: 9 | - check 10 | 11 | before_install: 12 | 13 | script: ./.travis/run.sh 14 | -------------------------------------------------------------------------------- /include/netlink-private/route/utils.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | 3 | #ifndef NETLINK_ROUTE_UTILS_PRIV_H_ 4 | #define NETLINK_ROUTE_UTILS_PRIV_H_ 5 | 6 | extern const uint8_t *const _nltst_map_stat_id_from_IPSTATS_MIB_v2; 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /doc/images/icons/README: -------------------------------------------------------------------------------- 1 | Replaced the plain DocBook XSL admonition icons with Jimmac's DocBook 2 | icons (http://jimmac.musichall.cz/ikony.php3). I dropped transparency 3 | from the Jimmac icons to get round MS IE and FOP PNG incompatibilies. 4 | 5 | Stuart Rackham 6 | -------------------------------------------------------------------------------- /python/py80211/examples/example04.py: -------------------------------------------------------------------------------- 1 | from py80211.station import * 2 | import netlink.capi as nl 3 | import sys 4 | 5 | ifidx = nl.if_nametoindex(sys.argv[1]) 6 | sl = station_list(ifidx, None, nl.NL_CB_DEBUG) 7 | for sta in sl: 8 | print(sta.attrs[nl80211.ATTR_STA_INFO]) 9 | -------------------------------------------------------------------------------- /doc/README: -------------------------------------------------------------------------------- 1 | Requirements to build documentation 2 | 3 | mscgen 4 | http://www.mcternan.me.uk/mscgen/ 5 | 6 | mscgen-filter-1.2 7 | https://github.com/hwmaier/asciidoc-mscgen-filter 8 | 9 | asciidoc > 8.6.x 10 | doxygen > 1.8.0 11 | 12 | Building the documentation: 13 | make gendoc 14 | -------------------------------------------------------------------------------- /python/py80211/examples/example05.py: -------------------------------------------------------------------------------- 1 | import netlink.capi as nl 2 | import py80211.iface 3 | 4 | iflist = py80211.iface.interface_list(None, nl.NL_CB_DEBUG) 5 | 6 | print "iflist:" 7 | print iflist._iface 8 | for iface in iflist: 9 | print "iface attributes:" 10 | print iface.attrs 11 | -------------------------------------------------------------------------------- /libnl-3.0.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libnl 7 | Description: Convenience library for netlink sockets 8 | Version: @PACKAGE_VERSION@ 9 | Libs: -L${libdir} -lnl-@MAJ_VERSION@ 10 | Cflags: -I${includedir}/libnl@MAJ_VERSION@ 11 | -------------------------------------------------------------------------------- /include/linux-private/linux/veth.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | #ifndef __NET_VETH_H_ 3 | #define __NET_VETH_H_ 4 | 5 | enum { 6 | VETH_INFO_UNSPEC, 7 | VETH_INFO_PEER, 8 | 9 | __VETH_INFO_MAX 10 | #define VETH_INFO_MAX (__VETH_INFO_MAX - 1) 11 | }; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /tests/util.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define nl_fail_if(condition, error, message) \ 4 | fail_if((condition), "nlerr=%d (%s): %s", \ 5 | (error), nl_geterror(error), (message)) 6 | 7 | Suite *make_nl_attr_suite(void); 8 | Suite *make_nl_addr_suite(void); 9 | Suite *make_nl_ematch_tree_clone_suite(void); 10 | 11 | -------------------------------------------------------------------------------- /libnl-genl-3.0.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libnl-genl 7 | Description: Generic Netlink Library 8 | Version: @PACKAGE_VERSION@ 9 | Requires: libnl-3.0 10 | Libs: -L${libdir} -lnl-genl-@MAJ_VERSION@ 11 | Cflags: -I${includedir}/libnl@MAJ_VERSION@ 12 | -------------------------------------------------------------------------------- /libnl-nf-3.0.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libnl-nf 7 | Description: Netfilter Netlink Library 8 | Version: @PACKAGE_VERSION@ 9 | Requires: libnl-route-3.0 10 | Libs: -L${libdir} -lnl-nf-@MAJ_VERSION@ 11 | Cflags: -I${includedir}/libnl@MAJ_VERSION@ 12 | -------------------------------------------------------------------------------- /libnl-xfrm-3.0.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libnl-xfrm 7 | Description: Netlink Routing Family Library 8 | Version: @PACKAGE_VERSION@ 9 | Requires: libnl-3.0 10 | Libs: -L${libdir} -lnl-xfrm-@MAJ_VERSION@ 11 | Cflags: -I${includedir}/libnl@MAJ_VERSION@ 12 | -------------------------------------------------------------------------------- /libnl-route-3.0.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libnl-route 7 | Description: Netlink Routing Family Library 8 | Version: @PACKAGE_VERSION@ 9 | Requires: libnl-3.0 10 | Libs: -L${libdir} -lnl-route-@MAJ_VERSION@ 11 | Cflags: -I${includedir}/libnl@MAJ_VERSION@ 12 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | die() { 4 | echo "$@" >&2 5 | exit 1 6 | } 7 | 8 | BASEDIR="$(dirname "$0")" 9 | 10 | cd "$BASEDIR" || die "Could not change into base directory $BASEDIR" 11 | 12 | autoreconf -fi || die "Error during autoreconf" 13 | rm -Rf autom4te.cache; 14 | 15 | doc/autogen.sh || die "Error during doc/autogen.sh" 16 | -------------------------------------------------------------------------------- /include/netlink/object-api.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2013 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_DUMMY_OBJECT_API_H_ 7 | #define NETLINK_DUMMY_OBJECT_API_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /libnl-idiag-3.0.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libnl-idiag 7 | Description: Netlink Inet Diag Family Library 8 | Version: @PACKAGE_VERSION@ 9 | Requires: libnl-3.0 10 | Libs: -L${libdir} -lnl-idiag-@MAJ_VERSION@ 11 | Cflags: -I${includedir}/libnl@MAJ_VERSION@ 12 | 13 | -------------------------------------------------------------------------------- /python/py80211/examples/example02.py: -------------------------------------------------------------------------------- 1 | from py80211.scan import * 2 | import netlink.capi as nl 3 | from py80211.cli import bss_info 4 | import sys 5 | 6 | ifidx = nl.if_nametoindex(sys.argv[1]) 7 | rh = scan_request(ifidx) 8 | rh.add_ssids(['Ziggo']) 9 | err = rh.send() 10 | if err == 0: 11 | for bss in bss_list(ifidx): 12 | print(str(bss_info(bss))) 13 | -------------------------------------------------------------------------------- /doc/gen-tags.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # Based on a script found on the englinemtn-devel mailinglist 5 | # written by Carsten Haitzler 6 | # 7 | 8 | for f in api/group__*.html 9 | do 10 | bf=$(basename $f) 11 | 12 | grep -oE "href=\"$bf#[a-z0-9]+\">[^<]+" $f | 13 | sed 's/href="\([^"]*\)">\([^<]*\)<\/a>/\2=api\/\1/' 14 | done 15 | -------------------------------------------------------------------------------- /include/netlink-private/route/mpls.h: -------------------------------------------------------------------------------- 1 | #ifndef MPLS_H_ 2 | #define MPLS_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | extern const char *mpls_ntop(int af, const void *addr, char *buf, size_t buflen); 9 | extern int mpls_pton(int af, const char *src, void *addr, size_t alen); 10 | 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /python/py80211/examples/example01.py: -------------------------------------------------------------------------------- 1 | import py80211.generated.defs as nl80211 2 | import py80211.wiphy 3 | import py80211.cli 4 | 5 | phylist = py80211.wiphy.wiphy_list() 6 | 7 | for phy in phylist: 8 | print('%s:' % phy.attrs[nl80211.ATTR_WIPHY_NAME]) 9 | for b in phy.attrs[nl80211.ATTR_WIPHY_BANDS]: 10 | print('%s' % str(py80211.cli.wiphy_band_info(b))) 11 | -------------------------------------------------------------------------------- /python/py80211/examples/example10.py: -------------------------------------------------------------------------------- 1 | import py80211.generated.defs as nl80211 2 | import py80211.wiphy 3 | import py80211.cli 4 | 5 | phylist = py80211.wiphy.wiphy_list() 6 | 7 | for phy in phylist: 8 | print('%s:' % phy.attrs[nl80211.ATTR_WIPHY_NAME]) 9 | for b in phy.attrs[nl80211.ATTR_WIPHY_BANDS]: 10 | print('%s' % str(py80211.cli.wiphy_band_info(b))) 11 | -------------------------------------------------------------------------------- /libnl-cli-3.0.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libnl-cli 7 | Description: Command Line Interface library for netlink sockets 8 | Version: @PACKAGE_VERSION@ 9 | Libs: -L${libdir} -lnl-cli-@MAJ_VERSION@ 10 | Cflags: -I${includedir} 11 | Requires: libnl-3.0 libnl-genl-3.0 libnl-nf-3.0 libnl-route-3.0 12 | -------------------------------------------------------------------------------- /doc/stylesheets/asciidoc-manpage.css: -------------------------------------------------------------------------------- 1 | /* Overrides for manpage documents */ 2 | h1 { 3 | padding-top: 0.5em; 4 | padding-bottom: 0.5em; 5 | border-top: 2px solid silver; 6 | border-bottom: 2px solid silver; 7 | } 8 | h2 { 9 | border-style: none; 10 | } 11 | div.sectionbody { 12 | margin-left: 3em; 13 | } 14 | 15 | @media print { 16 | div#toc { display: none; } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /.travis/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | CFLAGS="-Werror -Wall -Wdeclaration-after-statement -Wvla" 6 | 7 | if [ "$CC" = "clang" ]; then 8 | CFLAGS="$CFLAGS -Wno-error=unused-command-line-argument -Wno-error=unused-function" 9 | fi 10 | 11 | CFLAGS="$CFLAGS -DNL_MORE_ASSERTS=1000" 12 | 13 | export CFLAGS 14 | ./autogen.sh 15 | ./configure 16 | make -j 5 17 | make -j 5 check 18 | -------------------------------------------------------------------------------- /python/README: -------------------------------------------------------------------------------- 1 | 2 | *************************************************************************** 3 | 4 | NOTE: The python wrapper is experimental and may or may not work. 5 | 6 | *************************************************************************** 7 | 8 | For the brave: 9 | 10 | (requires an installed libnl) 11 | - $ python ./setup.py build 12 | - $ sudo python ./setup.py install 13 | -------------------------------------------------------------------------------- /include/netlink/cache-api.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2013 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_DUMMY_CACHE_API_H_ 7 | #define NETLINK_DUMMY_CACHE_API_H_ 8 | 9 | #include 10 | #include 11 | 12 | #warning "You are including a deprecated header file, include ." 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /include/netlink/route/qdisc/red.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2006 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_RED_H_ 7 | #define NETLINK_RED_H_ 8 | 9 | #include 10 | 11 | extern void rtnl_red_set_limit(struct rtnl_qdisc *qdisc, int limit); 12 | extern int rtnl_red_get_limit(struct rtnl_qdisc *qdisc); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /include/netlink/route/link/api.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2013 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_DUMMY_LINK_API_H_ 7 | #define NETLINK_DUMMY_LINK_API_H_ 8 | 9 | #include 10 | #include 11 | 12 | #warning "You are including a deprecated header file, include ." 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /include/netlink/route/link/info-api.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2013 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_DUMMY_LINK_INFO_API_H_ 7 | #define NETLINK_DUMMY_LINK_INFO_API_H_ 8 | 9 | #include 10 | #include 11 | 12 | #warning "You are including a deprecated header file, include ." 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /include/netlink/route/tc-api.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2013 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_DUMMY_TC_API_H_ 7 | #define NETLINK_DUMMY_TC_API_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #warning "You are including a deprecated header file, include ." 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /include/netlink-private/genl.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2013 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_GENL_PRIV_H_ 7 | #define NETLINK_GENL_PRIV_H_ 8 | 9 | #include 10 | #include 11 | 12 | #define GENL_HDRSIZE(hdrlen) (GENL_HDRLEN + (hdrlen)) 13 | 14 | extern int genl_resolve_id(struct genl_ops *ops); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /include/netlink/cli/class.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2010 Thomas Graf 4 | */ 5 | 6 | #ifndef __NETLINK_CLI_CLASS_H_ 7 | #define __NETLINK_CLI_CLASS_H_ 8 | 9 | #include 10 | #include 11 | 12 | extern struct rtnl_class *nl_cli_class_alloc(void); 13 | extern struct nl_cache *nl_cli_class_alloc_cache(struct nl_sock *, int); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /include/netlink/cli/rule.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2008-2009 Thomas Graf 4 | */ 5 | 6 | #ifndef __NETLINK_CLI_RULE_H_ 7 | #define __NETLINK_CLI_RULE_H_ 8 | 9 | #include 10 | 11 | extern struct rtnl_rule *nl_cli_rule_alloc(void); 12 | extern struct nl_cache *nl_cli_rule_alloc_cache(struct nl_sock *); 13 | extern void nl_cli_rule_parse_family(struct rtnl_rule *, char *); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /include/netlink/cli/qdisc.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2008-2011 Thomas Graf 4 | */ 5 | 6 | #ifndef __NETLINK_CLI_QDISC_H_ 7 | #define __NETLINK_CLI_QDISC_H_ 8 | 9 | #include 10 | 11 | #define nl_cli_qdisc_alloc_cache(sk) \ 12 | nl_cli_alloc_cache((sk), "queueing disciplines", \ 13 | rtnl_qdisc_alloc_cache) 14 | 15 | extern struct rtnl_qdisc *nl_cli_qdisc_alloc(void); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /python/py80211/examples/example07.py: -------------------------------------------------------------------------------- 1 | from py80211.scan import * 2 | import netlink.capi as nl 3 | import sys 4 | 5 | ifidx = nl.if_nametoindex(sys.argv[1]) 6 | level = nl.NL_CB_DEBUG 7 | if sys.argv[2] == 'start': 8 | rh = sched_scan_start(ifidx, level) 9 | rh.add_matches([{ 'ssid': 'lemonhead'}]) 10 | rh.set_interval(30000) 11 | elif sys.argv[2] == 'stop': 12 | rh = sched_scan_stop(ifidx, level) 13 | 14 | err = rh.send() 15 | print("scheduled scan %s: result=%d" % (sys.argv[2], err)) 16 | -------------------------------------------------------------------------------- /python/py80211/README: -------------------------------------------------------------------------------- 1 | Introduction 2 | ------------ 3 | py80211 provides a high-level API to interact with the kernel 4 | provided nl80211 interface. 5 | 6 | This project relies on Python support provided by libnl. This 7 | means this project will likely result in patches on libnl. The 8 | repository information for libnl can be found at: 9 | 10 | https://github.com/thom311/libnl 11 | 12 | Requirements 13 | ------------ 14 | - python 15 | - pycparser 16 | - libnl-3 python wrappers (incl. genl) 17 | -------------------------------------------------------------------------------- /include/netlink/route/cls/police.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2006 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_CLS_POLICE_H_ 7 | #define NETLINK_CLS_POLICE_H_ 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | extern char * nl_police2str(int, char *, size_t); 17 | extern int nl_str2police(const char *); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /python/netlink/route/links/dummy.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2011 Thomas Graf 3 | # 4 | 5 | """Dummy 6 | 7 | """ 8 | from __future__ import absolute_import 9 | 10 | __version__ = '1.0' 11 | __all__ = [ 12 | 'init', 13 | ] 14 | 15 | 16 | class DummyLink(object): 17 | def __init__(self, link): 18 | self._rtnl_link = link 19 | 20 | @staticmethod 21 | def brief(): 22 | return 'dummy' 23 | 24 | def init(link): 25 | link.dummy = DummyLink(link._rtnl_link) 26 | return link.dummy 27 | -------------------------------------------------------------------------------- /include/netlink/route/qdisc/fifo.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2006 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_FIFO_H_ 7 | #define NETLINK_FIFO_H_ 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | extern int rtnl_qdisc_fifo_set_limit(struct rtnl_qdisc *, int); 17 | extern int rtnl_qdisc_fifo_get_limit(struct rtnl_qdisc *); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /include/netlink/route/qdisc/cbq.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2006 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_CBQ_H_ 7 | #define NETLINK_CBQ_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | extern char * nl_ovl_strategy2str(int, char *, size_t); 18 | extern int nl_str2ovl_strategy(const char *); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /python/py80211/examples/example03.py: -------------------------------------------------------------------------------- 1 | from py80211.scan import * 2 | from py80211.station import * 3 | import netlink.capi as nl 4 | from py80211.cli import bss_info, sta_info 5 | import sys 6 | 7 | ifidx = nl.if_nametoindex(sys.argv[1]) 8 | bl = bss_list(ifidx) 9 | 10 | sta = station_list(ifidx) 11 | 12 | bss = bl.find_status_bss() 13 | if bss and bss.attrs[nl80211.BSS_STATUS] == nl80211.BSS_STATUS_ASSOCIATED: 14 | s = station(ifidx, bss.attrs[nl80211.BSS_BSSID], bl._access) 15 | sta_info_attrs = s.attrs[nl80211.ATTR_STA_INFO] 16 | print(sta_info_attrs) 17 | print(bss_info(bss)) -------------------------------------------------------------------------------- /python/doc/index.rst: -------------------------------------------------------------------------------- 1 | .. libnl-python documentation master file, created by 2 | sphinx-quickstart on Mon May 9 10:58:58 2011. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to libnl-python's documentation! 7 | ======================================== 8 | 9 | Contents: 10 | 11 | .. toctree:: 12 | :maxdepth: 2 13 | 14 | core 15 | route 16 | route_addr 17 | 18 | Indices and tables 19 | ================== 20 | 21 | * :ref:`genindex` 22 | * :ref:`modindex` 23 | * :ref:`search` 24 | 25 | -------------------------------------------------------------------------------- /src/lib/qdisc.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2008-2011 Thomas Graf 4 | */ 5 | 6 | /** 7 | * @ingroup cli 8 | * @defgroup cli_qdisc Queueing Disciplines 9 | * @{ 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | struct rtnl_qdisc *nl_cli_qdisc_alloc(void) 17 | { 18 | struct rtnl_qdisc *qdisc; 19 | 20 | if (!(qdisc = rtnl_qdisc_alloc())) 21 | nl_cli_fatal(ENOMEM, "Unable to allocate qdisc object"); 22 | 23 | return qdisc; 24 | } 25 | 26 | /** @} */ 27 | -------------------------------------------------------------------------------- /python/py80211/util/update.conf: -------------------------------------------------------------------------------- 1 | ################################################################### 2 | # Configuration file for release.py script 3 | # 4 | # Each line in this config file consists of: 5 | # 6 | # :: 7 | # 8 | # where: 9 | # kernel_source_branch = '/' 10 | # 11 | # Example: 12 | # master:stable/linux-4.11.y 13 | ################################################################### 14 | master:stable/linux-4.15.y:stable 15 | mac-next:mac-next/master:mac80211-next 16 | wl-testing:wl-testing/master:wireless-testing 17 | -------------------------------------------------------------------------------- /include/netlink/route/link/ppp.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2016 Jonas Johansson 4 | */ 5 | 6 | #ifndef NETLINK_LINK_PPP_H_ 7 | #define NETLINK_LINK_PPP_H_ 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | extern struct rtnl_link *rtnl_link_ppp_alloc(void); 17 | extern int rtnl_link_ppp_set_fd(struct rtnl_link *, int32_t); 18 | extern int rtnl_link_ppp_get_fd(struct rtnl_link *, int32_t *); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/netlink/cli/cls.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2010 Thomas Graf 4 | */ 5 | 6 | #ifndef __NETLINK_CLI_CLS_H_ 7 | #define __NETLINK_CLI_CLS_H_ 8 | 9 | #include 10 | #include 11 | 12 | extern struct rtnl_cls * nl_cli_cls_alloc(void); 13 | extern struct nl_cache * nl_cli_cls_alloc_cache(struct nl_sock *, 14 | int, uint32_t); 15 | extern void nl_cli_cls_parse_proto(struct rtnl_cls *, char *); 16 | extern struct rtnl_ematch_tree *nl_cli_cls_parse_ematch(struct rtnl_cls *, char *); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /include/netlink/route/act/gact.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2016 Sushma Sitaram 4 | */ 5 | 6 | #ifndef NETLINK_GACT_H_ 7 | #define NETLINK_GACT_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | extern int rtnl_gact_set_action(struct rtnl_act *act, int action); 19 | extern int rtnl_gact_get_action(struct rtnl_act *act); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /lib/version.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2012 Thomas Graf 4 | */ 5 | 6 | /** 7 | * @ingroup core 8 | * @defgroup utils Utilities 9 | * 10 | * Run-time version information 11 | * 12 | * @{ 13 | */ 14 | 15 | 16 | /** 17 | * @name Run-time version information 18 | * @{ 19 | */ 20 | 21 | #include 22 | 23 | const int nl_ver_num = LIBNL_VER_NUM; 24 | const int nl_ver_maj = LIBNL_VER_MAJ; 25 | const int nl_ver_min = LIBNL_VER_MIN; 26 | const int nl_ver_mic = LIBNL_VER_MIC; 27 | 28 | /** @} */ 29 | 30 | /** @} */ 31 | -------------------------------------------------------------------------------- /doc/resolve-asciidoc-refs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import fileinput 4 | import re 5 | import sys 6 | 7 | refs = {} 8 | complete_file = "" 9 | 10 | for line in open(sys.argv[1], 'r'): 11 | complete_file += line 12 | 13 | for m in re.findall('\[\[(.+)\]\]\n=+ ([^\n]+)', complete_file): 14 | ref, title = m 15 | refs["<<" + ref + ">>"] = "<<" + ref + ", " + title + ">>" 16 | 17 | def translate(match): 18 | try: 19 | return refs[match.group(0)] 20 | except KeyError: 21 | return "" 22 | 23 | rc = re.compile('|'.join(map(re.escape, sorted(refs, reverse=True)))) 24 | for line in open(sys.argv[1], 'r'): 25 | print rc.sub(translate, line), 26 | -------------------------------------------------------------------------------- /include/netlink/netfilter/netfilter.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2008 Patrick McHardy 4 | */ 5 | 6 | #ifndef NETLINK_NETFILTER_H_ 7 | #define NETLINK_NETFILTER_H_ 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | extern char * nfnl_verdict2str(unsigned int, char *, size_t); 16 | extern unsigned int nfnl_str2verdict(const char *); 17 | 18 | extern char * nfnl_inet_hook2str(unsigned int, char *, size_t); 19 | extern unsigned int nfnl_str2inet_hook(const char *); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /include/netlink/route/cls/fw.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2006 Thomas Graf 4 | * Copyright (c) 2006 Petr Gotthard 5 | * Copyright (c) 2006 Siemens AG Oesterreich 6 | */ 7 | 8 | #ifndef NETLINK_FW_H_ 9 | #define NETLINK_FW_H_ 10 | 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | extern int rtnl_fw_set_classid(struct rtnl_cls *, uint32_t); 19 | extern int rtnl_fw_set_mask(struct rtnl_cls *, uint32_t); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /include/netlink/route/cls/cgroup.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2009-2010 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_CLS_CGROUP_H_ 7 | #define NETLINK_CLS_CGROUP_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | extern void rtnl_cgroup_set_ematch(struct rtnl_cls *, 19 | struct rtnl_ematch_tree *); 20 | struct rtnl_ematch_tree * rtnl_cgroup_get_ematch(struct rtnl_cls *); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/nl-util-addr.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2009 Thomas Graf 4 | */ 5 | 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | int err; 11 | char host[256]; 12 | struct nl_addr *a; 13 | 14 | if (argc < 2) { 15 | fprintf(stderr, "Usage: nl-util-addr
\n"); 16 | return -1; 17 | } 18 | 19 | a = nl_cli_addr_parse(argv[1], AF_UNSPEC); 20 | err = nl_addr_resolve(a, host, sizeof(host)); 21 | if (err != 0) 22 | nl_cli_fatal(err, "Unable to resolve address \"%s\": %s", 23 | argv[1], nl_geterror(err)); 24 | 25 | printf("%s\n", host); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /include/netlink/route/cls/ematch/cmp.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2008-2010 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_CLS_EMATCH_CMP_H_ 7 | #define NETLINK_CLS_EMATCH_CMP_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | struct tcf_em_cmp; 18 | 19 | extern void rtnl_ematch_cmp_set(struct rtnl_ematch *, 20 | struct tcf_em_cmp *); 21 | extern struct tcf_em_cmp * 22 | rtnl_ematch_cmp_get(struct rtnl_ematch *); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/netlink/route/qdisc/plug.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2012 Shriram Rajagopalan 4 | */ 5 | 6 | #ifndef NETLINK_PLUG_H_ 7 | #define NETLINK_PLUG_H_ 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | extern int rtnl_qdisc_plug_set_limit(struct rtnl_qdisc *, int); 17 | extern int rtnl_qdisc_plug_buffer(struct rtnl_qdisc *); 18 | extern int rtnl_qdisc_plug_release_one(struct rtnl_qdisc *); 19 | extern int rtnl_qdisc_plug_release_indefinite(struct rtnl_qdisc *); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /tests/test-delete-link.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | struct rtnl_link *link; 9 | struct nl_sock *sk; 10 | int err; 11 | 12 | sk = nl_socket_alloc(); 13 | if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { 14 | nl_perror(err, "Unable to connect socket"); 15 | return err; 16 | } 17 | 18 | link = rtnl_link_alloc(); 19 | rtnl_link_set_name(link, "my_bond"); 20 | 21 | if ((err = rtnl_link_delete(sk, link)) < 0) { 22 | nl_perror(err, "Unable to delete link"); 23 | return err; 24 | } 25 | 26 | rtnl_link_put(link); 27 | nl_close(sk); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /include/netlink-private/socket.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2014 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_SOCKET_PRIV_H_ 7 | #define NETLINK_SOCKET_PRIV_H_ 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | int _nl_socket_is_local_port_unspecified (struct nl_sock *sk); 16 | uint32_t _nl_socket_set_local_port_no_release(struct nl_sock *sk, int generate_other); 17 | 18 | void _nl_socket_used_ports_release_all(const uint32_t *used_ports); 19 | void _nl_socket_used_ports_set(uint32_t *used_ports, uint32_t port); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /python/tests/test-create-bridge.py: -------------------------------------------------------------------------------- 1 | import netlink.core as netlink 2 | import netlink.route.capi as capi 3 | import netlink.route.link as link 4 | 5 | sock = netlink.lookup_socket(netlink.NETLINK_ROUTE) 6 | 7 | cache = link.LinkCache() 8 | cache.refill(sock) 9 | 10 | testtap1 = cache['testtap1'] 11 | print testtap1 12 | 13 | lbr = link.Link() 14 | lbr.type = 'bridge' 15 | lbr.name = 'testbridge' 16 | print lbr 17 | lbr.add() 18 | 19 | cache.refill(sock) 20 | lbr = cache['testbridge'] 21 | print lbr 22 | 23 | lbr.enslave(testtap1) 24 | cache.refill(sock) 25 | testtap1 = cache['testtap1'] 26 | 27 | print capi.rtnl_link_is_bridge(lbr._rtnl_link) 28 | print capi.rtnl_link_get_master(testtap1._rtnl_link) 29 | -------------------------------------------------------------------------------- /doc/index.txt: -------------------------------------------------------------------------------- 1 | Documentation Overview - libnl Suite 2 | ==================================== 3 | 4 | == Libraries 5 | 6 | image:library_overview.png["Library Hierarchy"] 7 | 8 | link:core.html[Netlink Library] (libnl):: 9 | Socket handling, sending and receiving, message construction and parsing, ... 10 | 11 | link:route.html[Routing Family Library] (libnl-route):: 12 | Adresses, links, neighbours, routing, traffic control, neighbour tables, ... 13 | 14 | Netfilter Library (libnl-nf):: 15 | Connection tracking, logging, queueing 16 | 17 | Generic Netlink Library (libnl-genl):: 18 | Controller API, family and command registration 19 | 20 | == Python Packages 21 | - netlink.core 22 | - netlink.route.link 23 | -------------------------------------------------------------------------------- /doc/stylesheets/toc2.css: -------------------------------------------------------------------------------- 1 | @media screen { 2 | body { 3 | max-width: 50em; /* approximately 80 characters wide */ 4 | margin-left: 16em; 5 | } 6 | 7 | #toc { 8 | position: fixed; 9 | top: 0; 10 | left: 0; 11 | bottom: 0; 12 | width: 13em; 13 | padding: 0.5em; 14 | padding-bottom: 1.5em; 15 | margin: 0; 16 | overflow: auto; 17 | border-right: 3px solid #f8f8f8; 18 | } 19 | 20 | #toc .toclevel1 { 21 | margin-top: 0.5em; 22 | } 23 | 24 | #toc .toclevel2 { 25 | margin-top: 0.25em; 26 | display: list-item; 27 | /* OLD color: #aaaaaa; */ 28 | color: #990000; 29 | } 30 | 31 | #toctitle { 32 | margin-top: 0.5em; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /include/netlink/route/link/inet.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2010 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_LINK_INET_H_ 7 | #define NETLINK_LINK_INET_H_ 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | extern const char * rtnl_link_inet_devconf2str(int, char *, size_t); 16 | extern int rtnl_link_inet_str2devconf(const char *); 17 | 18 | extern int rtnl_link_inet_get_conf(struct rtnl_link *, 19 | const unsigned int, uint32_t *); 20 | extern int rtnl_link_inet_set_conf(struct rtnl_link *, 21 | const unsigned int, uint32_t); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /lib/route/qdisc/blackhole.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2011 Thomas Graf 4 | */ 5 | 6 | /** 7 | * @ingroup qdisc 8 | * @defgroup qdisc_blackhole Blackhole 9 | * @{ 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | static struct rtnl_tc_ops blackhole_ops = { 17 | .to_kind = "blackhole", 18 | .to_type = RTNL_TC_TYPE_QDISC, 19 | }; 20 | 21 | static void __init blackhole_init(void) 22 | { 23 | rtnl_tc_register(&blackhole_ops); 24 | } 25 | 26 | static void __exit blackhole_exit(void) 27 | { 28 | rtnl_tc_unregister(&blackhole_ops); 29 | } 30 | 31 | /** @} */ 32 | -------------------------------------------------------------------------------- /tests/test-create-ifb.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | struct rtnl_link *link; 9 | struct nl_sock *sk; 10 | int err; 11 | 12 | sk = nl_socket_alloc(); 13 | if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { 14 | nl_perror(err, "Unable to connect socket"); 15 | return err; 16 | } 17 | 18 | link = rtnl_link_alloc(); 19 | rtnl_link_set_type(link, "ifb"); 20 | rtnl_link_set_name(link, "ifb1"); 21 | 22 | if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0) { 23 | nl_perror(err, "Unable to add link"); 24 | return err; 25 | } 26 | 27 | rtnl_link_put(link); 28 | nl_close(sk); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /lib/route/link/dummy.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2011 Thomas Graf 4 | */ 5 | 6 | /** 7 | * @ingroup link 8 | * @defgroup dummy Dummy 9 | * 10 | * @details 11 | * \b Link Type Name: "dummy" 12 | * 13 | * @{ 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | static struct rtnl_link_info_ops dummy_info_ops = { 21 | .io_name = "dummy", 22 | }; 23 | 24 | static void __init dummy_init(void) 25 | { 26 | rtnl_link_register_info(&dummy_info_ops); 27 | } 28 | 29 | static void __exit dummy_exit(void) 30 | { 31 | rtnl_link_unregister_info(&dummy_info_ops); 32 | } 33 | 34 | /** @} */ 35 | -------------------------------------------------------------------------------- /tests/test-create-bond.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | struct rtnl_link *link; 10 | struct nl_sock *sk; 11 | int err; 12 | 13 | sk = nl_socket_alloc(); 14 | if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { 15 | nl_perror(err, "Unable to connect socket"); 16 | return err; 17 | } 18 | 19 | link = rtnl_link_bond_alloc(); 20 | rtnl_link_set_name(link, "my_bond"); 21 | 22 | if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0) { 23 | nl_perror(err, "Unable to add link"); 24 | return err; 25 | } 26 | 27 | rtnl_link_put(link); 28 | nl_close(sk); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /tests/test-socket-creation.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | struct nl_sock *h[1025]; 7 | int i; 8 | 9 | h[0] = nl_socket_alloc(); 10 | printf("Created handle with port 0x%x\n", 11 | nl_socket_get_local_port(h[0])); 12 | nl_socket_free(h[0]); 13 | h[0] = nl_socket_alloc(); 14 | printf("Created handle with port 0x%x\n", 15 | nl_socket_get_local_port(h[0])); 16 | nl_socket_free(h[0]); 17 | 18 | for (i = 0; i < 1025; i++) { 19 | h[i] = nl_socket_alloc(); 20 | if (h[i] == NULL) 21 | nl_perror(ENOMEM, "Unable to allocate socket"); 22 | else 23 | printf("Created handle with port 0x%x\n", 24 | nl_socket_get_local_port(h[i])); 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /lib/route/link/ifb.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2014 Cong Wang 4 | */ 5 | 6 | /** 7 | * @ingroup link 8 | * @defgroup ifb Intermediate Functional Block 9 | * 10 | * @details 11 | * \b Link Type Name: "ifb" 12 | * 13 | * @{ 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | static struct rtnl_link_info_ops ifb_info_ops = { 21 | .io_name = "ifb", 22 | }; 23 | 24 | static void __init ifb_init(void) 25 | { 26 | rtnl_link_register_info(&ifb_info_ops); 27 | } 28 | 29 | static void __exit ifb_exit(void) 30 | { 31 | rtnl_link_unregister_info(&ifb_info_ops); 32 | } 33 | 34 | /** @} */ 35 | -------------------------------------------------------------------------------- /include/netlink/route/link/vrf.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2015 Cumulus Networks. All rights reserved. 4 | * Copyright (c) 2015 David Ahern 5 | */ 6 | 7 | #ifndef NETLINK_LINK_VRF_H_ 8 | #define NETLINK_LINK_VRF_H_ 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | extern struct rtnl_link *rtnl_link_vrf_alloc(void); 18 | extern int rtnl_link_is_vrf(struct rtnl_link *link); 19 | extern int rtnl_link_vrf_get_tableid(struct rtnl_link *link, uint32_t *id); 20 | extern int rtnl_link_vrf_set_tableid(struct rtnl_link *link, uint32_t id); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /include/linux-private/linux/netconf.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | #ifndef _LINUX_NETCONF_H_ 3 | #define _LINUX_NETCONF_H_ 4 | 5 | #include 6 | #include 7 | 8 | struct netconfmsg { 9 | __u8 ncm_family; 10 | }; 11 | 12 | enum { 13 | NETCONFA_UNSPEC, 14 | NETCONFA_IFINDEX, 15 | NETCONFA_FORWARDING, 16 | NETCONFA_RP_FILTER, 17 | NETCONFA_MC_FORWARDING, 18 | NETCONFA_PROXY_NEIGH, 19 | NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN, 20 | NETCONFA_INPUT, 21 | NETCONFA_BC_FORWARDING, 22 | __NETCONFA_MAX 23 | }; 24 | #define NETCONFA_MAX (__NETCONFA_MAX - 1) 25 | #define NETCONFA_ALL -1 26 | 27 | #define NETCONFA_IFINDEX_ALL -1 28 | #define NETCONFA_IFINDEX_DEFAULT -2 29 | 30 | #endif /* _LINUX_NETCONF_H_ */ 31 | -------------------------------------------------------------------------------- /include/netlink/route/link/veth.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2013 Cong Wang 4 | */ 5 | 6 | #ifndef NETLINK_LINK_VETH_H_ 7 | #define NETLINK_LINK_VETH_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | extern struct rtnl_link *rtnl_link_veth_alloc(void); 18 | extern void rtnl_link_veth_release(struct rtnl_link *); 19 | 20 | extern int rtnl_link_is_veth(struct rtnl_link *); 21 | 22 | extern struct rtnl_link *rtnl_link_veth_get_peer(struct rtnl_link *); 23 | extern int rtnl_link_veth_add(struct nl_sock *sock, const char *name, 24 | const char *peer, pid_t pid); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /include/linux-private/linux/tc_act/tc_gact.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | #ifndef __LINUX_TC_GACT_H 3 | #define __LINUX_TC_GACT_H 4 | 5 | #include 6 | #include 7 | 8 | #define TCA_ACT_GACT 5 9 | struct tc_gact { 10 | tc_gen; 11 | 12 | }; 13 | 14 | struct tc_gact_p { 15 | #define PGACT_NONE 0 16 | #define PGACT_NETRAND 1 17 | #define PGACT_DETERM 2 18 | #define MAX_RAND (PGACT_DETERM + 1 ) 19 | __u16 ptype; 20 | __u16 pval; 21 | int paction; 22 | }; 23 | 24 | enum { 25 | TCA_GACT_UNSPEC, 26 | TCA_GACT_TM, 27 | TCA_GACT_PARMS, 28 | TCA_GACT_PROB, 29 | TCA_GACT_PAD, 30 | __TCA_GACT_MAX 31 | }; 32 | #define TCA_GACT_MAX (__TCA_GACT_MAX - 1) 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/netlink/route/qdisc/sfq.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2011 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_SFQ_H_ 7 | #define NETLINK_SFQ_H_ 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | extern void rtnl_sfq_set_quantum(struct rtnl_qdisc *, int); 17 | extern int rtnl_sfq_get_quantum(struct rtnl_qdisc *); 18 | 19 | extern void rtnl_sfq_set_limit(struct rtnl_qdisc *, int); 20 | extern int rtnl_sfq_get_limit(struct rtnl_qdisc *); 21 | 22 | extern void rtnl_sfq_set_perturb(struct rtnl_qdisc *, int); 23 | extern int rtnl_sfq_get_perturb(struct rtnl_qdisc *); 24 | 25 | extern int rtnl_sfq_get_divisor(struct rtnl_qdisc *); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /include/netlink/cli/neigh.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2008-2009 Thomas Graf 4 | */ 5 | 6 | #ifndef __NETLINK_CLI_NEIGH_H_ 7 | #define __NETLINK_CLI_NEIGH_H_ 8 | 9 | #include 10 | 11 | #define nl_cli_neigh_alloc_cache(sk) \ 12 | nl_cli_alloc_cache_flags((sk), "neighbour", NL_CACHE_AF_ITER, \ 13 | rtnl_neigh_alloc_cache_flags) 14 | 15 | extern struct rtnl_neigh *nl_cli_neigh_alloc(void); 16 | extern void nl_cli_neigh_parse_dst(struct rtnl_neigh *, char *); 17 | extern void nl_cli_neigh_parse_lladdr(struct rtnl_neigh *, char *); 18 | extern void nl_cli_neigh_parse_dev(struct rtnl_neigh *, struct nl_cache *, char *); 19 | extern void nl_cli_neigh_parse_family(struct rtnl_neigh *, char *); 20 | extern void nl_cli_neigh_parse_state(struct rtnl_neigh *, char *); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /include/netlink/route/act/mirred.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2013 Cong Wang 4 | */ 5 | 6 | #ifndef NETLINK_MIRRED_H_ 7 | #define NETLINK_MIRRED_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | extern int rtnl_mirred_set_action(struct rtnl_act *, int); 19 | extern int rtnl_mirred_get_action(struct rtnl_act *); 20 | extern int rtnl_mirred_set_ifindex(struct rtnl_act *, uint32_t); 21 | extern uint32_t rtnl_mirred_get_ifindex(struct rtnl_act *); 22 | extern int rtnl_mirred_set_policy(struct rtnl_act *, int); 23 | extern int rtnl_mirred_get_policy(struct rtnl_act *); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /include/netlink/route/link/ipvlan.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2015 Cong Wang 4 | */ 5 | 6 | #ifndef NETLINK_LINK_IPVLAN_H_ 7 | #define NETLINK_LINK_IPVLAN_H_ 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | extern struct rtnl_link *rtnl_link_ipvlan_alloc(void); 17 | 18 | extern int rtnl_link_is_ipvlan(struct rtnl_link *); 19 | 20 | extern char * rtnl_link_ipvlan_mode2str(int, char *, size_t); 21 | extern int rtnl_link_ipvlan_str2mode(const char *); 22 | 23 | extern int rtnl_link_ipvlan_set_mode(struct rtnl_link *, 24 | uint16_t); 25 | extern int rtnl_link_ipvlan_get_mode(struct rtnl_link *, uint16_t *out_mode); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /tests/check-all.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2013 Thomas Graf 4 | */ 5 | 6 | #include 7 | 8 | #include "util.h" 9 | 10 | static Suite *main_suite(void) 11 | { 12 | Suite *suite = suite_create("main"); 13 | 14 | return suite; 15 | } 16 | 17 | int main(int argc, char *argv[]) 18 | { 19 | SRunner *runner; 20 | int nfailed; 21 | 22 | runner = srunner_create(main_suite()); 23 | 24 | /* Add testsuites below */ 25 | 26 | srunner_add_suite(runner, make_nl_addr_suite()); 27 | srunner_add_suite(runner, make_nl_attr_suite()); 28 | srunner_add_suite(runner, make_nl_ematch_tree_clone_suite()); 29 | 30 | /* Do not add testsuites below this line */ 31 | 32 | srunner_run_all(runner, CK_ENV); 33 | 34 | nfailed = srunner_ntests_failed(runner); 35 | srunner_free(runner); 36 | 37 | return nfailed != 0; 38 | } 39 | -------------------------------------------------------------------------------- /src/nl-link-name2ifindex.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2008 Thomas Graf 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | static void print_usage(void) 12 | { 13 | printf("Usage: nl-link-name2ifindex \n"); 14 | exit(0); 15 | } 16 | 17 | int main(int argc, char *argv[]) 18 | { 19 | struct nl_sock *sock; 20 | struct nl_cache *link_cache; 21 | uint32_t ifindex; 22 | 23 | if (argc < 2) 24 | print_usage(); 25 | 26 | sock = nl_cli_alloc_socket(); 27 | nl_cli_connect(sock, NETLINK_ROUTE); 28 | link_cache = nl_cli_link_alloc_cache(sock); 29 | 30 | if (!(ifindex = rtnl_link_name2i(link_cache, argv[1]))) 31 | nl_cli_fatal(ENOENT, "Interface \"%s\" does not exist", 32 | argv[1]); 33 | 34 | printf("%u\n", ifindex); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /include/linux-private/linux/socket.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | #ifndef _LINUX_SOCKET_H 3 | #define _LINUX_SOCKET_H 4 | 5 | /* 6 | * Desired design of maximum size and alignment (see RFC2553) 7 | */ 8 | #define _K_SS_MAXSIZE 128 /* Implementation specific max size */ 9 | #define _K_SS_ALIGNSIZE (__alignof__ (struct sockaddr *)) 10 | /* Implementation specific desired alignment */ 11 | 12 | typedef unsigned short __kernel_sa_family_t; 13 | 14 | struct __kernel_sockaddr_storage { 15 | __kernel_sa_family_t ss_family; /* address family */ 16 | /* Following field(s) are implementation specific */ 17 | char __data[_K_SS_MAXSIZE - sizeof(unsigned short)]; 18 | /* space to achieve desired size, */ 19 | /* _SS_MAXSIZE value minus size of ss_family */ 20 | } __attribute__ ((aligned(_K_SS_ALIGNSIZE))); /* force desired alignment */ 21 | 22 | #endif /* _LINUX_SOCKET_H */ 23 | -------------------------------------------------------------------------------- /include/linux-private/linux/tc_act/tc_mirred.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | #ifndef __LINUX_TC_MIR_H 3 | #define __LINUX_TC_MIR_H 4 | 5 | #include 6 | #include 7 | 8 | #define TCA_ACT_MIRRED 8 9 | #define TCA_EGRESS_REDIR 1 /* packet redirect to EGRESS*/ 10 | #define TCA_EGRESS_MIRROR 2 /* mirror packet to EGRESS */ 11 | #define TCA_INGRESS_REDIR 3 /* packet redirect to INGRESS*/ 12 | #define TCA_INGRESS_MIRROR 4 /* mirror packet to INGRESS */ 13 | 14 | struct tc_mirred { 15 | tc_gen; 16 | int eaction; /* one of IN/EGRESS_MIRROR/REDIR */ 17 | __u32 ifindex; /* ifindex of egress port */ 18 | }; 19 | 20 | enum { 21 | TCA_MIRRED_UNSPEC, 22 | TCA_MIRRED_TM, 23 | TCA_MIRRED_PARMS, 24 | TCA_MIRRED_PAD, 25 | __TCA_MIRRED_MAX 26 | }; 27 | #define TCA_MIRRED_MAX (__TCA_MIRRED_MAX - 1) 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /include/linux-private/linux/mpls_iptunnel.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ 2 | /* 3 | * mpls tunnel api 4 | * 5 | * Authors: 6 | * Roopa Prabhu 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU General Public License 10 | * as published by the Free Software Foundation; either version 11 | * 2 of the License, or (at your option) any later version. 12 | */ 13 | 14 | #ifndef _LINUX_MPLS_IPTUNNEL_H 15 | #define _LINUX_MPLS_IPTUNNEL_H 16 | 17 | /* MPLS tunnel attributes 18 | * [RTA_ENCAP] = { 19 | * [MPLS_IPTUNNEL_DST] 20 | * [MPLS_IPTUNNEL_TTL] 21 | * } 22 | */ 23 | enum { 24 | MPLS_IPTUNNEL_UNSPEC, 25 | MPLS_IPTUNNEL_DST, 26 | MPLS_IPTUNNEL_TTL, 27 | __MPLS_IPTUNNEL_MAX, 28 | }; 29 | #define MPLS_IPTUNNEL_MAX (__MPLS_IPTUNNEL_MAX - 1) 30 | 31 | #endif /* _LINUX_MPLS_IPTUNNEL_H */ 32 | -------------------------------------------------------------------------------- /include/linux-private/linux/sock_diag.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | #ifndef __SOCK_DIAG_H__ 3 | #define __SOCK_DIAG_H__ 4 | 5 | #include 6 | 7 | #define SOCK_DIAG_BY_FAMILY 20 8 | #define SOCK_DESTROY 21 9 | 10 | struct sock_diag_req { 11 | __u8 sdiag_family; 12 | __u8 sdiag_protocol; 13 | }; 14 | 15 | enum { 16 | SK_MEMINFO_RMEM_ALLOC, 17 | SK_MEMINFO_RCVBUF, 18 | SK_MEMINFO_WMEM_ALLOC, 19 | SK_MEMINFO_SNDBUF, 20 | SK_MEMINFO_FWD_ALLOC, 21 | SK_MEMINFO_WMEM_QUEUED, 22 | SK_MEMINFO_OPTMEM, 23 | SK_MEMINFO_BACKLOG, 24 | SK_MEMINFO_DROPS, 25 | 26 | SK_MEMINFO_VARS, 27 | }; 28 | 29 | enum sknetlink_groups { 30 | SKNLGRP_NONE, 31 | SKNLGRP_INET_TCP_DESTROY, 32 | SKNLGRP_INET_UDP_DESTROY, 33 | SKNLGRP_INET6_TCP_DESTROY, 34 | SKNLGRP_INET6_UDP_DESTROY, 35 | __SKNLGRP_MAX, 36 | }; 37 | #define SKNLGRP_MAX (__SKNLGRP_MAX - 1) 38 | 39 | #endif /* __SOCK_DIAG_H__ */ 40 | -------------------------------------------------------------------------------- /src/lib/class.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2010-2011 Thomas Graf 4 | */ 5 | 6 | /** 7 | * @ingroup cli 8 | * @defgroup cli_class Traffic Classes 9 | * @{ 10 | */ 11 | 12 | #include 13 | #include 14 | 15 | struct rtnl_class *nl_cli_class_alloc(void) 16 | { 17 | struct rtnl_class *class; 18 | 19 | if (!(class = rtnl_class_alloc())) 20 | nl_cli_fatal(ENOMEM, "Unable to allocate class object"); 21 | 22 | return class; 23 | } 24 | 25 | struct nl_cache *nl_cli_class_alloc_cache(struct nl_sock *sock, int ifindex) 26 | { 27 | struct nl_cache *cache; 28 | int err; 29 | 30 | if ((err = rtnl_class_alloc_cache(sock, ifindex, &cache)) < 0) 31 | nl_cli_fatal(err, "Unable to allocate class cache: %s", 32 | nl_geterror(err)); 33 | 34 | nl_cache_mngt_provide(cache); 35 | 36 | return cache; 37 | } 38 | 39 | /** @} */ 40 | -------------------------------------------------------------------------------- /include/netlink/route/link/bonding.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2011-2013 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_LINK_BONDING_H_ 7 | #define NETLINK_LINK_BONDING_H_ 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | extern struct rtnl_link *rtnl_link_bond_alloc(void); 17 | 18 | extern int rtnl_link_bond_add(struct nl_sock *, const char *, 19 | struct rtnl_link *); 20 | 21 | extern int rtnl_link_bond_enslave_ifindex(struct nl_sock *, int, int); 22 | extern int rtnl_link_bond_enslave(struct nl_sock *, struct rtnl_link *, 23 | struct rtnl_link *); 24 | 25 | extern int rtnl_link_bond_release_ifindex(struct nl_sock *, int); 26 | extern int rtnl_link_bond_release(struct nl_sock *, struct rtnl_link *); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /include/netlink/route/link/xfrmi.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2019 Eyal Birger 4 | * 5 | * Based on netlink/route/link/ipvti.h 6 | */ 7 | 8 | #ifndef NETLINK_LINK_XFRMI_H_ 9 | #define NETLINK_LINK_XFRMI_H_ 10 | 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | extern struct rtnl_link *rtnl_link_xfrmi_alloc(void); 18 | 19 | extern int rtnl_link_is_xfrmi(struct rtnl_link *link); 20 | 21 | extern int rtnl_link_xfrmi_set_link(struct rtnl_link *link, uint32_t index); 22 | extern int rtnl_link_xfrmi_get_link(struct rtnl_link *link, uint32_t *out_link); 23 | 24 | extern int rtnl_link_xfrmi_set_if_id(struct rtnl_link *link, uint32_t if_id); 25 | extern int rtnl_link_xfrmi_get_if_id(struct rtnl_link *link, uint32_t *out_if_id); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /include/netlink/genl/ctrl.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2012 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_GENL_CTRL_H_ 7 | #define NETLINK_GENL_CTRL_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | struct genl_family; 18 | 19 | extern int genl_ctrl_alloc_cache(struct nl_sock *, 20 | struct nl_cache **); 21 | extern struct genl_family * genl_ctrl_search(struct nl_cache *, int); 22 | extern struct genl_family * genl_ctrl_search_by_name(struct nl_cache *, 23 | const char *); 24 | extern int genl_ctrl_resolve(struct nl_sock *, 25 | const char *); 26 | extern int genl_ctrl_resolve_grp(struct nl_sock *sk, 27 | const char *family, 28 | const char *grp); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/netlink/version.h.in: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2008-2011 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_VERSION_H_ 7 | #define NETLINK_VERSION_H_ 8 | 9 | /* Compile Time Versioning Information */ 10 | 11 | #define LIBNL_STRING "@PACKAGE_STRING@" 12 | #define LIBNL_VERSION "@PACKAGE_VERSION@" 13 | 14 | #define LIBNL_VER_MAJ @MAJ_VERSION@ 15 | #define LIBNL_VER_MIN @MIN_VERSION@ 16 | #define LIBNL_VER_MIC @MIC_VERSION@ 17 | #define LIBNL_VER(maj,min) ((maj) << 8 | (min)) 18 | #define LIBNL_VER_NUM LIBNL_VER(LIBNL_VER_MAJ, LIBNL_VER_MIN) 19 | 20 | #define LIBNL_CURRENT @LT_CURRENT@ 21 | #define LIBNL_REVISION @LT_REVISION@ 22 | #define LIBNL_AGE @LT_AGE@ 23 | 24 | /* Run-time version information */ 25 | 26 | extern const int nl_ver_num; 27 | extern const int nl_ver_maj; 28 | extern const int nl_ver_min; 29 | extern const int nl_ver_mic; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /include/netlink/route/cls/ematch/nbyte.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2010 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_CLS_EMATCH_NBYTE_H_ 7 | #define NETLINK_CLS_EMATCH_NBYTE_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | extern void rtnl_ematch_nbyte_set_offset(struct rtnl_ematch *, 18 | uint8_t, uint16_t); 19 | extern uint16_t rtnl_ematch_nbyte_get_offset(struct rtnl_ematch *); 20 | extern uint8_t rtnl_ematch_nbyte_get_layer(struct rtnl_ematch *); 21 | extern void rtnl_ematch_nbyte_set_pattern(struct rtnl_ematch *, 22 | uint8_t *, size_t); 23 | extern uint8_t * rtnl_ematch_nbyte_get_pattern(struct rtnl_ematch *); 24 | extern size_t rtnl_ematch_nbyte_get_len(struct rtnl_ematch *); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /python/py80211/examples/example06.py: -------------------------------------------------------------------------------- 1 | ## 2 | # client-server example 3 | # 4 | # This requires Pyro4 package to be installed. You need to start a Pyro4 5 | # name server which you can start in seperate terminal running 'pyro4-ns'. 6 | # In yet another terminal you can start the server using 7 | # 'python -m py80211.server'. 8 | # 9 | # By default it works on localhost. See [1] for details. 10 | # 11 | # [1] https://pythonhosted.org/Pyro4/tutorials.html#running-it-on-different-machines 12 | # 13 | import Pyro4 as pyro 14 | import sys 15 | 16 | import py80211.generated.defs as nl80211 17 | import py80211.wiphy 18 | import py80211.cli 19 | 20 | servername = sys.argv[1] 21 | pf = pyro.Proxy('PYRONAME:py80211.server.%s' % servername) 22 | phylist = pf.create_instance('py80211.wiphy.wiphy_list') 23 | 24 | for phy in phylist.wiphys: 25 | print('%s:' % phy.attrs[nl80211.ATTR_WIPHY_NAME]) 26 | for b in phy.attrs[nl80211.ATTR_WIPHY_BANDS]: 27 | print('%s' % str(py80211.cli.wiphy_band_info(b))) 28 | -------------------------------------------------------------------------------- /python/py80211/build/lib.linux-x86_64-2.7/py80211/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # nl80211 support module 3 | # 4 | # Copyright 2013 Arend van Spriel 5 | # 6 | # Permission to use, copy, modify, and/or distribute this software for any 7 | # purpose with or without fee is hereby granted, provided that the above 8 | # copyright notice and this permission notice appear in all copies. 9 | # 10 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | # 18 | from generated.defs import * 19 | from generated import strmap 20 | -------------------------------------------------------------------------------- /src/nl-link-ifindex2name.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2009 Thomas Graf 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | static void print_usage(void) 12 | { 13 | printf("Usage: nl-link-ifindex2name \n"); 14 | exit(0); 15 | } 16 | 17 | int main(int argc, char *argv[]) 18 | { 19 | struct nl_sock *sock; 20 | struct nl_cache *link_cache; 21 | char name[IFNAMSIZ]; 22 | uint32_t ifindex; 23 | 24 | if (argc < 2) 25 | print_usage(); 26 | 27 | sock = nl_cli_alloc_socket(); 28 | nl_cli_connect(sock, NETLINK_ROUTE); 29 | link_cache = nl_cli_link_alloc_cache(sock); 30 | 31 | ifindex = nl_cli_parse_u32(argv[1]); 32 | 33 | if (!rtnl_link_i2name(link_cache, ifindex, name, sizeof(name))) 34 | nl_cli_fatal(ENOENT, "Interface index %d does not exist", 35 | ifindex); 36 | 37 | printf("%s\n", name); 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /include/netlink-private/route/link/sriov.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2016 Intel Corp. All rights reserved. 4 | * Copyright (c) 2016 Jef Oliver 5 | */ 6 | 7 | #ifndef NETLINK_PRIV_LINK_SRIOV_H_ 8 | #define NETLINK_PRIV_LINK_SRIOV_H_ 9 | 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | extern int rtnl_link_sriov_clone(struct rtnl_link *, struct rtnl_link *); 18 | extern void rtnl_link_sriov_dump_details(struct rtnl_link *, struct nl_dump_params *); 19 | extern void rtnl_link_sriov_dump_stats(struct rtnl_link *, struct nl_dump_params *); 20 | extern int rtnl_link_sriov_fill_vflist(struct nl_msg *, struct rtnl_link *); 21 | extern void rtnl_link_sriov_free_data(struct rtnl_link *); 22 | extern int rtnl_link_sriov_parse_vflist(struct rtnl_link *, struct nlattr **); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/netlink/route/cls/matchall.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2017 Volodymyr Bendiuga 4 | */ 5 | 6 | #ifndef NETLINK_MATCHALL_H_ 7 | #define NETLINK_MATCHALL_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | extern int rtnl_mall_set_classid(struct rtnl_cls *, uint32_t); 19 | extern int rtnl_mall_get_classid(struct rtnl_cls *, uint32_t *); 20 | extern int rtnl_mall_set_flags(struct rtnl_cls *, uint32_t); 21 | extern int rtnl_mall_get_flags(struct rtnl_cls *, uint32_t *); 22 | extern int rtnl_mall_append_action(struct rtnl_cls *, struct rtnl_act *); 23 | extern struct rtnl_act *rtnl_mall_get_first_action(struct rtnl_cls *); 24 | extern int rtnl_mall_del_action(struct rtnl_cls *, struct rtnl_act *); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /include/netlink/data.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2008 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_DATA_H_ 7 | #define NETLINK_DATA_H_ 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | struct nlattr; 16 | 17 | struct nl_data; 18 | 19 | /* General */ 20 | extern struct nl_data * nl_data_alloc(const void *, size_t); 21 | extern struct nl_data * nl_data_alloc_attr(const struct nlattr *); 22 | extern struct nl_data * nl_data_clone(const struct nl_data *); 23 | extern int nl_data_append(struct nl_data *, const void *, size_t); 24 | extern void nl_data_free(struct nl_data *); 25 | 26 | /* Access Functions */ 27 | extern void * nl_data_get(const struct nl_data *); 28 | extern size_t nl_data_get_size(const struct nl_data *); 29 | 30 | /* Misc */ 31 | extern int nl_data_cmp(const struct nl_data *, 32 | const struct nl_data *); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /include/netlink/route/cls/basic.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2008-2010 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_BASIC_H_ 7 | #define NETLINK_BASIC_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | extern void rtnl_basic_set_target(struct rtnl_cls *, uint32_t); 19 | extern uint32_t rtnl_basic_get_target(struct rtnl_cls *); 20 | extern void rtnl_basic_set_ematch(struct rtnl_cls *, 21 | struct rtnl_ematch_tree *); 22 | extern struct rtnl_ematch_tree *rtnl_basic_get_ematch(struct rtnl_cls *); 23 | extern int rtnl_basic_add_action(struct rtnl_cls *, struct rtnl_act *); 24 | extern int rtnl_basic_del_action(struct rtnl_cls *, struct rtnl_act *); 25 | extern struct rtnl_act* rtnl_basic_get_action(struct rtnl_cls *); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /include/linux-private/linux/tc_act/tc_vlan.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2014 Jiri Pirko 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | */ 10 | 11 | #ifndef __LINUX_TC_VLAN_H 12 | #define __LINUX_TC_VLAN_H 13 | 14 | #include 15 | 16 | #define TCA_ACT_VLAN 12 17 | 18 | #define TCA_VLAN_ACT_POP 1 19 | #define TCA_VLAN_ACT_PUSH 2 20 | #define TCA_VLAN_ACT_MODIFY 3 21 | 22 | struct tc_vlan { 23 | tc_gen; 24 | int v_action; 25 | }; 26 | 27 | enum { 28 | TCA_VLAN_UNSPEC, 29 | TCA_VLAN_TM, 30 | TCA_VLAN_PARMS, 31 | TCA_VLAN_PUSH_VLAN_ID, 32 | TCA_VLAN_PUSH_VLAN_PROTOCOL, 33 | TCA_VLAN_PAD, 34 | TCA_VLAN_PUSH_VLAN_PRIORITY, 35 | __TCA_VLAN_MAX, 36 | }; 37 | #define TCA_VLAN_MAX (__TCA_VLAN_MAX - 1) 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/netlink/netlink-compat.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2006 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_COMPAT_H_ 7 | #define NETLINK_COMPAT_H_ 8 | 9 | #if !defined _LINUX_SOCKET_H && !defined _BITS_SOCKADDR_H 10 | typedef unsigned short sa_family_t; 11 | #endif 12 | 13 | #ifndef IFNAMSIZ 14 | /** Maximum length of a interface name */ 15 | #define IFNAMSIZ 16 16 | #endif 17 | 18 | /* patch 2.4.x if_arp */ 19 | #ifndef ARPHRD_INFINIBAND 20 | #define ARPHRD_INFINIBAND 32 21 | #endif 22 | 23 | /* patch 2.4.x eth header file */ 24 | #ifndef ETH_P_MPLS_UC 25 | #define ETH_P_MPLS_UC 0x8847 26 | #endif 27 | 28 | #ifndef ETH_P_MPLS_MC 29 | #define ETH_P_MPLS_MC 0x8848 30 | #endif 31 | 32 | #ifndef ETH_P_EDP2 33 | #define ETH_P_EDP2 0x88A2 34 | #endif 35 | 36 | #ifndef ETH_P_HDLC 37 | #define ETH_P_HDLC 0x0019 38 | #endif 39 | 40 | #ifndef AF_LLC 41 | #define AF_LLC 26 42 | #endif 43 | 44 | #ifndef AF_MPLS 45 | #define AF_MPLS 28 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/nl-link-release.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2011 Thomas Graf 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | struct nl_sock *sock; 15 | struct nl_cache *link_cache; 16 | struct rtnl_link *slave; 17 | int err; 18 | 19 | if (argc < 2) { 20 | fprintf(stderr, "Usage: nl-link-release slave\n"); 21 | return 1; 22 | } 23 | 24 | sock = nl_cli_alloc_socket(); 25 | nl_cli_connect(sock, NETLINK_ROUTE); 26 | link_cache = nl_cli_link_alloc_cache(sock); 27 | 28 | if (!(slave = rtnl_link_get_by_name(link_cache, argv[1]))) { 29 | fprintf(stderr, "Unknown link: %s\n", argv[1]); 30 | return 1; 31 | } 32 | 33 | if ((err = rtnl_link_bond_release(sock, slave)) < 0) { 34 | fprintf(stderr, "Unable to release slave %s: %s\n", 35 | argv[1], nl_geterror(err)); 36 | return 1; 37 | } 38 | 39 | return 0; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /doc/stylesheets/xhtml11-quirks.css: -------------------------------------------------------------------------------- 1 | /* Workarounds for IE6's broken and incomplete CSS2. */ 2 | 3 | div.sidebar-content { 4 | background: #ffffee; 5 | border: 1px solid silver; 6 | padding: 0.5em; 7 | } 8 | div.sidebar-title, div.image-title { 9 | color: #527bbd; 10 | font-family: sans-serif; 11 | font-weight: bold; 12 | margin-top: 0.0em; 13 | margin-bottom: 0.5em; 14 | } 15 | 16 | div.listingblock div.content { 17 | border: 1px solid silver; 18 | background: #f4f4f4; 19 | padding: 0.5em; 20 | } 21 | 22 | div.quoteblock-attribution { 23 | padding-top: 0.5em; 24 | text-align: right; 25 | } 26 | 27 | pre.verseblock-content { 28 | font-family: inherit; 29 | } 30 | div.verseblock-attribution { 31 | padding-top: 0.75em; 32 | text-align: left; 33 | } 34 | 35 | div.exampleblock-content { 36 | border-left: 3px solid #dddddd; 37 | padding-left: 0.5em; 38 | } 39 | 40 | div.imageblock.latex div.image-title { margin-top: 0.5em; } 41 | 42 | /* IE6 sets dynamically generated links as visited. */ 43 | div#toc a:visited { color: blue; } 44 | -------------------------------------------------------------------------------- /include/netlink/route/pktloc.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2010 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_PKTLOC_H_ 7 | #define NETLINK_PKTLOC_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | struct rtnl_pktloc 20 | { 21 | char * name; 22 | uint8_t layer; 23 | uint8_t shift; 24 | uint16_t offset; 25 | uint16_t align; 26 | uint32_t mask; 27 | uint32_t refcnt; 28 | 29 | struct nl_list_head list; 30 | }; 31 | 32 | extern int rtnl_pktloc_lookup(const char *, struct rtnl_pktloc **); 33 | extern struct rtnl_pktloc *rtnl_pktloc_alloc(void); 34 | extern void rtnl_pktloc_put(struct rtnl_pktloc *); 35 | extern int rtnl_pktloc_add(struct rtnl_pktloc *); 36 | extern void rtnl_pktloc_foreach(void (*cb)(struct rtnl_pktloc *, void *), 37 | void *); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /include/netlink-private/route/nexthop-encap.h: -------------------------------------------------------------------------------- 1 | #ifndef NETLINK_NEXTHOP_ENCAP_H_ 2 | #define NETLINK_NEXTHOP_ENCAP_H_ 3 | 4 | struct nh_encap_ops { 5 | uint16_t encap_type; 6 | 7 | int (*build_msg)(struct nl_msg *msg, void *priv); 8 | int (*parse_msg)(struct nlattr *nla, struct rtnl_nexthop *rtnh); 9 | 10 | int (*compare)(void *a, void *b); 11 | 12 | void (*dump)(void *priv, struct nl_dump_params *dp); 13 | void (*destructor)(void *priv); 14 | }; 15 | 16 | struct rtnl_nh_encap; 17 | 18 | /* 19 | * generic nexthop encap 20 | */ 21 | void nh_set_encap(struct rtnl_nexthop *nh, struct rtnl_nh_encap *rtnh_encap); 22 | 23 | int nh_encap_parse_msg(struct nlattr *encap, struct nlattr *encap_type, 24 | struct rtnl_nexthop *rtnh); 25 | int nh_encap_build_msg(struct nl_msg *msg, struct rtnl_nh_encap *rtnh_encap); 26 | 27 | void nh_encap_dump(struct rtnl_nh_encap *rtnh_encap, struct nl_dump_params *dp); 28 | 29 | int nh_encap_compare(struct rtnl_nh_encap *a, struct rtnl_nh_encap *b); 30 | 31 | /* 32 | * MPLS encap 33 | */ 34 | extern struct nh_encap_ops mpls_encap_ops; 35 | #endif 36 | -------------------------------------------------------------------------------- /include/netlink/cli/addr.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2008-2009 Thomas Graf 4 | */ 5 | 6 | #ifndef __NETLINK_CLI_ADDR_H_ 7 | #define __NETLINK_CLI_ADDR_H_ 8 | 9 | #include 10 | 11 | #define nl_cli_addr_alloc_cache(sk) \ 12 | nl_cli_alloc_cache((sk), "address", rtnl_addr_alloc_cache) 13 | 14 | extern struct rtnl_addr *nl_cli_addr_alloc(void); 15 | 16 | extern void nl_cli_addr_parse_family(struct rtnl_addr *, char *); 17 | extern void nl_cli_addr_parse_local(struct rtnl_addr *, char *); 18 | extern void nl_cli_addr_parse_dev(struct rtnl_addr *, struct nl_cache *,char *); 19 | extern void nl_cli_addr_parse_label(struct rtnl_addr *, char *); 20 | extern void nl_cli_addr_parse_peer(struct rtnl_addr *, char *); 21 | extern void nl_cli_addr_parse_scope(struct rtnl_addr *, char *); 22 | extern void nl_cli_addr_parse_broadcast(struct rtnl_addr *, char *); 23 | extern void nl_cli_addr_parse_preferred(struct rtnl_addr *, char *); 24 | extern void nl_cli_addr_parse_valid(struct rtnl_addr *, char *); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /doc/doxygen-link.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from __future__ import print_function 4 | import fileinput 5 | import re 6 | import sys 7 | 8 | 9 | rc_script = re.compile(r'\s*(.*\S)?\s*') 10 | 11 | def parse_dict(filename): 12 | links = {} 13 | for line in open(filename, 'r'): 14 | m = re.match('^([^=]+)=([^\n]+)$', line); 15 | if not m: 16 | continue 17 | name = m.group(1) 18 | value = m.group(2) 19 | 20 | # strip leading and trailing whitespace 21 | m = rc_script.match(name) 22 | if m: 23 | name = m.group(1) 24 | 25 | # skip special names 26 | if name == '': 27 | continue 28 | if name == '\\': 29 | continue 30 | 31 | links[name] = "" + name + "" 32 | return links 33 | 34 | links = parse_dict(sys.argv[1]) 35 | 36 | def translate(match): 37 | return links[match.group(1)] 38 | 39 | # match for all names, with word boundaries \b 40 | rc = re.compile(r'\b(' + '|'.join(map(re.escape, sorted(links, reverse=True))) + r')\b') 41 | 42 | for line in open(sys.argv[2], 'r'): 43 | print(rc.sub(translate, line), end='') 44 | -------------------------------------------------------------------------------- /include/netlink/route/act/skbedit.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2015 Cong Wang 4 | */ 5 | 6 | #ifndef NETLINK_SKBEDIT_H_ 7 | #define NETLINK_SKBEDIT_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | extern int rtnl_skbedit_set_action(struct rtnl_act *act, int action); 19 | extern int rtnl_skbedit_get_action(struct rtnl_act *act); 20 | extern int rtnl_skbedit_set_queue_mapping(struct rtnl_act *act, uint16_t index); 21 | extern int rtnl_skbedit_get_queue_mapping(struct rtnl_act *act, uint16_t *index); 22 | extern int rtnl_skbedit_set_mark(struct rtnl_act *act, uint32_t mark); 23 | extern int rtnl_skbedit_get_mark(struct rtnl_act *act, uint32_t *mark); 24 | extern int rtnl_skbedit_set_priority(struct rtnl_act *act, uint32_t prio); 25 | extern int rtnl_skbedit_get_priority(struct rtnl_act *act, uint32_t *prio); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/nl-list-sockets.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2009 Thomas Graf 4 | */ 5 | 6 | #include 7 | 8 | #define PROC_NETLINK "/proc/net/netlink" 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | FILE *fd; 13 | char buf[2048], p[64]; 14 | 15 | fd = fopen(PROC_NETLINK, "re"); 16 | if (fd == NULL) { 17 | perror("fopen"); 18 | return -1; 19 | } 20 | 21 | printf("Address Family PID Groups rmem " 22 | "wmem CB refcnt\n"); 23 | 24 | while (fgets(buf, sizeof(buf), fd)) { 25 | unsigned long sk, cb; 26 | int ret, proto, pid, rmem, wmem, refcnt; 27 | unsigned int groups; 28 | 29 | ret = sscanf(buf, "%lx %d %d %08x %d %d %lx %d\n", 30 | &sk, &proto, &pid, &groups, &rmem, &wmem, 31 | &cb, &refcnt); 32 | if (ret != 8) 33 | continue; 34 | 35 | printf("0x%016lx %-16s %-6d %08x %-6d %-6d 0x%08lx %d\n", 36 | sk, nl_nlfamily2str(proto, p, sizeof(p)), pid, 37 | groups, rmem, wmem, cb, refcnt); 38 | } 39 | 40 | fclose(fd); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /tests/test-create-veth.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | struct rtnl_link *link; 10 | struct nl_sock *sk; 11 | int err; 12 | struct rtnl_link *peer; 13 | 14 | sk = nl_socket_alloc(); 15 | if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { 16 | nl_perror(err, "Unable to connect socket"); 17 | return err; 18 | } 19 | 20 | #if 0 21 | rtnl_link_veth_add(sk, "veth2", "veth3", getpid()); 22 | #else 23 | link = rtnl_link_veth_alloc(); 24 | if (!link) { 25 | nl_perror(err, "Unable to alloc link"); 26 | return err; 27 | } 28 | 29 | rtnl_link_set_name(link, "veth8"); 30 | peer = rtnl_link_veth_get_peer(link); 31 | rtnl_link_set_name(peer, "veth9"); 32 | 33 | if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0) { 34 | nl_perror(err, "Unable to add link"); 35 | return err; 36 | } 37 | printf("peer is %s\n", rtnl_link_get_name(peer)); 38 | rtnl_link_put(peer); 39 | rtnl_link_put(link); 40 | #endif 41 | nl_close(sk); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /include/netlink/route/cls/ematch/meta.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2010 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_CLS_EMATCH_META_H_ 7 | #define NETLINK_CLS_EMATCH_META_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | struct rtnl_meta_value; 18 | 19 | extern struct rtnl_meta_value * rtnl_meta_value_alloc_int(uint64_t); 20 | extern struct rtnl_meta_value * rtnl_meta_value_alloc_var(void *, size_t); 21 | extern struct rtnl_meta_value * rtnl_meta_value_alloc_id(uint8_t, uint16_t, 22 | uint8_t, uint64_t); 23 | extern void rtnl_meta_value_put(struct rtnl_meta_value *); 24 | 25 | extern void rtnl_ematch_meta_set_lvalue(struct rtnl_ematch *, 26 | struct rtnl_meta_value *); 27 | void rtnl_ematch_meta_set_rvalue(struct rtnl_ematch *, 28 | struct rtnl_meta_value *); 29 | extern void rtnl_ematch_meta_set_operand(struct rtnl_ematch *, uint8_t); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/lib/rule.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2008-2009 Thomas Graf 4 | */ 5 | 6 | /** 7 | * @ingroup cli 8 | * @defgroup cli_rule Routing Rules 9 | * 10 | * @{ 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | struct rtnl_rule *nl_cli_rule_alloc(void) 17 | { 18 | struct rtnl_rule *rule; 19 | 20 | rule = rtnl_rule_alloc(); 21 | if (!rule) 22 | nl_cli_fatal(ENOMEM, "Unable to allocate rule object"); 23 | 24 | return rule; 25 | } 26 | 27 | struct nl_cache *nl_cli_rule_alloc_cache(struct nl_sock *sk) 28 | { 29 | struct nl_cache *cache; 30 | int err; 31 | 32 | if ((err = rtnl_rule_alloc_cache(sk, AF_UNSPEC, &cache)) < 0) 33 | nl_cli_fatal(err, "Unable to allocate routing rule cache: %s\n", 34 | nl_geterror(err)); 35 | 36 | nl_cache_mngt_provide(cache); 37 | 38 | return cache; 39 | } 40 | 41 | void nl_cli_rule_parse_family(struct rtnl_rule *rule, char *arg) 42 | { 43 | int family; 44 | 45 | if ((family = nl_str2af(arg)) != AF_UNSPEC) 46 | rtnl_rule_set_family(rule, family); 47 | } 48 | 49 | /** @} */ 50 | -------------------------------------------------------------------------------- /tests/test-create-vlan.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | struct rtnl_link *link; 10 | struct nl_cache *link_cache; 11 | struct nl_sock *sk; 12 | int err, master_index; 13 | 14 | sk = nl_socket_alloc(); 15 | if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { 16 | nl_perror(err, "Unable to connect socket"); 17 | return err; 18 | } 19 | 20 | if ((err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &link_cache)) < 0) { 21 | nl_perror(err, "Unable to allocate cache"); 22 | return err; 23 | } 24 | 25 | if (!(master_index = rtnl_link_name2i(link_cache, "eth0"))) { 26 | fprintf(stderr, "Unable to lookup eth0"); 27 | return -1; 28 | } 29 | 30 | link = rtnl_link_vlan_alloc(); 31 | 32 | rtnl_link_set_link(link, master_index); 33 | 34 | rtnl_link_vlan_set_id(link, 10); 35 | 36 | if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0) { 37 | nl_perror(err, "Unable to add link"); 38 | return err; 39 | } 40 | 41 | rtnl_link_put(link); 42 | nl_close(sk); 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /python/netlink/utils.h: -------------------------------------------------------------------------------- 1 | struct list_head { 2 | struct list_head *next; 3 | }; 4 | 5 | #define LIST_HEAD(name) \ 6 | struct list_head name = { &(name) } 7 | 8 | static inline int list_empty(const struct list_head *head) 9 | { 10 | return head->next == head; 11 | } 12 | 13 | static inline void list_add(struct list_head *new, struct list_head *head) 14 | { 15 | new->next = head->next; 16 | head->next = new; 17 | } 18 | 19 | static inline void list_del(struct list_head *entry, struct list_head *prev) 20 | { 21 | prev->next = entry->next; 22 | entry->next = entry; 23 | } 24 | 25 | #define list_for_each_safe(pos, n, head) \ 26 | for (n = (head), pos = (head)->next; pos != (head); \ 27 | n = pos, pos = n->next) 28 | 29 | #undef offsetof 30 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 31 | 32 | #define container_of(ptr, type, member) ({ \ 33 | const __typeof__( ((type *)0)->member ) *__mptr = (ptr);\ 34 | (type *)( (char *)__mptr - offsetof(type,member) );}) 35 | 36 | #ifdef DEBUG 37 | #define pynl_dbg(fmt, ...) \ 38 | fprintf(stderr, "%s: " fmt, __func__, __VA_ARGS__) 39 | #else 40 | #define pynl_dbg(fmt, ...) 41 | #endif 42 | -------------------------------------------------------------------------------- /include/netlink/route/qdisc/prio.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2011 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_PRIO_H_ 7 | #define NETLINK_PRIO_H_ 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | /** 17 | * @name Default Values 18 | * @{ 19 | */ 20 | 21 | /** 22 | * Default number of bands. 23 | * @ingroup prio 24 | */ 25 | #define QDISC_PRIO_DEFAULT_BANDS 3 26 | 27 | /** 28 | * Default priority mapping. 29 | * @ingroup prio 30 | */ 31 | #define QDISC_PRIO_DEFAULT_PRIOMAP \ 32 | { 1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 } 33 | 34 | /** @} */ 35 | 36 | extern void rtnl_qdisc_prio_set_bands(struct rtnl_qdisc *, int); 37 | extern int rtnl_qdisc_prio_get_bands(struct rtnl_qdisc *); 38 | extern int rtnl_qdisc_prio_set_priomap(struct rtnl_qdisc *, uint8_t[], int); 39 | extern uint8_t *rtnl_qdisc_prio_get_priomap(struct rtnl_qdisc *); 40 | 41 | extern char * rtnl_prio2str(int, char *, size_t); 42 | extern int rtnl_str2prio(const char *); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /include/netlink/route/qdisc/dsmark.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2011 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_DSMARK_H_ 7 | #define NETLINK_DSMARK_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | extern int rtnl_class_dsmark_set_bitmask(struct rtnl_class *, uint8_t); 18 | extern int rtnl_class_dsmark_get_bitmask(struct rtnl_class *); 19 | 20 | extern int rtnl_class_dsmark_set_value(struct rtnl_class *, uint8_t); 21 | extern int rtnl_class_dsmark_get_value(struct rtnl_class *); 22 | 23 | extern int rtnl_qdisc_dsmark_set_indices(struct rtnl_qdisc *, uint16_t); 24 | extern int rtnl_qdisc_dsmark_get_indices(struct rtnl_qdisc *); 25 | 26 | extern int rtnl_qdisc_dsmark_set_default_index(struct rtnl_qdisc *, 27 | uint16_t); 28 | extern int rtnl_qdisc_dsmark_get_default_index(struct rtnl_qdisc *); 29 | 30 | extern int rtnl_qdisc_dsmark_set_set_tc_index(struct rtnl_qdisc *, int); 31 | extern int rtnl_qdisc_dsmark_get_set_tc_index(struct rtnl_qdisc *); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/netlink/route/qdisc/tbf.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2011 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_TBF_H_ 7 | #define NETLINK_TBF_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | extern void rtnl_qdisc_tbf_set_limit(struct rtnl_qdisc *, int); 18 | extern int rtnl_qdisc_tbf_set_limit_by_latency(struct rtnl_qdisc *, int); 19 | extern int rtnl_qdisc_tbf_get_limit(struct rtnl_qdisc *); 20 | 21 | extern void rtnl_qdisc_tbf_set_rate(struct rtnl_qdisc *, int, int, int); 22 | extern int rtnl_qdisc_tbf_get_rate(struct rtnl_qdisc *); 23 | extern int rtnl_qdisc_tbf_get_rate_bucket(struct rtnl_qdisc *); 24 | extern int rtnl_qdisc_tbf_get_rate_cell(struct rtnl_qdisc *); 25 | 26 | extern int rtnl_qdisc_tbf_set_peakrate(struct rtnl_qdisc *, int, int, int); 27 | extern int rtnl_qdisc_tbf_get_peakrate(struct rtnl_qdisc *); 28 | extern int rtnl_qdisc_tbf_get_peakrate_bucket(struct rtnl_qdisc *); 29 | extern int rtnl_qdisc_tbf_get_peakrate_cell(struct rtnl_qdisc *); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /python/doc/route_addr.rst: -------------------------------------------------------------------------------- 1 | ================= 2 | Network Addresses 3 | ================= 4 | 5 | The **Address** module provides access to the network address configuration 6 | of the kernel. It provides an interface to fetch all configured addresses, 7 | add new addresses and to delete existing addresses. 8 | 9 | Fetching the list of network addresses is achieved by creating a new 10 | address cache:: 11 | 12 | import netlink.route.address as Address 13 | 14 | addr_cache = Address.AddressCache() 15 | addr_cache.refill() 16 | 17 | for addr in addr_cache: 18 | print addr 19 | 20 | .. py:module:: netlink.route.addr 21 | 22 | 23 | AddressCache 24 | ------------ 25 | 26 | .. py:class:: AddressCache 27 | 28 | Represents a cache containing all or a subset of network addresses. 29 | 30 | .. py:method:: lookup(ifindex, local) 31 | 32 | Lookup the address which matches ifindex and local address 33 | 34 | :raises: KeyError if address is not found. 35 | 36 | Address 37 | ------- 38 | 39 | .. py:class:: Address 40 | 41 | Representation of a configured network address. 42 | 43 | .. py:attribute:: ifindex 44 | 45 | Interface index 46 | 47 | :rtype: int 48 | -------------------------------------------------------------------------------- /src/nl-link-enslave.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2011 Thomas Graf 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | struct nl_sock *sock; 15 | struct nl_cache *link_cache; 16 | struct rtnl_link *master, *slave; 17 | int err; 18 | 19 | if (argc < 3) { 20 | fprintf(stderr, "Usage: nl-link-enslave master slave\n"); 21 | return 1; 22 | } 23 | 24 | sock = nl_cli_alloc_socket(); 25 | nl_cli_connect(sock, NETLINK_ROUTE); 26 | link_cache = nl_cli_link_alloc_cache(sock); 27 | 28 | if (!(master = rtnl_link_get_by_name(link_cache, argv[1]))) { 29 | fprintf(stderr, "Unknown link: %s\n", argv[1]); 30 | return 1; 31 | } 32 | 33 | if (!(slave = rtnl_link_get_by_name(link_cache, argv[2]))) { 34 | fprintf(stderr, "Unknown link: %s\n", argv[2]); 35 | return 1; 36 | } 37 | 38 | if ((err = rtnl_link_bond_enslave(sock, master, slave)) < 0) { 39 | fprintf(stderr, "Unable to enslave %s to %s: %s\n", 40 | argv[2], argv[1], nl_geterror(err)); 41 | return 1; 42 | } 43 | 44 | return 0; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /include/netlink/cli/link.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2008-2010 Thomas Graf 4 | */ 5 | 6 | #ifndef __NETLINK_CLI_LINK_H_ 7 | #define __NETLINK_CLI_LINK_H_ 8 | 9 | #include 10 | #include 11 | 12 | extern struct rtnl_link *nl_cli_link_alloc(void); 13 | extern struct nl_cache *nl_cli_link_alloc_cache_family(struct nl_sock *, int); 14 | extern struct nl_cache *nl_cli_link_alloc_cache_family_flags(struct nl_sock *, int, 15 | unsigned int); 16 | extern struct nl_cache *nl_cli_link_alloc_cache(struct nl_sock *); 17 | extern struct nl_cache *nl_cli_link_alloc_cache_flags(struct nl_sock *, 18 | unsigned int); 19 | 20 | extern void nl_cli_link_parse_family(struct rtnl_link *, char *); 21 | extern void nl_cli_link_parse_name(struct rtnl_link *, char *); 22 | extern void nl_cli_link_parse_mtu(struct rtnl_link *, char *); 23 | extern void nl_cli_link_parse_ifindex(struct rtnl_link *, char *); 24 | extern void nl_cli_link_parse_txqlen(struct rtnl_link *, char *); 25 | extern void nl_cli_link_parse_weight(struct rtnl_link *, char *); 26 | extern void nl_cli_link_parse_ifalias(struct rtnl_link *, char *); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/netlink/route/act/vlan.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2018 Volodymyr Bendiuga 4 | */ 5 | 6 | #ifndef NETLINK_VLAN_H_ 7 | #define NETLINK_VLAN_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | extern int rtnl_vlan_set_mode(struct rtnl_act *act, int mode); 18 | extern int rtnl_vlan_get_mode(struct rtnl_act *act, int *out_mode); 19 | extern int rtnl_vlan_set_action(struct rtnl_act *act, int action); 20 | extern int rtnl_vlan_get_action(struct rtnl_act *act, int *out_action); 21 | extern int rtnl_vlan_set_protocol(struct rtnl_act *act, uint16_t protocol); 22 | extern int rtnl_vlan_get_protocol(struct rtnl_act *act, uint16_t *out_protocol); 23 | extern int rtnl_vlan_set_vlan_id(struct rtnl_act *act, uint16_t vid); 24 | extern int rtnl_vlan_get_vlan_id(struct rtnl_act *act, uint16_t *out_vid); 25 | extern int rtnl_vlan_set_vlan_prio(struct rtnl_act *act, uint8_t prio); 26 | extern int rtnl_vlan_get_vlan_prio(struct rtnl_act *act, uint8_t *out_prio); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif /* NETLINK_VLAN_H_ */ 33 | -------------------------------------------------------------------------------- /include/netlink/netfilter/nfnl.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2008 Thomas Graf 4 | * Copyright (c) 2007 Philip Craig 5 | * Copyright (c) 2007 Secure Computing Corporation 6 | */ 7 | 8 | #ifndef NETLINK_NFNL_H_ 9 | #define NETLINK_NFNL_H_ 10 | 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #define NFNL_HDRLEN NLMSG_ALIGN(sizeof(struct nfgenmsg)) 18 | #define NFNLMSG_TYPE(subsys, subtype) (((subsys) << 8) | (subtype)) 19 | 20 | extern int nfnl_connect(struct nl_sock *); 21 | 22 | extern uint8_t nfnlmsg_subsys(struct nlmsghdr *); 23 | extern uint8_t nfnlmsg_subtype(struct nlmsghdr *); 24 | extern uint8_t nfnlmsg_family(struct nlmsghdr *); 25 | extern uint16_t nfnlmsg_res_id(struct nlmsghdr *); 26 | 27 | extern int nfnl_send_simple(struct nl_sock *, uint8_t, uint8_t, 28 | int, uint8_t, uint16_t); 29 | extern struct nl_msg * nfnlmsg_alloc_simple(uint8_t, uint8_t, int, 30 | uint8_t, uint16_t); 31 | extern int nfnlmsg_put(struct nl_msg *, uint32_t, uint32_t, 32 | uint8_t, uint8_t, int, uint8_t, uint16_t); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /python/py80211/util/extract.h: -------------------------------------------------------------------------------- 1 | /* 2 | * nl80211 preprocessor template 3 | * 4 | * Copyright 2013 Arend van Spriel 5 | * 6 | * Permission to use, copy, modify, and/or distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | #define __attribute__(x) 19 | #define __read_mostly 20 | #define bool unsigned char 21 | #define __u32 unsigned int 22 | #define __u16 unsigned short 23 | #define __u8 unsigned char 24 | #define __s8 signed char 25 | #define u64 unsigned long long 26 | #define _LINUX_TYPES_H 27 | #define __LINUX_NETLINK_H 28 | #include "nl80211.h" 29 | -------------------------------------------------------------------------------- /tests/test-create-xfrmi.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | struct nl_cache *link_cache; 7 | struct rtnl_link *link; 8 | struct nl_sock *sk; 9 | int err, if_index; 10 | 11 | sk = nl_socket_alloc(); 12 | if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { 13 | nl_perror(err, "Unable to connect socket"); 14 | return err; 15 | } 16 | 17 | err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &link_cache); 18 | if (err < 0) { 19 | nl_perror(err, "Unable to allocate cache"); 20 | return err; 21 | } 22 | 23 | if_index = rtnl_link_name2i(link_cache, "eth0"); 24 | if (!if_index) { 25 | fprintf(stderr, "Unable to lookup eth0"); 26 | return -1; 27 | } 28 | 29 | link = rtnl_link_xfrmi_alloc(); 30 | if (!link) { 31 | nl_perror(err, "Unable to allocate link"); 32 | return -1; 33 | 34 | } 35 | 36 | rtnl_link_set_name(link, "ipsec0"); 37 | rtnl_link_xfrmi_set_link(link, if_index); 38 | rtnl_link_xfrmi_set_if_id(link, 16); 39 | 40 | err = rtnl_link_add(sk, link, NLM_F_CREATE); 41 | if (err < 0) { 42 | nl_perror(err, "Unable to add link"); 43 | return err; 44 | } 45 | 46 | rtnl_link_put(link); 47 | nl_close(sk); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /libnl-genl-3.sym: -------------------------------------------------------------------------------- 1 | libnl_3 { 2 | global: 3 | # these functions are in private header files and should have never 4 | # been exported. We might hide them later. 5 | genl_resolve_id; 6 | 7 | genl_connect; 8 | genl_ctrl_alloc_cache; 9 | genl_ctrl_resolve; 10 | genl_ctrl_resolve_grp; 11 | genl_ctrl_search; 12 | genl_ctrl_search_by_name; 13 | genl_family_add_grp; 14 | genl_family_add_op; 15 | genl_family_alloc; 16 | genl_family_get_hdrsize; 17 | genl_family_get_id; 18 | genl_family_get_maxattr; 19 | genl_family_get_name; 20 | genl_family_get_version; 21 | genl_family_ops; 22 | genl_family_put; 23 | genl_family_set_hdrsize; 24 | genl_family_set_id; 25 | genl_family_set_maxattr; 26 | genl_family_set_name; 27 | genl_family_set_version; 28 | genl_handle_msg; 29 | genl_mngt_resolve; 30 | genl_op2name; 31 | genl_ops_resolve; 32 | genl_register; 33 | genl_register_family; 34 | genl_send_simple; 35 | genl_unregister; 36 | genl_unregister_family; 37 | genlmsg_attrdata; 38 | genlmsg_attrlen; 39 | genlmsg_data; 40 | genlmsg_hdr; 41 | genlmsg_len; 42 | genlmsg_parse; 43 | genlmsg_put; 44 | genlmsg_user_data; 45 | genlmsg_user_datalen; 46 | genlmsg_user_hdr; 47 | genlmsg_valid_hdr; 48 | genlmsg_validate; 49 | local: 50 | *; 51 | }; 52 | -------------------------------------------------------------------------------- /python/py80211/setup.py: -------------------------------------------------------------------------------- 1 | # 2 | # nl80211 package setup script 3 | # 4 | # Copyright 2013 Arend van Spriel 5 | # 6 | # Permission to use, copy, modify, and/or distribute this software for any 7 | # purpose with or without fee is hereby granted, provided that the above 8 | # copyright notice and this permission notice appear in all copies. 9 | # 10 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | # 18 | from distutils.core import setup 19 | 20 | setup(name = 'py80211', 21 | version = '1.0', 22 | description = 'Python package providing access to nl80211 kernel API', 23 | author = 'Arend van Spriel', 24 | author_email = 'aspriel@gmail.com', 25 | package_dir = {'py80211': 'lib'}, 26 | packages = ['py80211','py80211.generated'], 27 | ) 28 | -------------------------------------------------------------------------------- /include/netlink/route/qdisc/hfsc.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2014 Cong Wang 4 | */ 5 | 6 | #ifndef NETLINK_HFSC_H_ 7 | #define NETLINK_HFSC_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | struct tc_service_curve; 19 | 20 | extern uint32_t rtnl_qdisc_hfsc_get_defcls(const struct rtnl_qdisc *); 21 | extern int rtnl_qdisc_hfsc_set_defcls(struct rtnl_qdisc *, uint32_t); 22 | 23 | extern int rtnl_class_hfsc_get_rsc(const struct rtnl_class *cls, struct tc_service_curve *tsc); 24 | extern int rtnl_class_hfsc_set_rsc(struct rtnl_class *cls, const struct tc_service_curve *tsc); 25 | extern int rtnl_class_hfsc_get_fsc(const struct rtnl_class *cls, struct tc_service_curve *tsc); 26 | extern int rtnl_class_hfsc_set_fsc(struct rtnl_class *cls, const struct tc_service_curve *tsc); 27 | extern int rtnl_class_hfsc_get_usc(const struct rtnl_class *cls, struct tc_service_curve *tsc); 28 | extern int rtnl_class_hfsc_set_usc(struct rtnl_class *cls, const struct tc_service_curve *tsc); 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /tests/test-create-ipvlan.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | struct rtnl_link *link; 10 | struct nl_cache *link_cache; 11 | struct nl_sock *sk; 12 | int err, master_index; 13 | 14 | sk = nl_socket_alloc(); 15 | if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { 16 | nl_perror(err, "Unable to connect socket"); 17 | return err; 18 | } 19 | 20 | if ((err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &link_cache)) < 0) { 21 | nl_perror(err, "Unable to allocate cache"); 22 | return err; 23 | } 24 | 25 | if (!(master_index = rtnl_link_name2i(link_cache, "eth0"))) { 26 | fprintf(stderr, "Unable to lookup eth0"); 27 | return -1; 28 | } 29 | 30 | if (!(link = rtnl_link_ipvlan_alloc())) { 31 | fprintf(stderr, "Unable to allocate link"); 32 | return -1; 33 | } 34 | 35 | rtnl_link_set_link(link, master_index); 36 | rtnl_link_ipvlan_set_mode(link, rtnl_link_ipvlan_str2mode("l2")); 37 | 38 | if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0) { 39 | nl_perror(err, "Unable to add link"); 40 | return err; 41 | } 42 | 43 | rtnl_link_put(link); 44 | nl_close(sk); 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /tests/test-create-vxlan.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | struct rtnl_link *link; 10 | struct nl_addr *addr; 11 | struct nl_sock *sk; 12 | int err; 13 | 14 | sk = nl_socket_alloc(); 15 | if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { 16 | nl_perror(err, "Unable to connect socket"); 17 | return err; 18 | } 19 | 20 | link = rtnl_link_vxlan_alloc(); 21 | 22 | rtnl_link_set_name(link, "vxlan128"); 23 | 24 | if ((err = rtnl_link_vxlan_set_id(link, 128)) < 0) { 25 | nl_perror(err, "Unable to set VXLAN network identifier"); 26 | return err; 27 | } 28 | 29 | if ((err = nl_addr_parse("239.0.0.1", AF_INET, &addr)) < 0) { 30 | nl_perror(err, "Unable to parse IP address"); 31 | return err; 32 | } 33 | 34 | if ((err = rtnl_link_vxlan_set_group(link, addr)) < 0) { 35 | nl_perror(err, "Unable to set multicast IP address"); 36 | return err; 37 | } 38 | nl_addr_put(addr); 39 | 40 | if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0) { 41 | nl_perror(err, "Unable to add link"); 42 | return err; 43 | } 44 | 45 | rtnl_link_put(link); 46 | nl_close(sk); 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /include/netlink/cli/tc.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2010-2011 Thomas Graf 4 | */ 5 | 6 | #ifndef __NETLINK_CLI_TC_H_ 7 | #define __NETLINK_CLI_TC_H_ 8 | 9 | #include 10 | 11 | struct rtnl_tc_ops; 12 | 13 | extern void nl_cli_tc_parse_dev(struct rtnl_tc *, struct nl_cache *, char *); 14 | extern void nl_cli_tc_parse_parent(struct rtnl_tc *, char *); 15 | extern void nl_cli_tc_parse_handle(struct rtnl_tc *, char *, int); 16 | extern void nl_cli_tc_parse_mtu(struct rtnl_tc *, char *); 17 | extern void nl_cli_tc_parse_mpu(struct rtnl_tc *, char *); 18 | extern void nl_cli_tc_parse_overhead(struct rtnl_tc *, char *); 19 | extern void nl_cli_tc_parse_linktype(struct rtnl_tc *, char *); 20 | extern void nl_cli_tc_parse_kind(struct rtnl_tc *, char *); 21 | 22 | struct nl_cli_tc_module 23 | { 24 | const char * tm_name; 25 | enum rtnl_tc_type tm_type; 26 | struct rtnl_tc_ops * tm_ops; 27 | void (*tm_parse_argv)(struct rtnl_tc *, int, char **); 28 | struct nl_list_head tm_list; 29 | }; 30 | 31 | extern struct nl_cli_tc_module *nl_cli_tc_lookup(struct rtnl_tc_ops *); 32 | extern void nl_cli_tc_register(struct nl_cli_tc_module *); 33 | extern void nl_cli_tc_unregister(struct nl_cli_tc_module *); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /man/nl-classid-lookup.8: -------------------------------------------------------------------------------- 1 | .TH nl\-classid\-lookup 8 "19 October 2010" "libnl" 2 | .SH NAME 3 | nl\-classid\-lookup - Lookup classid definitions 4 | .SH SYNOPSIS 5 | .B nl\-classid\-lookup 6 | .RB [ \-hv ] 7 | .RB [ \-r ] 8 | .RB [ \-\-raw ] 9 | .I name 10 | 11 | .SH DESCRIPTION 12 | .PP 13 | nl\-classid\-lookup searches the classid database for a matching entry. It is used 14 | to resolve qdisc/class names to classid values and vice versa. 15 | 16 | .SH OPTIONS 17 | .TP 18 | .BR \-\^h " or " \-\-help 19 | Print help text to console and exit. 20 | .TP 21 | .BR \-\^v " or " \-\-version 22 | Print versioning information to console and exit. 23 | .TP 24 | .BR \-\^r " or " \-\-reverse 25 | Do a reverse lookup. Lookup a classid and print its name. 26 | .TP 27 | .B \-\-raw 28 | Print the raw classid in hexadecimal format, do not pretty print it. 29 | 30 | .SH USAGE 31 | .PP 32 | Resolve the qdisc/class name "interactive": 33 | .PP 34 | .RS 35 | # nl\-classid\-lookup interactive 36 | .RE 37 | .PP 38 | Lookup the name of classid 1:2: 39 | .PP 40 | .RS 41 | # nl\-classid\-lookup -r 1:2 42 | .RE 43 | 44 | .SH FILES 45 | .PP 46 | /etc/libnl/classid 47 | 48 | .SH AUTHOR 49 | .PP 50 | Thomas Graf is the original author and current maintainer of libnl and 51 | libnl tools. Many people have contributed to it since. 52 | -------------------------------------------------------------------------------- /lib/route/cls/ematch/container.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2008-2013 Thomas Graf 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | static int container_parse(struct rtnl_ematch *e, void *data, size_t len __attribute__((unused))) 12 | { 13 | /* 14 | The kernel may provide more than 4 bytes of data in the future and we want 15 | older libnl versions to be ok with that. We want interfaces to be growable 16 | so we only ever enforce a minimum data length and copy as much as we are 17 | aware of. Thomas Graf. 18 | */ 19 | memcpy(e->e_data, data, sizeof(uint32_t)); 20 | 21 | return 0; 22 | } 23 | 24 | static int container_fill(struct rtnl_ematch *e, struct nl_msg *msg) 25 | { 26 | return nlmsg_append(msg, e->e_data, sizeof(uint32_t), 0); 27 | } 28 | 29 | static struct rtnl_ematch_ops container_ops = { 30 | .eo_kind = TCF_EM_CONTAINER, 31 | .eo_name = "container", 32 | .eo_minlen = sizeof(uint32_t), 33 | .eo_datalen = sizeof(uint32_t), 34 | .eo_parse = container_parse, 35 | .eo_fill = container_fill, 36 | }; 37 | 38 | static void __init container_init(void) 39 | { 40 | rtnl_ematch_register(&container_ops); 41 | } 42 | -------------------------------------------------------------------------------- /include/netlink/cli/route.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2008-2009 Thomas Graf 4 | */ 5 | 6 | #ifndef __NETLINK_CLI_ROUTE_H_ 7 | #define __NETLINK_CLI_ROUTE_H_ 8 | 9 | #include 10 | 11 | extern struct rtnl_route *nl_cli_route_alloc(void); 12 | 13 | extern struct nl_cache *nl_cli_route_alloc_cache(struct nl_sock *, int); 14 | 15 | extern void nl_cli_route_parse_family(struct rtnl_route *, char *); 16 | extern void nl_cli_route_parse_dst(struct rtnl_route *, char *); 17 | extern void nl_cli_route_parse_src(struct rtnl_route *, char *); 18 | extern void nl_cli_route_parse_pref_src(struct rtnl_route *, char *); 19 | extern void nl_cli_route_parse_metric(struct rtnl_route *, char *); 20 | extern void nl_cli_route_parse_nexthop(struct rtnl_route *, char *, struct nl_cache *); 21 | extern void nl_cli_route_parse_table(struct rtnl_route *, char *); 22 | extern void nl_cli_route_parse_prio(struct rtnl_route *, char *); 23 | extern void nl_cli_route_parse_scope(struct rtnl_route *, char *); 24 | extern void nl_cli_route_parse_protocol(struct rtnl_route *, char *); 25 | extern void nl_cli_route_parse_type(struct rtnl_route *, char *); 26 | extern void nl_cli_route_parse_iif(struct rtnl_route *, char *, struct nl_cache *); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /include/netlink/cli/ct.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2008-2009 Thomas Graf 4 | */ 5 | 6 | #ifndef __NETLINK_CLI_CT_H_ 7 | #define __NETLINK_CLI_CT_H_ 8 | 9 | #include 10 | #include 11 | 12 | extern struct nfnl_ct *nl_cli_ct_alloc(void); 13 | extern struct nl_cache *nl_cli_ct_alloc_cache(struct nl_sock *); 14 | 15 | extern void nl_cli_ct_parse_family(struct nfnl_ct *, char *); 16 | extern void nl_cli_ct_parse_protocol(struct nfnl_ct *, char *); 17 | extern void nl_cli_ct_parse_mark(struct nfnl_ct *, char *); 18 | extern void nl_cli_ct_parse_timeout(struct nfnl_ct *, char *); 19 | extern void nl_cli_ct_parse_id(struct nfnl_ct *, char *); 20 | extern void nl_cli_ct_parse_use(struct nfnl_ct *, char *); 21 | extern void nl_cli_ct_parse_src(struct nfnl_ct *, int, char *); 22 | extern void nl_cli_ct_parse_dst(struct nfnl_ct *, int, char *); 23 | extern void nl_cli_ct_parse_src_port(struct nfnl_ct *, int, char *); 24 | extern void nl_cli_ct_parse_dst_port(struct nfnl_ct *, int, char *); 25 | extern void nl_cli_ct_parse_tcp_state(struct nfnl_ct *, char *); 26 | extern void nl_cli_ct_parse_status(struct nfnl_ct *, char *); 27 | extern void nl_cli_ct_parse_zone(struct nfnl_ct *, char *); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /etc/classid: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # 3 | # ClassID <-> Name Translation Table 4 | # 5 | # This file can be used to assign names to classids for easier reference 6 | # in all libnl tools. 7 | # 8 | # Format: 9 | # # qdisc definition 10 | # # class deifnition 11 | # # class definition referencing an 12 | # existing qdisc definition. 13 | # 14 | # Example: 15 | # 1: top # top -> 1:0 16 | # top:1 interactive # interactive -> 1:1 17 | # top:2 www # www -> 1:2 18 | # top:3 bulk # bulk -> 1:3 19 | # 2:1 test_class # test_class -> 2:1 20 | # 21 | # Illegal Example: 22 | # 30:1 classD 23 | # classD:2 invalidClass # classD refers to a class, not a qdisc 24 | # 25 | ############################################################################### 26 | 27 | # 28 | 29 | # Reserved default classids 30 | 0:0 none 31 | ffff:ffff root 32 | ffff:fff1 ingress 33 | 34 | # 35 | # List your classid definitions here: 36 | # 37 | 38 | 39 | 40 | ############################################################################### 41 | # List of auto-generated classids 42 | # 43 | # DO NOT ADD CLASSID DEFINITIONS BELOW THIS LINE 44 | # 45 | # 46 | -------------------------------------------------------------------------------- /include/netlink/route/link/inet6.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2014 Dan Williams 4 | */ 5 | 6 | #ifndef NETLINK_LINK_INET6_H_ 7 | #define NETLINK_LINK_INET6_H_ 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | const char * rtnl_link_inet6_addrgenmode2str (uint8_t mode, 16 | char *buf, 17 | size_t len); 18 | 19 | uint8_t rtnl_link_inet6_str2addrgenmode (const char *mode); 20 | 21 | extern int rtnl_link_inet6_get_token(struct rtnl_link *, 22 | struct nl_addr **); 23 | 24 | extern int rtnl_link_inet6_set_token(struct rtnl_link *, 25 | struct nl_addr *); 26 | 27 | extern int rtnl_link_inet6_get_addr_gen_mode(struct rtnl_link *, 28 | uint8_t *); 29 | 30 | extern int rtnl_link_inet6_set_addr_gen_mode(struct rtnl_link *, 31 | uint8_t); 32 | 33 | extern int rtnl_link_inet6_get_flags(struct rtnl_link *, 34 | uint32_t *); 35 | 36 | extern int rtnl_link_inet6_set_flags(struct rtnl_link *, 37 | uint32_t); 38 | 39 | /* Link Flags Translations */ 40 | extern char * rtnl_link_inet6_flags2str(int, char *, size_t); 41 | extern int rtnl_link_inet6_str2flags(const char *); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /include/netlink/route/qdisc/fq_codel.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2013 Cong Wang 4 | */ 5 | 6 | #ifndef NETLINK_FQ_CODEL_H_ 7 | #define NETLINK_FQ_CODEL_H_ 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | extern int rtnl_qdisc_fq_codel_set_limit(struct rtnl_qdisc *, int); 17 | extern int rtnl_qdisc_fq_codel_get_limit(struct rtnl_qdisc *); 18 | 19 | extern int rtnl_qdisc_fq_codel_set_target(struct rtnl_qdisc *, uint32_t); 20 | extern uint32_t rtnl_qdisc_fq_codel_get_target(struct rtnl_qdisc *); 21 | 22 | extern int rtnl_qdisc_fq_codel_set_interval(struct rtnl_qdisc *, uint32_t); 23 | extern uint32_t rtnl_qdisc_fq_codel_get_interval(struct rtnl_qdisc *); 24 | 25 | extern int rtnl_qdisc_fq_codel_set_quantum(struct rtnl_qdisc *, uint32_t); 26 | extern uint32_t rtnl_qdisc_fq_codel_get_quantum(struct rtnl_qdisc *); 27 | 28 | extern int rtnl_qdisc_fq_codel_set_flows(struct rtnl_qdisc *, int); 29 | extern int rtnl_qdisc_fq_codel_get_flows(struct rtnl_qdisc *); 30 | 31 | extern int rtnl_qdisc_fq_codel_set_ecn(struct rtnl_qdisc *, int); 32 | extern int rtnl_qdisc_fq_codel_get_ecn(struct rtnl_qdisc *); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /include/netlink/hashtable.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2012 Cumulus Networks, Inc 4 | */ 5 | 6 | #ifndef NETLINK_HASHTABLE_H_ 7 | #define NETLINK_HASHTABLE_H_ 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | typedef struct nl_hash_node { 17 | uint32_t key; 18 | uint32_t key_size; 19 | struct nl_object * obj; 20 | struct nl_hash_node * next; 21 | } nl_hash_node_t; 22 | 23 | typedef struct nl_hash_table { 24 | int size; 25 | nl_hash_node_t ** nodes; 26 | } nl_hash_table_t; 27 | 28 | /* Default hash table size */ 29 | #define NL_MAX_HASH_ENTRIES 1024 30 | 31 | /* Access Functions */ 32 | extern nl_hash_table_t * nl_hash_table_alloc(int size); 33 | extern void nl_hash_table_free(nl_hash_table_t *ht); 34 | 35 | extern int nl_hash_table_add(nl_hash_table_t *ht, 36 | struct nl_object *obj); 37 | extern int nl_hash_table_del(nl_hash_table_t *ht, 38 | struct nl_object *obj); 39 | 40 | extern struct nl_object * nl_hash_table_lookup(nl_hash_table_t *ht, 41 | struct nl_object *obj); 42 | extern uint32_t nl_hash(void *k, size_t length, 43 | uint32_t initval); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif /* NETLINK_HASHTABLE_H_ */ 50 | -------------------------------------------------------------------------------- /include/netlink/fib_lookup/lookup.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2008 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_FIB_LOOKUP_H_ 7 | #define NETLINK_FIB_LOOKUP_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | struct flnl_result; 19 | 20 | extern struct flnl_result * flnl_result_alloc(void); 21 | extern void flnl_result_put(struct flnl_result *); 22 | 23 | extern struct nl_cache * flnl_result_alloc_cache(void); 24 | 25 | extern int flnl_lookup_build_request(struct flnl_request *, 26 | int, 27 | struct nl_msg **); 28 | extern int flnl_lookup(struct nl_sock *, 29 | struct flnl_request *, 30 | struct nl_cache *); 31 | 32 | extern int flnl_result_get_table_id(struct flnl_result *res); 33 | extern int flnl_result_get_prefixlen(struct flnl_result *res); 34 | extern int flnl_result_get_nexthop_sel(struct flnl_result *res); 35 | extern int flnl_result_get_type(struct flnl_result *res); 36 | extern int flnl_result_get_scope(struct flnl_result *res); 37 | extern int flnl_result_get_error(struct flnl_result *res); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /include/netlink/route/cls/ematch/text.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2010 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_CLS_EMATCH_TEXT_H_ 7 | #define NETLINK_CLS_EMATCH_TEXT_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | extern void rtnl_ematch_text_set_from(struct rtnl_ematch *, 18 | uint8_t, uint16_t); 19 | extern uint16_t rtnl_ematch_text_get_from_offset(struct rtnl_ematch *); 20 | extern uint8_t rtnl_ematch_text_get_from_layer(struct rtnl_ematch *); 21 | extern void rtnl_ematch_text_set_to(struct rtnl_ematch *, 22 | uint8_t, uint16_t); 23 | extern uint16_t rtnl_ematch_text_get_to_offset(struct rtnl_ematch *); 24 | extern uint8_t rtnl_ematch_text_get_to_layer(struct rtnl_ematch *); 25 | extern void rtnl_ematch_text_set_pattern(struct rtnl_ematch *, 26 | char *, size_t); 27 | extern char * rtnl_ematch_text_get_pattern(struct rtnl_ematch *); 28 | extern size_t rtnl_ematch_text_get_len(struct rtnl_ematch *); 29 | extern void rtnl_ematch_text_set_algo(struct rtnl_ematch *, const char *); 30 | extern char * rtnl_ematch_text_get_algo(struct rtnl_ematch *); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /tests/test-create-macsec.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | struct rtnl_link *link; 12 | struct nl_cache *link_cache; 13 | struct nl_sock *sk; 14 | int err, master_index; 15 | 16 | sk = nl_socket_alloc(); 17 | if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { 18 | nl_perror(err, "Unable to connect socket"); 19 | return err; 20 | } 21 | 22 | if ((err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &link_cache)) < 0) { 23 | nl_perror(err, "Unable to allocate cache"); 24 | return err; 25 | } 26 | 27 | if (!(master_index = rtnl_link_name2i(link_cache, "eth0"))) { 28 | fprintf(stderr, "Unable to lookup eth0"); 29 | return -1; 30 | } 31 | 32 | 33 | link = rtnl_link_macsec_alloc(); 34 | 35 | rtnl_link_set_link(link, master_index); 36 | 37 | rtnl_link_macsec_set_port(link, 10); 38 | rtnl_link_macsec_set_encrypt(link, 1); 39 | rtnl_link_macsec_set_replay_protect(link, 1); 40 | rtnl_link_macsec_set_window(link, 200); 41 | 42 | if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0) { 43 | nl_perror(err, "Unable to add link"); 44 | return err; 45 | } 46 | 47 | rtnl_link_put(link); 48 | nl_close(sk); 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /tests/test-loopback-up-down.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) 5 | { 6 | struct nl_sock *sk; 7 | struct rtnl_link *link, *change; 8 | struct nl_cache *cache; 9 | int err = 0; 10 | 11 | sk = nl_socket_alloc(); 12 | if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { 13 | nl_perror(err, "Unable to connect socket"); 14 | return err; 15 | } 16 | 17 | if ((err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &cache)) < 0) { 18 | nl_perror(err, "Unable to allocate cache"); 19 | goto out; 20 | } 21 | 22 | if (!(link = rtnl_link_get_by_name(cache, "lo"))) { 23 | fprintf(stderr, "Interface not found\n"); 24 | err = 1; 25 | goto out; 26 | } 27 | 28 | /* exit if the loopback interface is already deactivated */ 29 | err = rtnl_link_get_flags(link); 30 | if (!(err & IFF_UP)) { 31 | err = 0; 32 | goto out; 33 | } 34 | 35 | change = rtnl_link_alloc(); 36 | rtnl_link_unset_flags(change, IFF_UP); 37 | 38 | if ((err = rtnl_link_change(sk, link, change, 0)) < 0) { 39 | nl_perror(err, "Unable to deactivate lo"); 40 | goto out; 41 | } 42 | 43 | rtnl_link_set_flags(change, IFF_UP); 44 | if ((err = rtnl_link_change(sk, link, change, 0)) < 0) { 45 | nl_perror(err, "Unable to activate lo"); 46 | goto out; 47 | } 48 | 49 | err = 0; 50 | 51 | out: 52 | nl_socket_free(sk); 53 | return err; 54 | } 55 | -------------------------------------------------------------------------------- /lib/cli/qdisc/ingress.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2013 Cong Wang 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | static void print_usage(void) 10 | { 11 | printf( 12 | "Usage: nl-qdisc-add [...] ingress\n" 13 | "\n" 14 | "OPTIONS\n" 15 | " --help Show this help text.\n" 16 | "\n" 17 | "EXAMPLE" 18 | " # Attach ingress to eth1\n" 19 | " nl-qdisc-add --dev=eth1 --parent=root ingress\n"); 20 | } 21 | 22 | static void ingress_parse_argv(struct rtnl_tc *tc, int argc, char **argv) 23 | { 24 | for (;;) { 25 | int c, optidx = 0; 26 | static struct option long_opts[] = { 27 | { "help", 0, 0, 'h' }, 28 | { 0, 0, 0, 0 } 29 | }; 30 | 31 | c = getopt_long(argc, argv, "h", long_opts, &optidx); 32 | if (c == -1) 33 | break; 34 | 35 | switch (c) { 36 | case 'h': 37 | print_usage(); 38 | return; 39 | } 40 | } 41 | } 42 | 43 | static struct nl_cli_tc_module ingress_module = 44 | { 45 | .tm_name = "ingress", 46 | .tm_type = RTNL_TC_TYPE_QDISC, 47 | .tm_parse_argv = ingress_parse_argv, 48 | }; 49 | 50 | static void __init ingress_init(void) 51 | { 52 | nl_cli_tc_register(&ingress_module); 53 | } 54 | 55 | static void __exit ingress_exit(void) 56 | { 57 | nl_cli_tc_unregister(&ingress_module); 58 | } 59 | -------------------------------------------------------------------------------- /include/netlink/idiag/meminfo.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2013 Sassano Systems LLC 4 | */ 5 | 6 | #ifndef NETLINK_IDIAGNL_MEMINFO_H_ 7 | #define NETLINK_IDIAGNL_MEMINFO_H_ 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif /* __cplusplus */ 14 | 15 | extern struct nl_object_ops idiagnl_meminfo_obj_ops; 16 | 17 | extern struct idiagnl_meminfo *idiagnl_meminfo_alloc(void); 18 | extern void idiagnl_meminfo_get(struct idiagnl_meminfo *); 19 | extern void idiagnl_meminfo_put(struct idiagnl_meminfo *); 20 | 21 | extern uint32_t idiagnl_meminfo_get_rmem(const struct idiagnl_meminfo *); 22 | extern uint32_t idiagnl_meminfo_get_wmem(const struct idiagnl_meminfo *); 23 | extern uint32_t idiagnl_meminfo_get_fmem(const struct idiagnl_meminfo *); 24 | extern uint32_t idiagnl_meminfo_get_tmem(const struct idiagnl_meminfo *); 25 | 26 | extern void idiagnl_meminfo_set_rmem(struct idiagnl_meminfo *, uint32_t); 27 | extern void idiagnl_meminfo_set_wmem(struct idiagnl_meminfo *, uint32_t); 28 | extern void idiagnl_meminfo_set_fmem(struct idiagnl_meminfo *, uint32_t); 29 | extern void idiagnl_meminfo_set_tmem(struct idiagnl_meminfo *, uint32_t); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif /* __cplusplus */ 34 | 35 | #endif /* NETLINK_IDIAGNL_MEMINFO_H_ */ 36 | -------------------------------------------------------------------------------- /lib/route/qdisc/ingress.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2013 Cong Wang 4 | */ 5 | 6 | /** 7 | * @ingroup qdisc 8 | * @defgroup qdisc_ingress Ingress qdisc 9 | * 10 | * @{ 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | struct dumb { 21 | uint32_t foo; 22 | }; 23 | 24 | static int dumb_msg_parser(struct rtnl_tc *tc, void *data) 25 | { 26 | return 0; 27 | } 28 | 29 | static void dumb_dump_line(struct rtnl_tc *tc, void *data, 30 | struct nl_dump_params *p) 31 | { 32 | } 33 | 34 | static int dumb_msg_fill(struct rtnl_tc *tc, void *data, struct nl_msg *msg) 35 | { 36 | return 0; 37 | } 38 | 39 | static struct rtnl_tc_ops ingress_ops = { 40 | .to_kind = "ingress", 41 | .to_type = RTNL_TC_TYPE_QDISC, 42 | .to_size = sizeof(struct dumb), 43 | .to_msg_parser = dumb_msg_parser, 44 | .to_dump[NL_DUMP_LINE] = dumb_dump_line, 45 | .to_msg_fill = dumb_msg_fill, 46 | }; 47 | 48 | static void __init ingress_init(void) 49 | { 50 | rtnl_tc_register(&ingress_ops); 51 | } 52 | 53 | static void __exit ingress_exit(void) 54 | { 55 | rtnl_tc_unregister(&ingress_ops); 56 | } 57 | 58 | /** @} */ 59 | -------------------------------------------------------------------------------- /include/netlink/route/netconf.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2017 David Ahern 4 | */ 5 | 6 | #ifndef NETCONF_H_ 7 | #define NETCONF_H_ 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | struct rtnl_netconf; 14 | 15 | int rtnl_netconf_alloc_cache(struct nl_sock *sk, struct nl_cache **result); 16 | 17 | struct rtnl_netconf *rtnl_netconf_get_by_idx(struct nl_cache *cache, int family, 18 | int ifindex); 19 | struct rtnl_netconf *rtnl_netconf_get_all(struct nl_cache *cache, 20 | int family); 21 | struct rtnl_netconf *rtnl_netconf_get_default(struct nl_cache *cache, 22 | int family); 23 | void rtnl_netconf_put(struct rtnl_netconf *nc); 24 | 25 | int rtnl_netconf_get_family(struct rtnl_netconf *nc, int *val); 26 | int rtnl_netconf_get_ifindex(struct rtnl_netconf *nc, int *val); 27 | int rtnl_netconf_get_forwarding(struct rtnl_netconf *nc, int *val); 28 | int rtnl_netconf_get_mc_forwarding(struct rtnl_netconf *nc, int *val); 29 | int rtnl_netconf_get_rp_filter(struct rtnl_netconf *nc, int *val); 30 | int rtnl_netconf_get_proxy_neigh(struct rtnl_netconf *nc, int *val); 31 | int rtnl_netconf_get_ignore_routes_linkdown(struct rtnl_netconf *nc, int *val); 32 | int rtnl_netconf_get_input(struct rtnl_netconf *nc, int *val); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lib/cli/qdisc/blackhole.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2010-2011 Thomas Graf 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | static void print_usage(void) 10 | { 11 | printf( 12 | "Usage: nl-qdisc-add [...] blackhole [OPTIONS]...\n" 13 | "\n" 14 | "OPTIONS\n" 15 | " --help Show this help text.\n" 16 | "\n" 17 | "EXAMPLE" 18 | " # Drop all outgoing packets on eth1\n" 19 | " nl-qdisc-add --dev=eth1 --parent=root blackhole\n"); 20 | } 21 | 22 | static void blackhole_parse_argv(struct rtnl_tc *tc, int argc, char **argv) 23 | { 24 | for (;;) { 25 | int c, optidx = 0; 26 | static struct option long_opts[] = { 27 | { "help", 0, 0, 'h' }, 28 | { 0, 0, 0, 0 } 29 | }; 30 | 31 | c = getopt_long(argc, argv, "h", long_opts, &optidx); 32 | if (c == -1) 33 | break; 34 | 35 | switch (c) { 36 | case 'h': 37 | print_usage(); 38 | return; 39 | } 40 | } 41 | } 42 | 43 | static struct nl_cli_tc_module blackhole_module = 44 | { 45 | .tm_name = "blackhole", 46 | .tm_type = RTNL_TC_TYPE_QDISC, 47 | .tm_parse_argv = blackhole_parse_argv, 48 | }; 49 | 50 | static void __init blackhole_init(void) 51 | { 52 | nl_cli_tc_register(&blackhole_module); 53 | } 54 | 55 | static void __exit blackhole_exit(void) 56 | { 57 | nl_cli_tc_unregister(&blackhole_module); 58 | } 59 | -------------------------------------------------------------------------------- /include/netlink/route/link/ipvti.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2014 Susant Sahani 4 | */ 5 | 6 | #ifndef NETLINK_LINK_IPVTI_H_ 7 | #define NETLINK_LINK_IPVTI_H_ 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | extern struct rtnl_link *rtnl_link_ipvti_alloc(void); 16 | extern int rtnl_link_ipvti_add(struct nl_sock *sk, const char *name); 17 | 18 | extern int rtnl_link_is_ipvti(struct rtnl_link *link); 19 | 20 | extern int rtnl_link_ipvti_set_link(struct rtnl_link *link, uint32_t index); 21 | extern uint32_t rtnl_link_ipvti_get_link(struct rtnl_link *link); 22 | 23 | extern int rtnl_link_ipvti_set_ikey(struct rtnl_link *link, uint32_t ikey); 24 | extern uint32_t rtnl_link_ipvti_get_ikey(struct rtnl_link *link); 25 | 26 | extern int rtnl_link_ipvti_set_okey(struct rtnl_link *link, uint32_t okey); 27 | extern uint32_t rtnl_link_ipvti_get_okey(struct rtnl_link *link); 28 | 29 | extern int rtnl_link_ipvti_set_local(struct rtnl_link *link, uint32_t addr); 30 | extern uint32_t rtnl_link_ipvti_get_local(struct rtnl_link *link); 31 | 32 | extern int rtnl_link_ipvti_set_remote(struct rtnl_link *link, uint32_t addr); 33 | extern uint32_t rtnl_link_ipvti_get_remote(struct rtnl_link *link); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /tests/test-create-macvtap.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | struct rtnl_link *link; 12 | struct nl_cache *link_cache; 13 | struct nl_sock *sk; 14 | struct nl_addr* addr; 15 | int err, master_index; 16 | 17 | sk = nl_socket_alloc(); 18 | if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { 19 | nl_perror(err, "Unable to connect socket"); 20 | return err; 21 | } 22 | 23 | if ((err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &link_cache)) < 0) { 24 | nl_perror(err, "Unable to allocate cache"); 25 | return err; 26 | } 27 | 28 | if (!(master_index = rtnl_link_name2i(link_cache, "eth0"))) { 29 | fprintf(stderr, "Unable to lookup eth0"); 30 | return -1; 31 | } 32 | 33 | link = rtnl_link_macvtap_alloc(); 34 | 35 | rtnl_link_set_link(link, master_index); 36 | 37 | addr = nl_addr_build(AF_LLC, ether_aton("00:11:22:33:44:55"), ETH_ALEN); 38 | rtnl_link_set_addr(link, addr); 39 | nl_addr_put(addr); 40 | 41 | rtnl_link_macvtap_set_mode(link, rtnl_link_macvtap_str2mode("bridge")); 42 | 43 | if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0) { 44 | nl_perror(err, "Unable to add link"); 45 | return err; 46 | } 47 | 48 | rtnl_link_put(link); 49 | nl_close(sk); 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /include/netlink-private/tc.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2013 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_TC_PRIV_H_ 7 | #define NETLINK_TC_PRIV_H_ 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #define TCA_ATTR_HANDLE 0x0001 16 | #define TCA_ATTR_PARENT 0x0002 17 | #define TCA_ATTR_IFINDEX 0x0004 18 | #define TCA_ATTR_KIND 0x0008 19 | #define TCA_ATTR_FAMILY 0x0010 20 | #define TCA_ATTR_INFO 0x0020 21 | #define TCA_ATTR_OPTS 0x0040 22 | #define TCA_ATTR_STATS 0x0080 23 | #define TCA_ATTR_XSTATS 0x0100 24 | #define TCA_ATTR_LINK 0x0200 25 | #define TCA_ATTR_MTU 0x0400 26 | #define TCA_ATTR_MPU 0x0800 27 | #define TCA_ATTR_OVERHEAD 0x1000 28 | #define TCA_ATTR_LINKTYPE 0x2000 29 | #define TCA_ATTR_CHAIN 0x4000 30 | #define TCA_ATTR_MAX TCA_ATTR_CHAIN 31 | 32 | extern int tca_parse(struct nlattr **, int, struct rtnl_tc *, 33 | const struct nla_policy *); 34 | 35 | #define RTNL_TC_RTABLE_SIZE 256 36 | 37 | extern int rtnl_tc_build_rate_table(struct rtnl_tc *tc, struct rtnl_ratespec *, 38 | uint32_t *); 39 | 40 | 41 | static inline void *tca_xstats(struct rtnl_tc *tca) 42 | { 43 | return tca->tc_xstats->d_data; 44 | } 45 | 46 | extern struct nl_af_group tc_groups[]; 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /tests/test-create-macvlan.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | struct rtnl_link *link; 12 | struct nl_cache *link_cache; 13 | struct nl_sock *sk; 14 | struct nl_addr* addr; 15 | int err, master_index; 16 | 17 | sk = nl_socket_alloc(); 18 | if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { 19 | nl_perror(err, "Unable to connect socket"); 20 | return err; 21 | } 22 | 23 | if ((err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &link_cache)) < 0) { 24 | nl_perror(err, "Unable to allocate cache"); 25 | return err; 26 | } 27 | 28 | if (!(master_index = rtnl_link_name2i(link_cache, "eth0"))) { 29 | fprintf(stderr, "Unable to lookup eth0"); 30 | return -1; 31 | } 32 | 33 | link = rtnl_link_macvlan_alloc(); 34 | 35 | rtnl_link_set_link(link, master_index); 36 | 37 | addr = nl_addr_build(AF_LLC, ether_aton("00:11:22:33:44:55"), ETH_ALEN); 38 | rtnl_link_set_addr(link, addr); 39 | nl_addr_put(addr); 40 | 41 | rtnl_link_macvlan_set_mode(link, rtnl_link_macvlan_str2mode("bridge")); 42 | 43 | if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0) { 44 | nl_perror(err, "Unable to add link"); 45 | return err; 46 | } 47 | 48 | rtnl_link_put(link); 49 | nl_close(sk); 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /include/netlink/route/rtnl.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2008 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_RTNL_H_ 7 | #define NETLINK_RTNL_H_ 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | /** 16 | * @name Realms 17 | * @{ 18 | */ 19 | 20 | /** 21 | * Mask specying the size of each realm part 22 | * @ingroup rtnl 23 | */ 24 | #define RTNL_REALM_MASK (0xFFFF) 25 | 26 | /** 27 | * Extract FROM realm from a realms field 28 | */ 29 | #define RTNL_REALM_FROM(realm) ((realm) >> 16) 30 | 31 | /** 32 | * Extract TO realm from a realms field 33 | */ 34 | #define RTNL_REALM_TO(realm) ((realm) & RTNL_REALM_MASK) 35 | 36 | /** 37 | * Build a realms field 38 | */ 39 | #define RTNL_MAKE_REALM(from, to) \ 40 | ((RTNL_REALM_TO(from) << 16) & RTNL_REALM_TO(to)) 41 | 42 | /** @} */ 43 | 44 | 45 | /* General */ 46 | extern int nl_rtgen_request(struct nl_sock *, int, int, int); 47 | 48 | /* Routing Type Translations */ 49 | extern char * nl_rtntype2str(int, char *, size_t); 50 | extern int nl_str2rtntype(const char *); 51 | 52 | /* Scope Translations */ 53 | extern char * rtnl_scope2str(int, char *, size_t); 54 | extern int rtnl_str2scope(const char *); 55 | 56 | /* Realms Translations */ 57 | extern char * rtnl_realms2str(uint32_t, char *, size_t); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /include/netlink/genl/family.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2012 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_GENL_FAMILY_H_ 7 | #define NETLINK_GENL_FAMILY_H_ 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | struct genl_family; 17 | 18 | extern struct genl_family * genl_family_alloc(void); 19 | extern void genl_family_put(struct genl_family *); 20 | 21 | extern unsigned int genl_family_get_id(struct genl_family *); 22 | extern void genl_family_set_id(struct genl_family *, unsigned int); 23 | extern char * genl_family_get_name(struct genl_family *); 24 | extern void genl_family_set_name(struct genl_family *, const char *); 25 | extern uint8_t genl_family_get_version(struct genl_family *); 26 | extern void genl_family_set_version(struct genl_family *, uint8_t); 27 | extern uint32_t genl_family_get_hdrsize(struct genl_family *); 28 | extern void genl_family_set_hdrsize(struct genl_family *, uint32_t); 29 | extern uint32_t genl_family_get_maxattr(struct genl_family *); 30 | extern void genl_family_set_maxattr(struct genl_family *, uint32_t); 31 | 32 | extern int genl_family_add_op(struct genl_family *, int, int); 33 | extern int genl_family_add_grp(struct genl_family *, uint32_t , 34 | const char *); 35 | 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /lib/route/pktloc_grammar.l: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "pktloc_syntax.h" 9 | 10 | int pktloc_get_column(yyscan_t); 11 | void pktloc_set_column(int, yyscan_t); 12 | %} 13 | 14 | %option 8bit 15 | %option reentrant 16 | %option warn 17 | %option noyywrap 18 | %option noinput 19 | %option nounput 20 | %option bison-bridge 21 | %option bison-locations 22 | %option prefix="pktloc_" 23 | 24 | %% 25 | 26 | [ \t\r\n]+ 27 | 28 | "#".* 29 | 30 | [[:digit:]]+ | 31 | 0[xX][[:xdigit:]]+ { 32 | yylval->i = strtoul(yytext, NULL, 0); 33 | return NUMBER; 34 | } 35 | 36 | "+" { return yylval->i = yytext[0]; } 37 | 38 | [uU]8 { yylval->i = TCF_EM_ALIGN_U8; return ALIGN; } 39 | [uU]16 { yylval->i = TCF_EM_ALIGN_U16; return ALIGN; } 40 | [uU]32 { yylval->i = TCF_EM_ALIGN_U32; return ALIGN; } 41 | 42 | [lL][iI][nN][kK] | 43 | [eE][tT][hH] { yylval->i = TCF_LAYER_LINK; return LAYER; } 44 | [nN][eE][tT] | 45 | [iI][pP] { yylval->i = TCF_LAYER_NETWORK; return LAYER; } 46 | [tT][rR][aA][nN][sS][pP][oO][rR][tT] | 47 | [tT][cC][pP] { yylval->i = TCF_LAYER_TRANSPORT; return LAYER; } 48 | 49 | 50 | [^ \t\r\n+]+ { 51 | yylval->s = strdup(yytext); 52 | if (yylval->s == NULL) 53 | return ERROR; 54 | return NAME; 55 | } 56 | -------------------------------------------------------------------------------- /tests/test-create-ipvti.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | struct nl_cache *link_cache; 7 | struct rtnl_link *link; 8 | struct in_addr addr; 9 | struct nl_sock *sk; 10 | int err, if_index; 11 | 12 | sk = nl_socket_alloc(); 13 | if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { 14 | nl_perror(err, "Unable to connect socket"); 15 | return err; 16 | } 17 | 18 | err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &link_cache); 19 | if ( err < 0) { 20 | nl_perror(err, "Unable to allocate cache"); 21 | return err; 22 | } 23 | 24 | if_index = rtnl_link_name2i(link_cache, "ens33"); 25 | if (!if_index) { 26 | fprintf(stderr, "Unable to lookup ens33"); 27 | return -1; 28 | } 29 | 30 | link = rtnl_link_ipvti_alloc(); 31 | if(!link) { 32 | nl_perror(err, "Unable to allocate link"); 33 | return -1; 34 | 35 | } 36 | rtnl_link_set_name(link, "ipvti-tun"); 37 | rtnl_link_ipvti_set_link(link, if_index); 38 | 39 | inet_pton(AF_INET, "192.168.254.12", &addr.s_addr); 40 | rtnl_link_ipvti_set_local(link, addr.s_addr); 41 | 42 | inet_pton(AF_INET, "192.168.254.13", &addr.s_addr); 43 | rtnl_link_ipvti_set_remote(link, addr.s_addr); 44 | 45 | err = rtnl_link_add(sk, link, NLM_F_CREATE); 46 | if (err < 0) { 47 | nl_perror(err, "Unable to add link"); 48 | return err; 49 | } 50 | 51 | rtnl_link_put(link); 52 | nl_close(sk); 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /tests/test-create-ip6tnl.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | struct nl_cache *link_cache; 7 | struct rtnl_link *link; 8 | struct in6_addr addr; 9 | struct nl_sock *sk; 10 | int err, if_index; 11 | 12 | sk = nl_socket_alloc(); 13 | if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { 14 | nl_perror(err, "Unable to connect socket"); 15 | return err; 16 | } 17 | 18 | err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &link_cache); 19 | if ( err < 0) { 20 | nl_perror(err, "Unable to allocate cache"); 21 | return err; 22 | } 23 | 24 | if_index = rtnl_link_name2i(link_cache, "ens33"); 25 | if (!if_index) { 26 | fprintf(stderr, "Unable to lookup ens33"); 27 | return -1; 28 | } 29 | 30 | link = rtnl_link_ip6_tnl_alloc(); 31 | if(!link) { 32 | nl_perror(err, "Unable to allocate link"); 33 | return -1; 34 | 35 | } 36 | rtnl_link_set_name(link, "ip6tnl-tun"); 37 | rtnl_link_ip6_tnl_set_link(link, if_index); 38 | 39 | inet_pton(AF_INET6, "2607:f0d0:1002:51::4", &addr); 40 | rtnl_link_ip6_tnl_set_local(link, &addr); 41 | 42 | inet_pton(AF_INET6, "2607:f0d0:1002:52::5", &addr); 43 | rtnl_link_ip6_tnl_set_remote(link, &addr); 44 | 45 | err = rtnl_link_add(sk, link, NLM_F_CREATE); 46 | if (err < 0) { 47 | nl_perror(err, "Unable to add link"); 48 | return err; 49 | } 50 | 51 | rtnl_link_put(link); 52 | nl_close(sk); 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /include/netlink/fib_lookup/request.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2006 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_FIB_LOOKUP_REQUEST_H_ 7 | #define NETLINK_FIB_LOOKUP_REQUEST_H_ 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | struct flnl_request; 17 | 18 | #define REQUEST_CAST(ptr) ((struct flnl_request *) (ptr)) 19 | 20 | extern struct flnl_request * flnl_request_alloc(void); 21 | 22 | extern void flnl_request_set_fwmark(struct flnl_request *, 23 | uint64_t); 24 | extern uint64_t flnl_request_get_fwmark(struct flnl_request *); 25 | extern void flnl_request_set_tos(struct flnl_request *, 26 | int); 27 | extern int flnl_request_get_tos(struct flnl_request *); 28 | extern void flnl_request_set_scope(struct flnl_request *, 29 | int); 30 | extern int flnl_request_get_scope(struct flnl_request *); 31 | extern void flnl_request_set_table(struct flnl_request *, 32 | int); 33 | extern int flnl_request_get_table(struct flnl_request *); 34 | extern int flnl_request_set_addr(struct flnl_request *, 35 | struct nl_addr *); 36 | extern struct nl_addr * flnl_request_get_addr(struct flnl_request *); 37 | 38 | extern int flnl_request_cmp(struct flnl_request *, 39 | struct flnl_request *); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /tests/test-nf-cache-mngr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | static void change_cb(struct nl_cache *cache, struct nl_object *obj, 6 | int action, void *data) 7 | { 8 | struct nfnl_ct *ct = (struct nfnl_ct *) obj; 9 | static struct nl_addr *hack = NULL; 10 | 11 | if (!hack) 12 | nl_addr_parse("194.88.212.233", AF_INET, &hack); 13 | 14 | if (!nl_addr_cmp(hack, nfnl_ct_get_src(ct, 1)) || 15 | !nl_addr_cmp(hack, nfnl_ct_get_dst(ct, 1))) { 16 | struct nl_dump_params dp = { 17 | .dp_type = NL_DUMP_LINE, 18 | .dp_fd = stdout, 19 | }; 20 | 21 | printf("UPDATE "); 22 | nl_object_dump(obj, &dp); 23 | } 24 | } 25 | 26 | int main(int argc, char *argv[]) 27 | { 28 | struct nl_cache_mngr *mngr; 29 | struct nl_sock *sock; 30 | struct nl_cache *ct; 31 | int err; 32 | 33 | sock = nl_cli_alloc_socket(); 34 | 35 | err = nl_cache_mngr_alloc(sock, NETLINK_NETFILTER, NL_AUTO_PROVIDE, &mngr); 36 | if (err < 0) { 37 | nl_perror(err, "nl_cache_mngr_alloc"); 38 | return -1; 39 | } 40 | 41 | err = nl_cache_mngr_add(mngr, "netfilter/ct", &change_cb, NULL, &ct); 42 | if (err < 0) { 43 | nl_perror(err, "nl_cache_mngr_add(netfilter/ct)"); 44 | return -1; 45 | } 46 | 47 | for (;;) { 48 | int err = nl_cache_mngr_poll(mngr, 5000); 49 | if (err < 0) { 50 | nl_perror(err, "nl_cache_mngr_poll()"); 51 | return -1; 52 | } 53 | 54 | } 55 | 56 | nl_cache_mngr_free(mngr); 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /include/netlink/route/link/macvtap.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2015 Beniamino Galvani 4 | */ 5 | 6 | #ifndef NETLINK_LINK_MACVTAP_H_ 7 | #define NETLINK_LINK_MACVTAP_H_ 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | extern struct rtnl_link *rtnl_link_macvtap_alloc(void); 17 | 18 | extern int rtnl_link_is_macvtap(struct rtnl_link *); 19 | 20 | extern char * rtnl_link_macvtap_mode2str(int, char *, size_t); 21 | extern int rtnl_link_macvtap_str2mode(const char *); 22 | 23 | extern char * rtnl_link_macvtap_flags2str(int, char *, size_t); 24 | extern int rtnl_link_macvtap_str2flags(const char *); 25 | 26 | extern int rtnl_link_macvtap_set_mode(struct rtnl_link *, 27 | uint32_t); 28 | extern uint32_t rtnl_link_macvtap_get_mode(struct rtnl_link *); 29 | 30 | extern int rtnl_link_macvtap_set_flags(struct rtnl_link *, 31 | uint16_t); 32 | extern int rtnl_link_macvtap_unset_flags(struct rtnl_link *, 33 | uint16_t); 34 | extern uint16_t rtnl_link_macvtap_get_flags(struct rtnl_link *); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /tests/test-create-sit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | struct nl_cache *link_cache; 7 | struct rtnl_link *link; 8 | struct in_addr addr; 9 | struct nl_sock *sk; 10 | int err, if_index; 11 | 12 | sk = nl_socket_alloc(); 13 | if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { 14 | nl_perror(err, "Unable to connect socket"); 15 | return err; 16 | } 17 | 18 | err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &link_cache); 19 | if ( err < 0) { 20 | nl_perror(err, "Unable to allocate cache"); 21 | return err; 22 | } 23 | 24 | if_index = rtnl_link_name2i(link_cache, "eno16777736"); 25 | if (!if_index) { 26 | fprintf(stderr, "Unable to lookup eno16777736"); 27 | return -1; 28 | } 29 | 30 | link = rtnl_link_sit_alloc(); 31 | if(!link) { 32 | nl_perror(err, "Unable to allocate link"); 33 | return -1; 34 | 35 | } 36 | rtnl_link_set_name(link, "sit-tun"); 37 | rtnl_link_sit_set_link(link, if_index); 38 | 39 | inet_pton(AF_INET, "192.168.254.12", &addr.s_addr); 40 | rtnl_link_sit_set_local(link, addr.s_addr); 41 | 42 | inet_pton(AF_INET, "192.168.254.13", &addr.s_addr); 43 | rtnl_link_sit_set_remote(link, addr.s_addr); 44 | 45 | rtnl_link_sit_set_ttl(link, 64); 46 | err = rtnl_link_add(sk, link, NLM_F_CREATE); 47 | if (err < 0) { 48 | nl_perror(err, "Unable to add link"); 49 | return err; 50 | } 51 | 52 | rtnl_link_put(link); 53 | nl_close(sk); 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /tests/test-create-ipgretap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | struct nl_cache *link_cache; 7 | struct rtnl_link *link; 8 | struct in_addr addr; 9 | struct nl_sock *sk; 10 | int err, if_index; 11 | 12 | sk = nl_socket_alloc(); 13 | if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { 14 | nl_perror(err, "Unable to connect socket"); 15 | return err; 16 | } 17 | 18 | err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &link_cache); 19 | if ( err < 0) { 20 | nl_perror(err, "Unable to allocate cache"); 21 | return err; 22 | } 23 | 24 | if_index = rtnl_link_name2i(link_cache, "enp0s5"); 25 | if (!if_index) { 26 | fprintf(stderr, "Unable to lookup enp0s5"); 27 | return -1; 28 | } 29 | 30 | link = rtnl_link_ipgretap_alloc(); 31 | if(!link) { 32 | nl_perror(err, "Unable to allocate link"); 33 | return -1; 34 | 35 | } 36 | rtnl_link_set_name(link, "ipgre-tap"); 37 | rtnl_link_ipgre_set_link(link, if_index); 38 | 39 | inet_pton(AF_INET, "10.211.55.10", &addr.s_addr); 40 | rtnl_link_ipgre_set_local(link, addr.s_addr); 41 | 42 | inet_pton(AF_INET, "10.133.6.33", &addr.s_addr); 43 | rtnl_link_ipgre_set_remote(link, addr.s_addr); 44 | 45 | rtnl_link_ipgre_set_ttl(link, 64); 46 | err = rtnl_link_add(sk, link, NLM_F_CREATE); 47 | if (err < 0) { 48 | nl_perror(err, "Unable to add link"); 49 | return err; 50 | } 51 | 52 | rtnl_link_put(link); 53 | nl_close(sk); 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /tests/test-create-ipip.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | struct nl_cache *link_cache; 7 | struct rtnl_link *link; 8 | struct in_addr addr; 9 | struct nl_sock *sk; 10 | int err, if_index; 11 | 12 | sk = nl_socket_alloc(); 13 | if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { 14 | nl_perror(err, "Unable to connect socket"); 15 | return err; 16 | } 17 | 18 | err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &link_cache); 19 | if ( err < 0) { 20 | nl_perror(err, "Unable to allocate cache"); 21 | return err; 22 | } 23 | 24 | if_index = rtnl_link_name2i(link_cache, "eno16777736"); 25 | if (!if_index) { 26 | fprintf(stderr, "Unable to lookup eno16777736"); 27 | return -1; 28 | } 29 | 30 | link = rtnl_link_ipip_alloc(); 31 | if(!link) { 32 | nl_perror(err, "Unable to allocate link"); 33 | return -1; 34 | } 35 | 36 | rtnl_link_set_name(link, "ipip-tun"); 37 | rtnl_link_ipip_set_link(link, if_index); 38 | 39 | inet_pton(AF_INET, "192.168.254.12", &addr.s_addr); 40 | rtnl_link_ipip_set_local(link, addr.s_addr); 41 | 42 | inet_pton(AF_INET, "192.168.254.13", &addr.s_addr); 43 | rtnl_link_ipip_set_remote(link, addr.s_addr); 44 | 45 | rtnl_link_ipip_set_ttl(link, 64); 46 | err = rtnl_link_add(sk, link, NLM_F_CREATE); 47 | if (err < 0) { 48 | nl_perror(err, "Unable to add link"); 49 | return err; 50 | } 51 | 52 | rtnl_link_put(link); 53 | nl_close(sk); 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /lib/netfilter/netfilter.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2008 Patrick McHardy 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | static const struct trans_tbl nfnl_verdicts[] = { 11 | __ADD(NF_DROP, NF_DROP), 12 | __ADD(NF_ACCEPT, NF_ACCEPT), 13 | __ADD(NF_STOLEN, NF_STOLEN), 14 | __ADD(NF_QUEUE, NF_QUEUE), 15 | __ADD(NF_REPEAT, NF_REPEAT), 16 | __ADD(NF_STOP, NF_STOP), 17 | }; 18 | 19 | char *nfnl_verdict2str(unsigned int verdict, char *buf, size_t len) 20 | { 21 | return __type2str(verdict, buf, len, nfnl_verdicts, 22 | ARRAY_SIZE(nfnl_verdicts)); 23 | } 24 | 25 | unsigned int nfnl_str2verdict(const char *name) 26 | { 27 | return __str2type(name, nfnl_verdicts, ARRAY_SIZE(nfnl_verdicts)); 28 | } 29 | 30 | static const struct trans_tbl nfnl_inet_hooks[] = { 31 | __ADD(NF_INET_PRE_ROUTING, NF_INET_PREROUTING), 32 | __ADD(NF_INET_LOCAL_IN, NF_INET_LOCAL_IN), 33 | __ADD(NF_INET_FORWARD, NF_INET_FORWARD), 34 | __ADD(NF_INET_LOCAL_OUT, NF_INET_LOCAL_OUT), 35 | __ADD(NF_INET_POST_ROUTING, NF_INET_POST_ROUTING), 36 | }; 37 | 38 | char *nfnl_inet_hook2str(unsigned int hook, char *buf, size_t len) 39 | { 40 | return __type2str(hook, buf, len, nfnl_inet_hooks, 41 | ARRAY_SIZE(nfnl_inet_hooks)); 42 | } 43 | 44 | unsigned int nfnl_str2inet_hook(const char *name) 45 | { 46 | return __str2type(name, nfnl_inet_hooks, ARRAY_SIZE(nfnl_inet_hooks)); 47 | } 48 | -------------------------------------------------------------------------------- /tests/test-create-ipgre.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | struct nl_cache *link_cache; 7 | struct rtnl_link *link; 8 | struct in_addr addr; 9 | struct nl_sock *sk; 10 | int err, if_index; 11 | 12 | sk = nl_socket_alloc(); 13 | if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { 14 | nl_perror(err, "Unable to connect socket"); 15 | return err; 16 | } 17 | 18 | err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &link_cache); 19 | if ( err < 0) { 20 | nl_perror(err, "Unable to allocate cache"); 21 | return err; 22 | } 23 | 24 | if_index = rtnl_link_name2i(link_cache, "eno16777736"); 25 | if (!if_index) { 26 | fprintf(stderr, "Unable to lookup eno16777736"); 27 | return -1; 28 | } 29 | 30 | link = rtnl_link_ipgre_alloc(); 31 | if(!link) { 32 | nl_perror(err, "Unable to allocate link"); 33 | return -1; 34 | 35 | } 36 | rtnl_link_set_name(link, "ipgre-tun"); 37 | rtnl_link_ipgre_set_link(link, if_index); 38 | 39 | inet_pton(AF_INET, "192.168.254.12", &addr.s_addr); 40 | rtnl_link_ipgre_set_local(link, addr.s_addr); 41 | 42 | inet_pton(AF_INET, "192.168.254.13", &addr.s_addr); 43 | rtnl_link_ipgre_set_remote(link, addr.s_addr); 44 | 45 | rtnl_link_ipgre_set_ttl(link, 64); 46 | err = rtnl_link_add(sk, link, NLM_F_CREATE); 47 | if (err < 0) { 48 | nl_perror(err, "Unable to add link"); 49 | return err; 50 | } 51 | 52 | rtnl_link_put(link); 53 | nl_close(sk); 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /include/netlink/errno.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2008 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_ERRNO_H_ 7 | #define NETLINK_ERRNO_H_ 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | #define NLE_SUCCESS 0 14 | #define NLE_FAILURE 1 15 | #define NLE_INTR 2 16 | #define NLE_BAD_SOCK 3 17 | #define NLE_AGAIN 4 18 | #define NLE_NOMEM 5 19 | #define NLE_EXIST 6 20 | #define NLE_INVAL 7 21 | #define NLE_RANGE 8 22 | #define NLE_MSGSIZE 9 23 | #define NLE_OPNOTSUPP 10 24 | #define NLE_AF_NOSUPPORT 11 25 | #define NLE_OBJ_NOTFOUND 12 26 | #define NLE_NOATTR 13 27 | #define NLE_MISSING_ATTR 14 28 | #define NLE_AF_MISMATCH 15 29 | #define NLE_SEQ_MISMATCH 16 30 | #define NLE_MSG_OVERFLOW 17 31 | #define NLE_MSG_TRUNC 18 32 | #define NLE_NOADDR 19 33 | #define NLE_SRCRT_NOSUPPORT 20 34 | #define NLE_MSG_TOOSHORT 21 35 | #define NLE_MSGTYPE_NOSUPPORT 22 36 | #define NLE_OBJ_MISMATCH 23 37 | #define NLE_NOCACHE 24 38 | #define NLE_BUSY 25 39 | #define NLE_PROTO_MISMATCH 26 40 | #define NLE_NOACCESS 27 41 | #define NLE_PERM 28 42 | #define NLE_PKTLOC_FILE 29 43 | #define NLE_PARSE_ERR 30 44 | #define NLE_NODEV 31 45 | #define NLE_IMMUTABLE 32 46 | #define NLE_DUMP_INTR 33 47 | #define NLE_ATTRSIZE 34 48 | 49 | #define NLE_MAX NLE_ATTRSIZE 50 | 51 | extern const char * nl_geterror(int); 52 | extern void nl_perror(int, const char *); 53 | extern int nl_syserr2nlerr(int); 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /include/netlink/route/link/ipip.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2014 Susant Sahani 4 | */ 5 | 6 | #ifndef NETLINK_LINK_IPIP_H_ 7 | #define NETLINK_LINK_IPIP_H_ 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | extern struct rtnl_link *rtnl_link_ipip_alloc(void); 16 | extern int rtnl_link_ipip_add(struct nl_sock *sk, const char *name); 17 | 18 | extern int rtnl_link_is_ipip(struct rtnl_link *link); 19 | 20 | extern uint32_t rtnl_link_ipip_get_link(struct rtnl_link *link); 21 | extern int rtnl_link_ipip_set_link(struct rtnl_link *link, uint32_t index); 22 | 23 | extern int rtnl_link_ipip_set_local(struct rtnl_link *link, uint32_t addr); 24 | extern uint32_t rtnl_link_ipip_get_local(struct rtnl_link *link); 25 | 26 | extern int rtnl_link_ipip_set_remote(struct rtnl_link *link, uint32_t addr); 27 | extern uint32_t rtnl_link_ipip_get_remote(struct rtnl_link *link); 28 | 29 | extern int rtnl_link_ipip_set_ttl(struct rtnl_link *link, uint8_t ttl); 30 | extern uint8_t rtnl_link_ipip_get_ttl(struct rtnl_link *link); 31 | 32 | extern int rtnl_link_ipip_set_tos(struct rtnl_link *link, uint8_t tos); 33 | extern uint8_t rtnl_link_ipip_get_tos(struct rtnl_link *link); 34 | 35 | extern int rtnl_link_ipip_set_pmtudisc(struct rtnl_link *link, uint8_t pmtudisc); 36 | extern uint8_t rtnl_link_ipip_get_pmtudisc(struct rtnl_link *link); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/netlink/route/action.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2013 Cong Wang 4 | */ 5 | 6 | #ifndef NETLINK_ACTION_H_ 7 | #define NETLINK_ACTION_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | extern struct rtnl_act *rtnl_act_alloc(void); 19 | extern struct rtnl_act *rtnl_act_next(struct rtnl_act *); 20 | extern void rtnl_act_get(struct rtnl_act *); 21 | extern void rtnl_act_put(struct rtnl_act *); 22 | extern int rtnl_act_build_add_request(struct rtnl_act *, int, 23 | struct nl_msg **); 24 | extern int rtnl_act_add(struct nl_sock *, struct rtnl_act *, int); 25 | extern int rtnl_act_change(struct nl_sock *, struct rtnl_act *, int); 26 | 27 | extern int rtnl_act_build_change_request(struct rtnl_act *, int, 28 | struct nl_msg **); 29 | extern int rtnl_act_build_delete_request(struct rtnl_act *, int, 30 | struct nl_msg **); 31 | extern int rtnl_act_delete(struct nl_sock *, struct rtnl_act *, 32 | int); 33 | extern int rtnl_act_append(struct rtnl_act **, struct rtnl_act *); 34 | extern int rtnl_act_remove(struct rtnl_act **, struct rtnl_act *); 35 | extern int rtnl_act_fill(struct nl_msg *, int, struct rtnl_act *); 36 | extern void rtnl_act_put_all(struct rtnl_act **); 37 | extern int rtnl_act_parse(struct rtnl_act **, struct nlattr *); 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /man/nl-pktloc-lookup.8: -------------------------------------------------------------------------------- 1 | .TH nl\-pktloc-lookup 8 "27 October 2010" "libnl" 2 | .SH NAME 3 | nl\-pktloc\-lookup - Lookup packet location definitions 4 | .SH SYNOPSIS 5 | .B nl\-pktloc\-lookup 6 | .I name 7 | .br 8 | .B nl\-pktloc\-lookup \-\-list 9 | 10 | .SH DESCRIPTION 11 | .PP 12 | nl\-pktloc\-lookup searches the packet location database for a matching 13 | entry. It is used to resolve packet location aliases to their definition, 14 | i.e. alignment, layer, offset, and mask. 15 | 16 | .SH OPTIONS 17 | .TP 18 | .BR \-\^h " or " \-\-help 19 | Print help text to console and exit. 20 | .TP 21 | .BR \-\^v " or " \-\-version 22 | Print versioning information to console and exit. 23 | .TP 24 | .BR \-\^l " or " \-\-list 25 | List all packet location definitions. 26 | .TP 27 | .BR \-\-u32=VALUE 28 | Prints the packet location definition in a special format that is 29 | understood by iproute2's u32 selector parser. It will output a 30 | u32 selector which will compare the provided value with the value 31 | specified by the packet location. 32 | 33 | Please note that due to the limitation of u32, it is not possible 34 | to use packet locations based on the link layer. nl-pktloc-lookup 35 | will print an error message in this case. 36 | 37 | Example: 38 | selector=$(nl-pktloc-lookup --u32 22 tcp.sport) 39 | tc filter add [...] u32 match $(selector) flowid 1:2 40 | 41 | .SH FILES 42 | .PP 43 | /etc/libnl/pktloc 44 | 45 | .SH AUTHOR 46 | .PP 47 | Thomas Graf is the original author and current maintainer of libnl and 48 | libnl tools. Many people have contributed to it since. 49 | -------------------------------------------------------------------------------- /include/netlink/idiag/vegasinfo.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2013 Sassano Systems LLC 4 | */ 5 | 6 | #ifndef NETLINK_IDIAGNL_VEGASINFO_H_ 7 | #define NETLINK_IDIAGNL_VEGASINFO_H_ 8 | 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif /* __cplusplus */ 14 | 15 | extern struct nl_object_ops idiagnl_vegasinfo_obj_ops; 16 | extern struct idiagnl_vegasinfo * idiagnl_vegasinfo_alloc(void); 17 | extern void idiagnl_vegasinfo_get(struct idiagnl_vegasinfo *); 18 | extern void idiagnl_vegasinfo_put(struct idiagnl_vegasinfo *); 19 | 20 | extern uint32_t idiagnl_vegasinfo_get_enabled(const struct idiagnl_vegasinfo *); 21 | extern uint32_t idiagnl_vegasinfo_get_rttcnt(const struct idiagnl_vegasinfo *); 22 | extern uint32_t idiagnl_vegasinfo_get_rtt(const struct idiagnl_vegasinfo *); 23 | extern uint32_t idiagnl_vegasinfo_get_minrtt(const struct idiagnl_vegasinfo *); 24 | 25 | extern void idiagnl_vegasinfo_set_enabled(struct idiagnl_vegasinfo *, 26 | uint32_t); 27 | extern void idiagnl_vegasinfo_set_rttcnt(struct idiagnl_vegasinfo *, 28 | uint32_t); 29 | extern void idiagnl_vegasinfo_set_rtt(struct idiagnl_vegasinfo *, uint32_t); 30 | extern void idiagnl_vegasinfo_set_minrtt(struct idiagnl_vegasinfo *, 31 | uint32_t); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif /* __cplusplus */ 36 | 37 | #endif /* NETLINK_IDIAGNL_VEGASINFO_H_ */ 38 | -------------------------------------------------------------------------------- /include/netlink/genl/genl.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2012 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_GENL_H_ 7 | #define NETLINK_GENL_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | extern int genl_connect(struct nl_sock *); 18 | extern int genl_send_simple(struct nl_sock *, int, int, 19 | int, int); 20 | 21 | extern void * genlmsg_put(struct nl_msg *, uint32_t, uint32_t, 22 | int, int, int, uint8_t, uint8_t); 23 | 24 | extern int genlmsg_valid_hdr(struct nlmsghdr *, int); 25 | extern int genlmsg_validate(struct nlmsghdr *, int, int, 26 | const struct nla_policy *); 27 | extern int genlmsg_parse(struct nlmsghdr *, int, struct nlattr **, 28 | int, const struct nla_policy *); 29 | extern struct genlmsghdr * 30 | genlmsg_hdr(struct nlmsghdr *); 31 | extern void * genlmsg_data(const struct genlmsghdr *); 32 | extern void * genlmsg_user_hdr(const struct genlmsghdr *); 33 | extern void * genlmsg_user_data(const struct genlmsghdr *, const int); 34 | extern int genlmsg_user_datalen(const struct genlmsghdr *, 35 | const int); 36 | extern int genlmsg_len(const struct genlmsghdr *); 37 | extern struct nlattr * genlmsg_attrdata(const struct genlmsghdr *, int); 38 | extern int genlmsg_attrlen(const struct genlmsghdr *, int); 39 | 40 | extern char * genl_op2name(int, int, char *, size_t); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /python/setup.py.in: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from distutils.core import setup, Extension 4 | 5 | opts = ['-O', '-nodefaultctor'] 6 | include = ['@top_builddir@/include', '@top_srcdir@/include'] 7 | library_dirs = ['@top_builddir@/lib/.libs'] 8 | 9 | netlink_capi = Extension('netlink/_capi', 10 | sources = ['netlink/capi.i'], 11 | include_dirs = include, 12 | swig_opts = opts, 13 | library_dirs = library_dirs, 14 | libraries = ['nl-3'], 15 | ) 16 | 17 | route_capi = Extension('netlink/route/_capi', 18 | sources = ['netlink/route/capi.i'], 19 | include_dirs = include, 20 | swig_opts = opts, 21 | library_dirs = library_dirs, 22 | libraries = ['nl-3', 'nl-route-3'], 23 | ) 24 | 25 | genl_capi = Extension('netlink/genl/_capi', 26 | sources = ['netlink/genl/capi.i'], 27 | include_dirs = include, 28 | swig_opts = opts, 29 | library_dirs = library_dirs, 30 | libraries = ['nl-3', 'nl-genl-3'], 31 | ) 32 | 33 | setup(name = 'netlink', 34 | version = '1.0', 35 | description = 'Python wrapper for netlink protocols', 36 | author = 'Thomas Graf', 37 | author_email = 'tgraf@suug.ch', 38 | url = 'http://www.infradead.org/~tgr/libnl/', 39 | license = 'LGPL 2', 40 | platforms = 'linux2', 41 | long_description = 'Experimental python bindings for libnl', 42 | ext_modules = [netlink_capi, route_capi, genl_capi], 43 | packages = ['netlink', 'netlink.genl', 'netlink.route', 44 | 'netlink.route.links', 'netlink.route.qdisc'], 45 | ) 46 | -------------------------------------------------------------------------------- /tests/test-create-vrf.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | struct nl_cache *link_cache; 10 | struct rtnl_link *link, *link2; 11 | struct nl_sock *sk; 12 | uint32_t tb_id; 13 | int err; 14 | 15 | sk = nl_socket_alloc(); 16 | if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { 17 | nl_perror(err, "Unable to connect socket"); 18 | return err; 19 | } 20 | 21 | if (!(link = rtnl_link_vrf_alloc())) { 22 | fprintf(stderr, "Unable to allocate link"); 23 | return -1; 24 | } 25 | 26 | rtnl_link_set_name(link, "vrf-red"); 27 | 28 | if ((err = rtnl_link_vrf_set_tableid(link, 10)) < 0) { 29 | nl_perror(err, "Unable to set VRF table id"); 30 | return err; 31 | } 32 | 33 | if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0) { 34 | nl_perror(err, "Unable to add link"); 35 | return err; 36 | } 37 | 38 | if ((err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &link_cache)) < 0) { 39 | nl_perror(err, "Unable to allocate cache"); 40 | return err; 41 | } 42 | 43 | if (!(link2 = rtnl_link_get_by_name(link_cache, "vrf-red"))) { 44 | fprintf(stderr, "Unable to lookup vrf-red"); 45 | return -1; 46 | } 47 | 48 | if ((err = rtnl_link_vrf_get_tableid(link2, &tb_id)) < 0) { 49 | nl_perror(err, "Unable to get VRF table id"); 50 | return err; 51 | } 52 | 53 | if (tb_id != 10) { 54 | fprintf(stderr, "Mismatch with VRF table id\n"); 55 | } 56 | 57 | rtnl_link_put(link); 58 | nl_close(sk); 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /include/netlink/route/classifier.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2011 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_CLASSIFIER_H_ 7 | #define NETLINK_CLASSIFIER_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | extern struct rtnl_cls *rtnl_cls_alloc(void); 19 | extern void rtnl_cls_put(struct rtnl_cls *); 20 | 21 | extern int rtnl_cls_alloc_cache(struct nl_sock *, int, uint32_t, 22 | struct nl_cache **); 23 | 24 | extern void rtnl_cls_cache_set_tc_params(struct nl_cache *, int, uint32_t); 25 | 26 | extern int rtnl_cls_build_add_request(struct rtnl_cls *, int, 27 | struct nl_msg **); 28 | extern int rtnl_cls_add(struct nl_sock *, struct rtnl_cls *, int); 29 | extern int rtnl_cls_change(struct nl_sock *, struct rtnl_cls *, int); 30 | 31 | extern int rtnl_cls_build_change_request(struct rtnl_cls *, int, 32 | struct nl_msg **); 33 | extern int rtnl_cls_build_delete_request(struct rtnl_cls *, int, 34 | struct nl_msg **); 35 | extern int rtnl_cls_delete(struct nl_sock *, struct rtnl_cls *, 36 | int); 37 | 38 | extern void rtnl_cls_set_prio(struct rtnl_cls *, uint16_t); 39 | extern uint16_t rtnl_cls_get_prio(struct rtnl_cls *); 40 | 41 | extern void rtnl_cls_set_protocol(struct rtnl_cls *, uint16_t); 42 | extern uint16_t rtnl_cls_get_protocol(struct rtnl_cls *); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /include/linux-private/linux/lwtunnel.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | #ifndef _LWTUNNEL_H_ 3 | #define _LWTUNNEL_H_ 4 | 5 | #include 6 | 7 | enum lwtunnel_encap_types { 8 | LWTUNNEL_ENCAP_NONE, 9 | LWTUNNEL_ENCAP_MPLS, 10 | LWTUNNEL_ENCAP_IP, 11 | LWTUNNEL_ENCAP_ILA, 12 | LWTUNNEL_ENCAP_IP6, 13 | LWTUNNEL_ENCAP_SEG6, 14 | LWTUNNEL_ENCAP_BPF, 15 | LWTUNNEL_ENCAP_SEG6_LOCAL, 16 | __LWTUNNEL_ENCAP_MAX, 17 | }; 18 | 19 | #define LWTUNNEL_ENCAP_MAX (__LWTUNNEL_ENCAP_MAX - 1) 20 | 21 | enum lwtunnel_ip_t { 22 | LWTUNNEL_IP_UNSPEC, 23 | LWTUNNEL_IP_ID, 24 | LWTUNNEL_IP_DST, 25 | LWTUNNEL_IP_SRC, 26 | LWTUNNEL_IP_TTL, 27 | LWTUNNEL_IP_TOS, 28 | LWTUNNEL_IP_FLAGS, 29 | LWTUNNEL_IP_PAD, 30 | __LWTUNNEL_IP_MAX, 31 | }; 32 | 33 | #define LWTUNNEL_IP_MAX (__LWTUNNEL_IP_MAX - 1) 34 | 35 | enum lwtunnel_ip6_t { 36 | LWTUNNEL_IP6_UNSPEC, 37 | LWTUNNEL_IP6_ID, 38 | LWTUNNEL_IP6_DST, 39 | LWTUNNEL_IP6_SRC, 40 | LWTUNNEL_IP6_HOPLIMIT, 41 | LWTUNNEL_IP6_TC, 42 | LWTUNNEL_IP6_FLAGS, 43 | LWTUNNEL_IP6_PAD, 44 | __LWTUNNEL_IP6_MAX, 45 | }; 46 | 47 | #define LWTUNNEL_IP6_MAX (__LWTUNNEL_IP6_MAX - 1) 48 | 49 | enum { 50 | LWT_BPF_PROG_UNSPEC, 51 | LWT_BPF_PROG_FD, 52 | LWT_BPF_PROG_NAME, 53 | __LWT_BPF_PROG_MAX, 54 | }; 55 | 56 | #define LWT_BPF_PROG_MAX (__LWT_BPF_PROG_MAX - 1) 57 | 58 | enum { 59 | LWT_BPF_UNSPEC, 60 | LWT_BPF_IN, 61 | LWT_BPF_OUT, 62 | LWT_BPF_XMIT, 63 | LWT_BPF_XMIT_HEADROOM, 64 | __LWT_BPF_MAX, 65 | }; 66 | 67 | #define LWT_BPF_MAX (__LWT_BPF_MAX - 1) 68 | 69 | #define LWT_BPF_MAX_HEADROOM 256 70 | 71 | #endif /* _LWTUNNEL_H_ */ 72 | -------------------------------------------------------------------------------- /src/lib/cls.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2010-2011 Thomas Graf 4 | */ 5 | 6 | /** 7 | * @ingroup cli 8 | * @defgroup cli_cls Classifiers 9 | * @{ 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | struct rtnl_cls *nl_cli_cls_alloc(void) 17 | { 18 | struct rtnl_cls *cls; 19 | 20 | if (!(cls = rtnl_cls_alloc())) 21 | nl_cli_fatal(ENOMEM, "Unable to allocate classifier object"); 22 | 23 | return cls; 24 | } 25 | 26 | struct nl_cache *nl_cli_cls_alloc_cache(struct nl_sock *sock, int ifindex, 27 | uint32_t parent) 28 | { 29 | struct nl_cache *cache; 30 | int err; 31 | 32 | if ((err = rtnl_cls_alloc_cache(sock, ifindex, parent, &cache)) < 0) 33 | nl_cli_fatal(err, "Unable to allocate classifier cache: %s", 34 | nl_geterror(err)); 35 | 36 | return cache; 37 | } 38 | 39 | void nl_cli_cls_parse_proto(struct rtnl_cls *cls, char *arg) 40 | { 41 | int proto; 42 | 43 | if ((proto = nl_str2ether_proto(arg)) < 0) 44 | nl_cli_fatal(proto, "Unknown protocol \"%s\".", arg); 45 | 46 | rtnl_cls_set_protocol(cls, proto); 47 | } 48 | 49 | struct rtnl_ematch_tree *nl_cli_cls_parse_ematch(struct rtnl_cls *cls, char *arg) 50 | { 51 | struct rtnl_ematch_tree *tree; 52 | char *errstr = NULL; 53 | int err; 54 | 55 | if ((err = rtnl_ematch_parse_expr(arg, &errstr, &tree)) < 0) 56 | nl_cli_fatal(err, "Unable to parse ematch expression: %s", 57 | errstr); 58 | 59 | if (errstr) 60 | free(errstr); 61 | 62 | return tree; 63 | } 64 | 65 | /** @} */ 66 | -------------------------------------------------------------------------------- /src/nl-neightbl-list.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2009 Thomas Graf 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | static void print_usage(void) 12 | { 13 | printf( 14 | "Usage: nl-neightbl-list [OPTION]...\n" 15 | "\n" 16 | "Options\n" 17 | " -f, --format=TYPE Output format { brief | details | stats }\n" 18 | " -h, --help Show this help\n" 19 | " -v, --version Show versioning information\n" 20 | ); 21 | exit(0); 22 | } 23 | 24 | int main(int argc, char *argv[]) 25 | { 26 | struct nl_sock *sock; 27 | struct nl_cache *neightbl_cache; 28 | struct nl_dump_params params = { 29 | .dp_type = NL_DUMP_LINE, 30 | .dp_fd = stdout, 31 | }; 32 | 33 | sock = nl_cli_alloc_socket(); 34 | nl_cli_connect(sock, NETLINK_ROUTE); 35 | nl_cli_link_alloc_cache(sock); 36 | neightbl_cache = nl_cli_alloc_cache(sock, "neighbour table", 37 | rtnl_neightbl_alloc_cache); 38 | 39 | for (;;) { 40 | int c, optidx = 0; 41 | static struct option long_opts[] = { 42 | { "format", 1, 0, 'f' }, 43 | { "help", 0, 0, 'h' }, 44 | { "version", 0, 0, 'v' }, 45 | { 0, 0, 0, 0 } 46 | }; 47 | 48 | c = getopt_long(argc, argv, "f:hv", long_opts, &optidx); 49 | if (c == -1) 50 | break; 51 | 52 | switch (c) { 53 | case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break; 54 | case 'h': print_usage(); break; 55 | case 'v': nl_cli_print_version(); break; 56 | } 57 | } 58 | 59 | nl_cache_dump(neightbl_cache, ¶ms); 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /tests/test-cache-mngr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | static int quit = 0; 11 | 12 | static struct nl_dump_params dp = { 13 | .dp_type = NL_DUMP_LINE, 14 | }; 15 | 16 | 17 | static void change_cb(struct nl_cache *cache, struct nl_object *obj, 18 | int action, void *data) 19 | { 20 | if (action == NL_ACT_NEW) 21 | printf("NEW "); 22 | else if (action == NL_ACT_DEL) 23 | printf("DEL "); 24 | else if (action == NL_ACT_CHANGE) 25 | printf("CHANGE "); 26 | 27 | nl_object_dump(obj, &dp); 28 | } 29 | 30 | static void sigint(int arg) 31 | { 32 | quit = 1; 33 | } 34 | 35 | int main(int argc, char *argv[]) 36 | { 37 | struct nl_cache_mngr *mngr; 38 | struct nl_cache *cache; 39 | int err, i; 40 | 41 | dp.dp_fd = stdout; 42 | 43 | signal(SIGINT, sigint); 44 | 45 | err = nl_cache_mngr_alloc(NULL, NETLINK_ROUTE, NL_AUTO_PROVIDE, &mngr); 46 | if (err < 0) 47 | nl_cli_fatal(err, "Unable to allocate cache manager: %s", 48 | nl_geterror(err)); 49 | 50 | for (i = 1; i < argc; i++) { 51 | err = nl_cache_mngr_add(mngr, argv[i], &change_cb, NULL, &cache); 52 | if (err < 0) 53 | nl_cli_fatal(err, "Unable to add cache %s: %s", 54 | argv[i], nl_geterror(err)); 55 | } 56 | 57 | while (!quit) { 58 | int err = nl_cache_mngr_poll(mngr, 1000); 59 | if (err < 0 && err != -NLE_INTR) 60 | nl_cli_fatal(err, "Polling failed: %s", nl_geterror(err)); 61 | 62 | nl_cache_mngr_info(mngr, &dp); 63 | } 64 | 65 | nl_cache_mngr_free(mngr); 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /lib/cli/cls/cgroup.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2010-2011 Thomas Graf 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | static void print_usage(void) 12 | { 13 | printf( 14 | "Usage: nl-cls-add [...] cgroup [OPTIONS]...\n" 15 | "\n" 16 | "OPTIONS\n" 17 | " -h, --help Show this help text.\n" 18 | " -e, --ematch=EXPR Ematch expression\n" 19 | "\n" 20 | "EXAMPLE" 21 | " nl-cls-add --dev=eth0 --parent=q_root cgroup\n"); 22 | } 23 | 24 | static void parse_argv(struct rtnl_tc *tc, int argc, char **argv) 25 | { 26 | struct rtnl_cls *cls = (struct rtnl_cls *) tc; 27 | struct rtnl_ematch_tree *tree; 28 | 29 | for (;;) { 30 | int c, optidx = 0; 31 | static struct option long_opts[] = { 32 | { "help", 0, 0, 'h' }, 33 | { "ematch", 1, 0, 'e' }, 34 | { 0, 0, 0, 0 } 35 | }; 36 | 37 | c = getopt_long(argc, argv, "he:", long_opts, &optidx); 38 | if (c == -1) 39 | break; 40 | 41 | switch (c) { 42 | case 'h': 43 | print_usage(); 44 | exit(0); 45 | 46 | case 'e': 47 | tree = nl_cli_cls_parse_ematch(cls, optarg); 48 | rtnl_cgroup_set_ematch(cls, tree); 49 | break; 50 | } 51 | } 52 | } 53 | 54 | static struct nl_cli_tc_module cgroup_module = 55 | { 56 | .tm_name = "cgroup", 57 | .tm_type = RTNL_TC_TYPE_CLS, 58 | .tm_parse_argv = parse_argv, 59 | }; 60 | 61 | static void __init cgroup_init(void) 62 | { 63 | nl_cli_tc_register(&cgroup_module); 64 | } 65 | 66 | static void __exit cgroup_exit(void) 67 | { 68 | nl_cli_tc_unregister(&cgroup_module); 69 | } 70 | -------------------------------------------------------------------------------- /include/netlink/route/link/vlan.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2013 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_LINK_VLAN_H_ 7 | #define NETLINK_LINK_VLAN_H_ 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | struct vlan_map 17 | { 18 | uint32_t vm_from; 19 | uint32_t vm_to; 20 | }; 21 | 22 | #define VLAN_PRIO_MAX 7 23 | 24 | extern struct rtnl_link *rtnl_link_vlan_alloc(void); 25 | 26 | extern int rtnl_link_is_vlan(struct rtnl_link *); 27 | 28 | extern char * rtnl_link_vlan_flags2str(int, char *, size_t); 29 | extern int rtnl_link_vlan_str2flags(const char *); 30 | 31 | extern int rtnl_link_vlan_set_protocol(struct rtnl_link *link, uint16_t); 32 | extern int rtnl_link_vlan_get_protocol(struct rtnl_link *link); 33 | 34 | extern int rtnl_link_vlan_set_id(struct rtnl_link *, uint16_t); 35 | extern int rtnl_link_vlan_get_id(struct rtnl_link *); 36 | 37 | extern int rtnl_link_vlan_set_flags(struct rtnl_link *, 38 | unsigned int); 39 | extern int rtnl_link_vlan_unset_flags(struct rtnl_link *, 40 | unsigned int); 41 | extern int rtnl_link_vlan_get_flags(struct rtnl_link *); 42 | 43 | extern int rtnl_link_vlan_set_ingress_map(struct rtnl_link *, 44 | int, uint32_t); 45 | extern uint32_t * rtnl_link_vlan_get_ingress_map(struct rtnl_link *); 46 | 47 | extern int rtnl_link_vlan_set_egress_map(struct rtnl_link *, 48 | uint32_t, int); 49 | extern struct vlan_map *rtnl_link_vlan_get_egress_map(struct rtnl_link *, 50 | int *); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /include/netlink/cli/exp.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2012 Rich Fought 4 | * Copyright (c) 2008-2009 Thomas Graf 5 | */ 6 | 7 | #ifndef __NETLINK_CLI_EXP_H_ 8 | #define __NETLINK_CLI_EXP_H_ 9 | 10 | #include 11 | #include 12 | 13 | extern struct nfnl_exp *nl_cli_exp_alloc(void); 14 | extern struct nl_cache *nl_cli_exp_alloc_cache(struct nl_sock *); 15 | 16 | extern void nl_cli_exp_parse_family(struct nfnl_exp *, char *); 17 | extern void nl_cli_exp_parse_timeout(struct nfnl_exp *, char *); 18 | extern void nl_cli_exp_parse_id(struct nfnl_exp *, char *); 19 | extern void nl_cli_exp_parse_helper_name(struct nfnl_exp *, char *); 20 | extern void nl_cli_exp_parse_zone(struct nfnl_exp *, char *); 21 | extern void nl_cli_exp_parse_flags(struct nfnl_exp *, char *); 22 | extern void nl_cli_exp_parse_class(struct nfnl_exp *, char *); 23 | extern void nl_cli_exp_parse_nat_dir(struct nfnl_exp *, char *); 24 | extern void nl_cli_exp_parse_fn(struct nfnl_exp *, char *); 25 | 26 | extern void nl_cli_exp_parse_src(struct nfnl_exp *, int, char *); 27 | extern void nl_cli_exp_parse_dst(struct nfnl_exp *, int, char *); 28 | extern void nl_cli_exp_parse_l4protonum(struct nfnl_exp *, int, char *); 29 | extern void nl_cli_exp_parse_src_port(struct nfnl_exp *, int, char *); 30 | extern void nl_cli_exp_parse_dst_port(struct nfnl_exp *, int, char *); 31 | extern void nl_cli_exp_parse_icmp_id(struct nfnl_exp *, int, char *); 32 | extern void nl_cli_exp_parse_icmp_type(struct nfnl_exp *, int, char *); 33 | extern void nl_cli_exp_parse_icmp_code(struct nfnl_exp *, int, char *); 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/linux-private/linux/tc_act/tc_skbedit.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | /* 3 | * Copyright (c) 2008, Intel Corporation. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms and conditions of the GNU General Public License, 7 | * version 2, as published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope it will be useful, but WITHOUT 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 | * more details. 13 | * 14 | * You should have received a copy of the GNU General Public License along with 15 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 16 | * Place - Suite 330, Boston, MA 02111-1307 USA. 17 | * 18 | * Author: Alexander Duyck 19 | */ 20 | 21 | #ifndef __LINUX_TC_SKBEDIT_H 22 | #define __LINUX_TC_SKBEDIT_H 23 | 24 | #include 25 | 26 | #define TCA_ACT_SKBEDIT 11 27 | 28 | #define SKBEDIT_F_PRIORITY 0x1 29 | #define SKBEDIT_F_QUEUE_MAPPING 0x2 30 | #define SKBEDIT_F_MARK 0x4 31 | #define SKBEDIT_F_PTYPE 0x8 32 | #define SKBEDIT_F_MASK 0x10 33 | #define SKBEDIT_F_INHERITDSFIELD 0x20 34 | 35 | struct tc_skbedit { 36 | tc_gen; 37 | }; 38 | 39 | enum { 40 | TCA_SKBEDIT_UNSPEC, 41 | TCA_SKBEDIT_TM, 42 | TCA_SKBEDIT_PARMS, 43 | TCA_SKBEDIT_PRIORITY, 44 | TCA_SKBEDIT_QUEUE_MAPPING, 45 | TCA_SKBEDIT_MARK, 46 | TCA_SKBEDIT_PAD, 47 | TCA_SKBEDIT_PTYPE, 48 | TCA_SKBEDIT_MASK, 49 | TCA_SKBEDIT_FLAGS, 50 | __TCA_SKBEDIT_MAX 51 | }; 52 | #define TCA_SKBEDIT_MAX (__TCA_SKBEDIT_MAX - 1) 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /lib/cli/qdisc/pfifo.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2010-2011 Thomas Graf 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | static void print_usage(void) 11 | { 12 | printf( 13 | "Usage: nl-qdisc-add [...] pfifo [OPTIONS]...\n" 14 | "\n" 15 | "OPTIONS\n" 16 | " --help Show this help text.\n" 17 | " --limit=LIMIT Maximum queue length in number of packets.\n" 18 | "\n" 19 | "EXAMPLE" 20 | " # Attach pfifo with a 32 packet limit to eth1\n" 21 | " nl-qdisc-add --dev=eth1 --parent=root pfifo --limit=32\n"); 22 | } 23 | 24 | static void pfifo_parse_argv(struct rtnl_tc *tc, int argc, char **argv) 25 | { 26 | struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc; 27 | 28 | for (;;) { 29 | int c, optidx = 0; 30 | enum { 31 | ARG_LIMIT = 257, 32 | }; 33 | static struct option long_opts[] = { 34 | { "help", 0, 0, 'h' }, 35 | { "limit", 1, 0, ARG_LIMIT }, 36 | { 0, 0, 0, 0 } 37 | }; 38 | 39 | c = getopt_long(argc, argv, "h", long_opts, &optidx); 40 | if (c == -1) 41 | break; 42 | 43 | switch (c) { 44 | case 'h': 45 | print_usage(); 46 | return; 47 | 48 | case ARG_LIMIT: 49 | rtnl_qdisc_fifo_set_limit(qdisc, nl_cli_parse_u32(optarg)); 50 | break; 51 | } 52 | } 53 | } 54 | 55 | static struct nl_cli_tc_module pfifo_module = 56 | { 57 | .tm_name = "pfifo", 58 | .tm_type = RTNL_TC_TYPE_QDISC, 59 | .tm_parse_argv = pfifo_parse_argv, 60 | }; 61 | 62 | static void __init pfifo_init(void) 63 | { 64 | nl_cli_tc_register(&pfifo_module); 65 | } 66 | 67 | static void __exit pfifo_exit(void) 68 | { 69 | nl_cli_tc_unregister(&pfifo_module); 70 | } 71 | -------------------------------------------------------------------------------- /lib/route/cls/police.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2013 Thomas Graf 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | /** 15 | * @name Policer Type 16 | * @{ 17 | */ 18 | 19 | static const struct trans_tbl police_types[] = { 20 | __ADD(TC_POLICE_UNSPEC,unspec), 21 | __ADD(TC_POLICE_OK,ok), 22 | __ADD(TC_POLICE_RECLASSIFY,reclassify), 23 | __ADD(TC_POLICE_SHOT,shot), 24 | #ifdef TC_POLICE_PIPE 25 | __ADD(TC_POLICE_PIPE,pipe), 26 | #endif 27 | }; 28 | 29 | /** 30 | * Transform a policer type number into a character string (Reentrant). 31 | * @arg type policer type 32 | * @arg buf destination buffer 33 | * @arg len buffer length 34 | * 35 | * Transforms a policer type number into a character string and stores 36 | * it in the provided buffer. 37 | * 38 | * @return The destination buffer or the type encoded in hex if no match was found. 39 | */ 40 | char * nl_police2str(int type, char *buf, size_t len) 41 | { 42 | return __type2str(type, buf, len, police_types, 43 | ARRAY_SIZE(police_types)); 44 | } 45 | 46 | /** 47 | * Transform a character string into a policer type number 48 | * @arg name policer type name 49 | * 50 | * Transform the provided character string specifying a policer 51 | * type into the corresponding numeric value 52 | * 53 | * @return Policer type number or a negative value. 54 | */ 55 | int nl_str2police(const char *name) 56 | { 57 | return __str2type(name, police_types, ARRAY_SIZE(police_types)); 58 | } 59 | 60 | /** @} */ 61 | -------------------------------------------------------------------------------- /src/genl-ctrl-list.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2012 Thomas Graf 4 | */ 5 | 6 | #include 7 | 8 | #include 9 | 10 | static struct nl_cache *alloc_genl_family_cache(struct nl_sock *sk) 11 | { 12 | return nl_cli_alloc_cache(sk, "generic netlink family", 13 | genl_ctrl_alloc_cache); 14 | } 15 | 16 | static void print_usage(void) 17 | { 18 | printf( 19 | "Usage: genl-ctrl-list [--details]\n" 20 | "\n" 21 | "Options\n" 22 | " -d, --details Include detailed information in the list\n" 23 | " -h, --help Show this help\n" 24 | " -v, --version Show versioning information\n" 25 | ); 26 | exit(0); 27 | } 28 | 29 | int main(int argc, char *argv[]) 30 | { 31 | struct nl_sock *sock; 32 | struct nl_cache *family_cache; 33 | struct nl_dump_params params = { 34 | .dp_type = NL_DUMP_LINE, 35 | .dp_fd = stdout, 36 | }; 37 | 38 | sock = nl_cli_alloc_socket(); 39 | nl_cli_connect(sock, NETLINK_GENERIC); 40 | family_cache = alloc_genl_family_cache(sock); 41 | 42 | for (;;) { 43 | int c, optidx = 0; 44 | static struct option long_opts[] = { 45 | { "details", 0, 0, 'd' }, 46 | { "format", 1, 0, 'f' }, 47 | { "help", 0, 0, 'h' }, 48 | { "version", 0, 0, 'v' }, 49 | { 0, 0, 0, 0 } 50 | }; 51 | 52 | c = getopt_long(argc, argv, "df:hv", long_opts, &optidx); 53 | if (c == -1) 54 | break; 55 | 56 | switch (c) { 57 | case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break; 58 | case 'd': params.dp_type = NL_DUMP_DETAILS; break; 59 | case 'h': print_usage(); break; 60 | case 'v': nl_cli_print_version(); break; 61 | } 62 | } 63 | 64 | nl_cache_dump(family_cache, ¶ms); 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /doc/src/hidden.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \cond skip 3 | * vim:syntax=doxygen 4 | * \endcond 5 | 6 | \page auto_ack_warning Disabling Auto-ACK 7 | 8 | \attention Disabling Auto-ACK (nl_socket_disable_auto_ack()) will cause this 9 | function to return immediately after sending the netlink message. 10 | The function will not wait for an eventual error message. It is 11 | the responsibility of the caller to handle any error messages or 12 | ACKs returned. 13 | 14 | \page pointer_lifetime_warning Pointer Lifetime 15 | 16 | \attention The reference counter of the returned object is not incremented. 17 | Therefore, the returned pointer is only valid during the lifetime 18 | of the parent object. Increment the reference counter if the object 19 | is supposed to stay around after the parent object was freed. 20 | 21 | \page private_struct Private Structure 22 | 23 | \note The definition of this structure is private to allow modification 24 | without breaking API. Use the designated accessor functions to 25 | access individual object attributes. 26 | 27 | \page read_only_attribute Read-Only Attribute 28 | 29 | \note The attribute this accessor is modifying is a read-only attribute 30 | which can not be modified in the kernel. Any changes to the 31 | attribute only have an effect on the local copy of the object. The 32 | accessor function is provided solely for the purpose of creating 33 | objects for comparison and filtering. 34 | 35 | \page low_level_api Low Level API 36 | 37 | \note This is a low level API function. A high level function implementing 38 | the same functionality with a simplified usage pattern exists. This 39 | function is available as an alternative if the default library 40 | behaviour is not desirable. 41 | 42 | */ 43 | -------------------------------------------------------------------------------- /etc/pktloc: -------------------------------------------------------------------------------- 1 | # 2 | # Location definitions for packet matching 3 | # 4 | 5 | # name alignment offset mask shift 6 | ip.version u8 net+0 0xF0 4 7 | ip.hdrlen u8 net+0 0x0F 8 | ip.diffserv u8 net+1 9 | ip.length u16 net+2 10 | ip.id u16 net+4 11 | ip.flag.res u8 net+6 0xff 7 12 | ip.df u8 net+6 0x40 6 13 | ip.mf u8 net+6 0x20 5 14 | ip.offset u16 net+6 0x1FFF 15 | ip.ttl u8 net+8 16 | ip.proto u8 net+9 17 | ip.chksum u16 net+10 18 | ip.src u32 net+12 19 | ip.dst u32 net+16 20 | 21 | # if ip.ihl > 5 22 | ip.opts u32 net+20 23 | 24 | 25 | # 26 | # IP version 6 27 | # 28 | # name alignment offset mask shift 29 | ip6.version u8 net+0 0xF0 4 30 | ip6.tc u16 net+0 0xFF0 4 31 | ip6.flowlabel u32 net+0 0xFFFFF 32 | ip6.length u16 net+4 33 | ip6.nexthdr u8 net+6 34 | ip6.hoplimit u8 net+7 35 | ip6.src 16 net+8 36 | ip6.dst 16 net+24 37 | 38 | # 39 | # Transmission Control Protocol (TCP) 40 | # 41 | # name alignment offset mask shift 42 | tcp.sport u16 tcp+0 43 | tcp.dport u16 tcp+2 44 | tcp.seq u32 tcp+4 45 | tcp.ack u32 tcp+8 46 | 47 | # Data offset (4 bits) 48 | tcp.off u8 tcp+12 0xF0 4 49 | 50 | # Reserved [0 0 0] (3 bits) 51 | tcp.reserved u8 tcp+12 0x04 1 52 | 53 | # ECN [N C E] (3 bits) 54 | tcp.ecn u16 tcp+12 0x01C00 6 55 | 56 | # Individual TCP flags (0|1) (6 bits in total) 57 | tcp.flag.urg u8 tcp+13 0x20 5 58 | tcp.flag.ack u8 tcp+13 0x10 4 59 | tcp.flag.psh u8 tcp+13 0x08 3 60 | tcp.flag.rst u8 tcp+13 0x04 2 61 | tcp.flag.syn u8 tcp+13 0x02 1 62 | tcp.flag.fin u8 tcp+13 0x01 63 | 64 | tcp.win u16 tcp+14 65 | tcp.csum u16 tcp+16 66 | tcp.urg u16 tcp+18 67 | tcp.opts u32 tcp+20 68 | 69 | # 70 | # User Datagram Protocol (UDP) 71 | # 72 | # name alignment offset mask shift 73 | udp.sport u16 tcp+0 74 | udp.dport u16 tcp+2 75 | udp.length u16 tcp+4 76 | udp.csum u16 tcp+6 77 | -------------------------------------------------------------------------------- /python/py80211/util/extract.d/nl80211_policy.py: -------------------------------------------------------------------------------- 1 | nl80211_policy[ATTR_GENERATION].type = NLA_U32 2 | nl80211_policy[ATTR_MAX_NUM_SCAN_SSIDS].type = NLA_U8 3 | nl80211_policy[ATTR_SUPPORT_AP_UAPSD].type = NLA_FLAG 4 | nl80211_policy[ATTR_MAX_MATCH_SETS].type = NLA_U8 5 | nl80211_policy[ATTR_FEATURE_FLAGS].type = NLA_U32 6 | nl80211_policy[ATTR_INTERFACE_COMBINATIONS].type = NLA_NESTED 7 | nl80211_policy[ATTR_SUPPORTED_COMMANDS].type = NLA_NESTED 8 | nl80211_policy[ATTR_SUPPORTED_COMMANDS].list_type = NLA_U32 9 | nl80211_policy[ATTR_WOWLAN_TRIGGERS_SUPPORTED].type = NLA_NESTED 10 | nl80211_policy[ATTR_WOWLAN_TRIGGERS_SUPPORTED].single = True 11 | nl80211_policy[ATTR_MAX_SCAN_IE_LEN].type = NLA_U16 12 | nl80211_policy[ATTR_MAX_NUM_PMKIDS].type = NLA_U8 13 | nl80211_policy[ATTR_SUPPORT_IBSS_RSN].type = NLA_FLAG 14 | nl80211_policy[ATTR_MAX_REMAIN_ON_CHANNEL_DURATION].type = NLA_U32 15 | nl80211_policy[ATTR_WIPHY_ANTENNA_AVAIL_TX].type = NLA_U32 16 | nl80211_policy[ATTR_WIPHY_ANTENNA_AVAIL_RX].type = NLA_U32 17 | nl80211_policy[ATTR_MAX_NUM_SCHED_SCAN_SSIDS].type = NLA_U8 18 | nl80211_policy[ATTR_MAX_SCHED_SCAN_IE_LEN].type = NLA_U16 19 | nl80211_policy[ATTR_MAX_CSA_COUNTERS].type = NLA_U8 20 | nl80211_policy[ATTR_SOFTWARE_IFTYPES].type = NLA_NESTED 21 | nl80211_policy[ATTR_TX_FRAME_TYPES].type = NLA_NESTED 22 | nl80211_policy[ATTR_TX_FRAME_TYPES].map = True 23 | nl80211_policy[ATTR_TX_FRAME_TYPES].list_type = NLA_U16 24 | nl80211_policy[ATTR_RX_FRAME_TYPES].type = NLA_NESTED 25 | nl80211_policy[ATTR_RX_FRAME_TYPES].map = True 26 | nl80211_policy[ATTR_RX_FRAME_TYPES].list_type = NLA_U16 27 | nl80211_policy[ATTR_WIPHY_BANDS].type = NLA_NESTED 28 | nl80211_policy[ATTR_SUPPORTED_IFTYPES].type = NLA_NESTED 29 | nl80211_policy[ATTR_STA_INFO].type = NLA_NESTED 30 | nl80211_policy[ATTR_STA_INFO].single = True 31 | nl80211_policy[ATTR_MNTR_FLAGS].type = NLA_UNSPEC 32 | nl80211_policy[ATTR_BSS].type = NLA_NESTED 33 | -------------------------------------------------------------------------------- /doc/src/toc.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \cond skip 3 | * vim:syntax=doxygen 4 | * \endcond 5 | 6 | \mainpage 7 | 8 | \section main_intro Introduction 9 | 10 | libnl is a set of libraries to deal with the netlink protocol and some 11 | of the high level protocols implemented on top of it. The goal is to 12 | provide APIs on different levels of abstraction. The core library libnl 13 | provides a fundamental set of functions to deal with sockets, construct 14 | messages, and send/receive those messages. Additional high level interfaces 15 | for several individual netlink protocols are provided in separate 16 | libraries (e.g. "nl-route", "nl-genl", ...). 17 | 18 | The library is designed to ensure that all components are optional, i.e. 19 | even though the core library provides a caching system which allows to 20 | easily manage objects of any kind, no application is required to use this 21 | caching system if it has no need for it. 22 | 23 | The library was developed and tested on 2.6.x and 3.x kernel releases. It 24 | may or may not work with older kernel series. Also, although all netlink 25 | protocols are required to maintain backwards compatibility, this has not 26 | always achieved and undesired side effects can occur if a recent libnl 27 | version is used with a considerably older kernel. 28 | 29 | \section main_toc Table of Contents 30 | 31 | \section main_trees GIT Trees 32 | 33 | \subsection tree_dev Development Tree 34 | 35 | @code 36 | git://git.infradead.org/users/tgr/libnl.git 37 | @endcode 38 | - Web: http://git.infradead.org/users/tgr/libnl.git 39 | 40 | \section main_website Website 41 | 42 | - https://www.infradead.org/~tgr/libnl/ 43 | 44 | \section main_mailinglist Mailinglist 45 | 46 | Please post questions and patches to the libnl mailinglist: 47 | 48 | @code 49 | libnl@lists.infradead.org 50 | @endcode 51 | 52 | - Archives: https://lists.infradead.org/pipermail/libnl/ 53 | 54 | */ 55 | -------------------------------------------------------------------------------- /include/netlink/route/class.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2003-2011 Thomas Graf 4 | */ 5 | 6 | #ifndef NETLINK_CLASS_H_ 7 | #define NETLINK_CLASS_H_ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | struct rtnl_class; 18 | 19 | extern struct rtnl_class * 20 | rtnl_class_alloc(void); 21 | extern void rtnl_class_put(struct rtnl_class *); 22 | 23 | extern int rtnl_class_alloc_cache(struct nl_sock *, int, 24 | struct nl_cache **); 25 | extern struct rtnl_class * 26 | rtnl_class_get(struct nl_cache *, int, uint32_t); 27 | 28 | extern struct rtnl_class * 29 | rtnl_class_get_by_parent(struct nl_cache *, int, uint32_t); 30 | 31 | extern struct rtnl_qdisc * 32 | rtnl_class_leaf_qdisc(struct rtnl_class *, 33 | struct nl_cache *); 34 | 35 | extern int rtnl_class_build_add_request(struct rtnl_class *, int, 36 | struct nl_msg **); 37 | extern int rtnl_class_add(struct nl_sock *, struct rtnl_class *, 38 | int); 39 | 40 | extern int rtnl_class_build_delete_request(struct rtnl_class *, 41 | struct nl_msg **); 42 | extern int rtnl_class_delete(struct nl_sock *, 43 | struct rtnl_class *); 44 | 45 | /* deprecated functions */ 46 | extern void rtnl_class_foreach_child(struct rtnl_class *, 47 | struct nl_cache *, 48 | void (*cb)(struct nl_object *, 49 | void *), 50 | void *) 51 | __attribute__((deprecated)); 52 | extern void rtnl_class_foreach_cls(struct rtnl_class *, 53 | struct nl_cache *, 54 | void (*cb)(struct nl_object *, 55 | void *), 56 | void *) 57 | __attribute__((deprecated)); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /tests/check-direct.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | 3 | #include 4 | 5 | #include "linux/snmp.h" 6 | #include "netlink-private/utils.h" 7 | #include "netlink-private/route/utils.h" 8 | 9 | #include "netlink/route/link.h" 10 | 11 | START_TEST(static_checks) 12 | { 13 | int i, j; 14 | char strbuf[100]; 15 | 16 | _NL_STATIC_ASSERT(RTNL_LINK_RX_PACKETS == 0); 17 | assert(_nltst_map_stat_id_from_IPSTATS_MIB_v2[0] == RTNL_LINK_RX_PACKETS); 18 | for (i = 1; i < __IPSTATS_MIB_MAX; i++) { 19 | assert(_nltst_map_stat_id_from_IPSTATS_MIB_v2[i] > 0); 20 | assert(_nltst_map_stat_id_from_IPSTATS_MIB_v2[i] < __RTNL_LINK_STATS_MAX); 21 | for (j = 1; j < i; j++) 22 | assert(_nltst_map_stat_id_from_IPSTATS_MIB_v2[i] != _nltst_map_stat_id_from_IPSTATS_MIB_v2[j]); 23 | } 24 | 25 | for (i = 0; i <= RTNL_LINK_STATS_MAX + 1; i++) { 26 | const char *s; 27 | 28 | s = rtnl_link_stat2str(i, strbuf, sizeof(strbuf)); 29 | assert (s); 30 | assert (s == strbuf); 31 | assert (strlen (s) < sizeof(strbuf)); 32 | if (strncmp(s, "0x", 2) == 0) { 33 | assert(i == RTNL_LINK_STATS_MAX + 1); 34 | ck_assert_int_eq(strtoll(&s[2], NULL, 16), i); 35 | } else 36 | ck_assert_int_le(i, RTNL_LINK_STATS_MAX); 37 | ck_assert_int_eq(i, rtnl_link_str2stat(s)); 38 | } 39 | } 40 | END_TEST 41 | 42 | static Suite *make_suite(void) 43 | { 44 | Suite *suite = suite_create("Direct"); 45 | 46 | TCase *nl_attr = tcase_create("Core"); 47 | tcase_add_test(nl_attr, static_checks); 48 | suite_add_tcase(suite, nl_attr); 49 | return suite; 50 | } 51 | 52 | int main(int argc, char *argv[]) 53 | { 54 | SRunner *runner; 55 | int nfailed; 56 | 57 | runner = srunner_create(suite_create("main")); 58 | 59 | srunner_add_suite(runner, make_suite()); 60 | 61 | srunner_run_all(runner, CK_ENV); 62 | 63 | nfailed = srunner_ntests_failed(runner); 64 | srunner_free(runner); 65 | return nfailed != 0; 66 | } 67 | -------------------------------------------------------------------------------- /lib/cli/qdisc/bfifo.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1-only */ 2 | /* 3 | * Copyright (c) 2010-2011 Thomas Graf 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | static void print_usage(void) 11 | { 12 | printf( 13 | "Usage: nl-qdisc-add [...] bfifo [OPTIONS]...\n" 14 | "\n" 15 | "OPTIONS\n" 16 | " --help Show this help text.\n" 17 | " --limit=LIMIT Maximum queue length in number of bytes.\n" 18 | "\n" 19 | "EXAMPLE" 20 | " # Attach bfifo with a 4KB bytes limit to eth1\n" 21 | " nl-qdisc-add --dev=eth1 --parent=root bfifo --limit=4096\n"); 22 | } 23 | 24 | static void bfifo_parse_argv(struct rtnl_tc *tc, int argc, char **argv) 25 | { 26 | struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc; 27 | int limit; 28 | 29 | for (;;) { 30 | int c, optidx = 0; 31 | enum { 32 | ARG_LIMIT = 257, 33 | }; 34 | static struct option long_opts[] = { 35 | { "help", 0, 0, 'h' }, 36 | { "limit", 1, 0, ARG_LIMIT }, 37 | { 0, 0, 0, 0 } 38 | }; 39 | 40 | c = getopt_long(argc, argv, "h", long_opts, &optidx); 41 | if (c == -1) 42 | break; 43 | 44 | switch (c) { 45 | case 'h': 46 | print_usage(); 47 | return; 48 | 49 | case ARG_LIMIT: 50 | limit = nl_size2int(optarg); 51 | if (limit < 0) { 52 | nl_cli_fatal(limit, "Unable to parse bfifo limit " 53 | "\"%s\": Invalid format.", optarg); 54 | } 55 | 56 | rtnl_qdisc_fifo_set_limit(qdisc, limit); 57 | break; 58 | } 59 | } 60 | } 61 | 62 | static struct nl_cli_tc_module bfifo_module = 63 | { 64 | .tm_name = "bfifo", 65 | .tm_type = RTNL_TC_TYPE_QDISC, 66 | .tm_parse_argv = bfifo_parse_argv, 67 | }; 68 | 69 | static void __init bfifo_init(void) 70 | { 71 | nl_cli_tc_register(&bfifo_module); 72 | } 73 | 74 | static void __exit bfifo_exit(void) 75 | { 76 | nl_cli_tc_unregister(&bfifo_module); 77 | } 78 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | # -*- Makefile -*- 2 | 3 | .PHONY: gendoc api_ref asciidoc 4 | 5 | ASCIIDOCOPTS = \ 6 | -a pygments \ 7 | -a language=c \ 8 | -a icons \ 9 | -a toc2 \ 10 | -a numbered \ 11 | -a imagesdir="./images/" \ 12 | -a iconsdir="./images/icons" \ 13 | -a stylesdir="$(abs_srcdir)/stylesheets/" 14 | 15 | EXTRA_DIST = \ 16 | core.txt \ 17 | core.html \ 18 | route.txt \ 19 | route.html \ 20 | index.txt \ 21 | index.html \ 22 | libnl.css \ 23 | stylesheets \ 24 | images \ 25 | api 26 | 27 | dist-hook: 28 | rm -f $(distdir)/aclocal.m4 29 | rm -f $(distdir)/configure 30 | rm -f $(distdir)/configure.in 31 | rm -rf $(distdir)/m4 32 | rm -f $(distdir)/README 33 | rm -f $(distdir)/missing 34 | rm -f $(distdir)/Doxyfile.in 35 | rm -f $(distdir)/Makefile.am 36 | rm -f $(distdir)/Makefile.in 37 | 38 | link_doc: 39 | if LINK_DOC 40 | ./gen-tags.sh > libnl.dict 41 | else 42 | @echo "Warning: Linking to API reference is disabled, check configure output" 43 | endif 44 | 45 | 46 | %.html: %.txt link_doc 47 | if HAVE_ASCIIDOC 48 | ./resolve-asciidoc-refs.py $< > asciidoc.tmp 49 | asciidoc $(ASCIIDOCOPTS) -o $@ asciidoc.tmp 50 | if LINK_DOC 51 | ./doxygen-link.py libnl.dict $@ > asciidoc.tmp 52 | mv asciidoc.tmp $@ 53 | endif 54 | else 55 | @echo "Warning: Building of asciidoc files is disabled, check autoconf logs" 56 | endif 57 | 58 | asciidoc: core.html route.html index.html 59 | 60 | api_ref: 61 | doxygen Doxyfile; 62 | 63 | gendoc: 64 | if GENERATE_DOC 65 | if HAVE_DOXYGEN 66 | $(MAKE) api_ref 67 | else 68 | @echo "Warning: Building of API reference (doxygen) is disabled, check autoconf logs" 69 | endif 70 | if HAVE_ASCIIDOC 71 | $(MAKE) asciidoc 72 | else 73 | @echo "Warning: Building of asciidoc files is disabled, check autoconf logs" 74 | endif 75 | else 76 | @echo "Warning: Building of documentation disabled by user or autoconf" 77 | endif 78 | 79 | clean-local: 80 | rm -f api/* libnl.dict *.html 81 | -------------------------------------------------------------------------------- /include/linux-private/linux/gen_stats.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 | #ifndef __LINUX_GEN_STATS_H 3 | #define __LINUX_GEN_STATS_H 4 | 5 | #include 6 | 7 | enum { 8 | TCA_STATS_UNSPEC, 9 | TCA_STATS_BASIC, 10 | TCA_STATS_RATE_EST, 11 | TCA_STATS_QUEUE, 12 | TCA_STATS_APP, 13 | TCA_STATS_RATE_EST64, 14 | TCA_STATS_PAD, 15 | __TCA_STATS_MAX, 16 | }; 17 | #define TCA_STATS_MAX (__TCA_STATS_MAX - 1) 18 | 19 | /** 20 | * struct gnet_stats_basic - byte/packet throughput statistics 21 | * @bytes: number of seen bytes 22 | * @packets: number of seen packets 23 | */ 24 | struct gnet_stats_basic { 25 | __u64 bytes; 26 | __u32 packets; 27 | }; 28 | struct gnet_stats_basic_packed { 29 | __u64 bytes; 30 | __u32 packets; 31 | } __attribute__ ((packed)); 32 | 33 | /** 34 | * struct gnet_stats_rate_est - rate estimator 35 | * @bps: current byte rate 36 | * @pps: current packet rate 37 | */ 38 | struct gnet_stats_rate_est { 39 | __u32 bps; 40 | __u32 pps; 41 | }; 42 | 43 | /** 44 | * struct gnet_stats_rate_est64 - rate estimator 45 | * @bps: current byte rate 46 | * @pps: current packet rate 47 | */ 48 | struct gnet_stats_rate_est64 { 49 | __u64 bps; 50 | __u64 pps; 51 | }; 52 | 53 | /** 54 | * struct gnet_stats_queue - queuing statistics 55 | * @qlen: queue length 56 | * @backlog: backlog size of queue 57 | * @drops: number of dropped packets 58 | * @requeues: number of requeues 59 | * @overlimits: number of enqueues over the limit 60 | */ 61 | struct gnet_stats_queue { 62 | __u32 qlen; 63 | __u32 backlog; 64 | __u32 drops; 65 | __u32 requeues; 66 | __u32 overlimits; 67 | }; 68 | 69 | /** 70 | * struct gnet_estimator - rate estimator configuration 71 | * @interval: sampling period 72 | * @ewma_log: the log of measurement window weight 73 | */ 74 | struct gnet_estimator { 75 | signed char interval; 76 | unsigned char ewma_log; 77 | }; 78 | 79 | 80 | #endif /* __LINUX_GEN_STATS_H */ 81 | --------------------------------------------------------------------------------