Commit Graph

345 Commits

Author SHA1 Message Date
Ian Bishop
0e3b74dbe2 replace syscall with golang.org/x/sys/unix 2017-10-26 09:45:08 -07:00
Manohar Castelino
b7fbf1f529 Allow index specification at link creation time
Allow the caller to specify the desired link index at link creation.

This is equivalent to
ip link add link eth0 name testmacvtap index 1000 type macvtap
ip link add dummy1 index 1001 type dummy

Signed-off-by: Manohar Castelino <manohar.r.castelino@intel.com>
2017-10-26 09:40:18 -07:00
Sylvain Afchain
b2de5d10e3 Add netnsid to link attrs 2017-10-20 10:18:20 -07:00
Vincent Bernat
808afc82b2 handle: ability for force receive buffer size
This uses `SO_RCVBUFFORCE` instead of `SO_RCVBUF`. This requires to be
root and Linux 2.6.14.
2017-10-20 10:10:50 -07:00
Vincent Bernat
ef84ebb87b handle: get/set receive buffer size
When receiving a lot of route changes (10,000 routes are enough), the
default receive buffer size (value of
`/proc/sys/net/core/rmem_default`) is too small and we get a `ENOBUF`
error. A user may want to increase the buffer size up to the value of
`/proc/sys/net/core/rmem_max` (by default, this is the same value). A
`SetSocketReceiveBufferSize()` function is provided to this
destination.

Possible improvements:

 1. automatically increase receive buffer size in higher level
    functions until we hit a maximum (get an error and/or the current
    value is smaller than expected)

 2. accept a "force" argument to use `SO_RCVBUFFORCE` to increase the
    value over `rmem_max` value
2017-10-20 10:10:50 -07:00
Flavio Crisciani
ef2b2c42e6 Add test to cover recv on close leak
This test spawns a go routine that subscribe for some
events while the main thread will close the socket.
The go routine will returns after 5s when the timetout
on the recv fires and the fd is actually == -1

Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
2017-10-20 10:09:56 -07:00
Flavio Crisciani
6177f17de7 Add method to set netlink recv timeout
If the socket is closed the recv that are waiting for messages
are not woken up. The result especially for Subscribe socket is
most likely a go routine leak.
This commit introduces a method to set the timeout

Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
2017-10-20 10:09:56 -07:00
Trevor Rosen
177f1ceba5 Move consts to Linux-specific file
Fixes #243
2017-09-24 11:05:54 -07:00
Julian Kornberger
619f36a9ae Convert if/else statements to switch 2017-09-24 11:05:26 -07:00
Vincent Bernat
c684918a4f Add more variant with options to subscribe functions
For link, address, route, add a `WithOptions` variant to the
`*Subscribe()` function to specify a namespace and an error
callback. Those options can be extended in the future without adding
more functions. For example, it could be possible to subscribe only
for a given family by adding a `Family` member to the appropriate
struct.

As a minor change, the private function is always suffixed by `At`,
since it was the case for route and raw netlink functions (but not for
address and link).
2017-09-24 11:01:49 -07:00
Vincent Bernat
46962a8c5d Optionally report subscription fatal errors to a callback function
When a fatal error happens in a `*Subscribe*()` function, the error
was not available to the user. We add a callback function that will be
invoked when such an error happens.

This also modifies the behavior of `AddrSubscribe*()` function to turn
parse errors into fatal errors, as it happens with the other functions.
2017-09-24 11:01:49 -07:00
Vincent Bernat
cda96d38a7 route: add Equal() method to compare routes
All fields are compared for strict equality.
2017-09-24 11:00:50 -07:00
Vincent Bernat
bda7895ec3 route: introduce ipNetEqual() helper function
This tests equality between two IPNet pointers.
2017-09-24 11:00:50 -07:00
Vincent Bernat
067fdf3bb1 route: fix display of nexthop gateway for multipath routes
This is a `net.IP` and therefore, we should use `%s`. Using `%d` gives
something like this:

    Gw: [0 0 0 0 0 0 0 0 0 0 255 255 192 168 24 2]

After this fix, we get:

    Gw: 192.168.24.2
2017-09-24 11:00:10 -07:00
Zvi "CtrlZvi" Effron
933b978eae Add support for loading XDP programs with flags 2017-09-05 23:17:00 -07:00
Zvi "CtrlZvi" Effron
241d179eba Fix failing XDP test
On newer linux kernels (4.12), netlink rejects a request to set an XDP
program with flags set to 0. Instead, flags need to not be specified if they
are 0.
2017-09-05 23:17:00 -07:00
Manohar Castelino
7d0c00f02e gre tunnel: Add support for gre tunnels
Add support for creating and managing gre tunnels.
This is equivalent to

Point to Point:
ip tunnel add tun4 mode gre local 192.0.2.1 remote 203.0.113.6 key 123

Point to Multipoint:
ip tunnel add tun8 mode gre local 192.0.2.1 key 1234

Signed-off-by: Manohar Castelino <manohar.r.castelino@intel.com>
2017-09-05 23:15:55 -07:00
Manohar Castelino
921f7441f1 ip neighbour: Add support for lladdr to be an IP address
The ip neighbour supports adding of peers statically using commands
where the lladdr is an IP address.

ip neighbor add 10.0.0.2 lladdr 203.0.113.6 dev tun8

This is used in the case of point-to-multipoint GRE to setup the
remote end point of the tunnel

Note that link-layer address and neighbor address are both IP addresses

Signed-off-by: Manohar Castelino <manohar.r.castelino@intel.com>
2017-09-05 23:15:55 -07:00
Dan Winship
8a610f1e24 Add LinkSetTxQLen 2017-09-05 23:13:55 -07:00
kishiguro
4fe6bd0383 Add Family to struct Rule so that user can specify address family. 2017-09-05 23:13:17 -07:00
Vishvananda Ishaya Abrams
a98f31ffc7 filter pfifo qdiscs in tests 2017-09-05 22:56:13 -07:00
tcely
f5a6f697a5 Calculate the broadcast address
This is like "ip addr add 127.0.0.1/8 broadcast +" and prevents interfaces without broadcast addresses.

Configuring the IP and netmask, but not the broadcast address leaves many applications in a broken state on Linux interfaces.
2017-08-08 08:43:08 -07:00
Parav Pandit
06ccf872a2 Corrected library function to have Vf prefix
Corrected function signature to have correct name LinkSetVfTrust
instead of LinkSetTrust.
This aligns with code comment and rest of the other VF functions.

Signed-off-by: Parav Pandit <parav@mellanox.com>
2017-08-07 21:21:46 -07:00
Parav Pandit
70cf3c74a8 Add support for setting trust state of a VF
Add support for setting trust state of a VF. This allows restricting
certain operations on VF when its untrusted such as disabling
promiscuous mode.

Signed-off-by: Parav Pandit <parav@mellanox.com>
2017-08-07 09:10:47 -07:00
Parav Pandit
a956595377 Add support to set spoof check attribute for VF
Add support to enable/disable spoof check for a VF

Signed-off-by: Parav Pandit <parav@mellanox.com>
2017-08-01 18:23:44 -07:00
Sibi Chakravarthy
8d7f7aad19 added missing mark in Sprintf 2017-07-18 16:23:47 -07:00
Sibi Chakravarthy
aeeae373ad constant bug fix 2017-07-18 16:23:47 -07:00
sibi
a56439f1e4 added-mark 2017-07-18 14:16:10 -07:00
Tobias Klauser
8c5a115d79 Add support for IFLA_XDP_PROG_ID
Allow to get IFLA_XDP_PROG_ID which will be part of Linux kernel 4.13+.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-07-09 20:04:06 -07:00
Tobias Klauser
b1eba2e916 Fix go vet issues in tests
Fix the following two issues reported by go vet:

  bridge_linux_test.go:41: possible formatting directive in Fatal call
  filter_test.go:204: possible formatting directive in Fatal call

by using Fatalf instead of Fatal when using formatting directives.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-07-05 07:46:37 -07:00
John-Lin
a43807d906 fixed build error and imported not used 2017-06-30 17:10:56 -07:00
Shaun Crampton
6e453822d8 Make conntrack filter into an interface to allow for custom filters. 2017-06-30 11:43:20 -07:00
Thomas Graf
4e28683688 link: Add support for IFLA_*_COLLECT_METADATA
- Implemented for VXLAN and GRE via a flag `FlowBased`
- Added unit tests to verify ability

Signed-off-by: Thomas Graf <tgraf@tgraf.ch>
2017-06-13 11:05:35 -07:00
Chun Chen
7593cff56f Add bridge vlan support 2017-06-13 11:04:51 -07:00
Aaron Lehmann
bd6d5de5cc nl: Use atomic load/store for fd field
This allows Close to be called concurrently with Receive without
triggering a data race.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-06-06 09:06:09 -07:00
Stuart McLaren
7bd45e5974 Add extra bond parameters
Add bond parameters corresponding to:

* IFLA_BOND_AD_ACTOR_SYS_PRIO
* IFLA_BOND_AD_USER_PORT_KEY
* IFLA_BOND_AD_ACTOR_SYSTEM
* IFLA_BOND_TLB_DYNAMIC_LB

These are available in new(ish) kernels.
2017-05-31 12:03:01 -07:00
Mohamed Elawadi
7d9b424492 link-add: support hardware address 2017-05-31 12:01:59 -07:00
Anirudh Aithal
99091d8440 add a named error when links are not found
A new error type LinkNotFoundError is returned instead
of the default error type to facilitate better error
handling by downstream consumers of this package
2017-05-24 13:54:39 -07:00
Fabio Kung
0872fbf301 allow listing all routes tables with a Table:RT_TABLE_UNSPEC filter
Replicate the behavior of ip route show table all, which is the same as
ip route show table 0

Signed-off-by: Fabio Kung <fabio.kung@gmail.com>
2017-05-17 17:11:14 -07:00
Taku Fukushima
a66e14955d Fix byte order and reference bug of U32 filters
This patch fixes the bug of U32 filters which byte orders are not
appropriately updated based on the endianess of the host. Golang's
range returns copied values instead of their references when it
iterates through a map and the indices should be used to access the
specific value of the map by reference.

This patch also fixes the bug of netlink.FilterAdd that breaks the user
facing model changing  the type of cSel, the copied TcU32Sel, from its
pointer to the struct. Previously the pointer is copied and therefore
the data that is given by the users is modified if the endiannesses of
the fields in it need to be changed.

To validate these changes, I added the validation that the user facing
model is identical before and after netlink.FilterAdd. In addition to
that, the fix for the reference bug enables the endianness validations
in the same test case.

Signed-off-by: Taku Fukushima <taku@soracom.jp>
2017-05-15 20:56:34 -07:00
Wataru Ishida
58c32ae2d7 Add support for GPRS Tunnelling Protocol(GTP)
Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
2017-05-06 23:07:19 -07:00
Wataru Ishida
fe2e32c2fb Add support for generic netlink
Signed-off-by: Wataru Ishida <ishida.wataru@lab.ntt.co.jp>
2017-05-06 23:07:19 -07:00
Tobias Klauser
90380e4b76 Add support for IFLA_XDP_FLAGS
Allow to get/set IFLA_XDP_FLAGS which is part of Linux kernel >= 4.10.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-05-06 23:05:39 -07:00
Pengfei Ni
1e045880fb Get broadcast addr in AddrList
Signed-off-by: Pengfei Ni <feiskyer@gmail.com>
2017-05-02 09:48:45 -07:00
Craig Furman
2632e243fb Can set some bridge flags
* Multicast snooping and hello time are the only ones supported at the
  moment
* Only pass values to kernel when user sets them, otherwise let kernel
  decide default
* Can set multicast snooping on existing bridges
* Tests disabled on Travis CI as the kernel version is too old
* All bridge flags copied from Kernel code, but only the two mentioned
  above work
  (5a7ad1146c/include/uapi/linux/if_link.h (L232-L281))

Signed-off-by: Petar Petrov <pppepito86@gmail.com>
Signed-off-by: Ed King <eking@pivotal.io>
Signed-off-by: Konstantinos Karampogias <konstantinos.karampogias@swisscom.com>
Signed-off-by: Will Martin <wmartin@pivotal.io>
2017-04-25 08:25:47 -07:00
David J. Wilder
b71e0bb214 Add support for BR_PROXYARP and BR_PROXYARP_WIFI.
Bridge ports can be set to use the proxy arp features by calling
either LinkSetBrProxyArp() or LinkSetBrProxyArpWiFi().

Signed-off-by: David Wilder <wilder@us.ibm.com>
2017-04-22 12:52:14 -07:00
Daniel Nardo
838b9b5fcb Set the change flags to IFF_PROMISC instead of IFF_UP on the SetPromiscOn/Off functions. 2017-04-22 12:51:05 -07:00
Taku Fukushima
f321bd7f3a Remove unnecessary condition of parsing U32 data
This patch removes the unnecessary condition of parsing U32 data that
checks if sel.Flags has nl.TC_U32_TERMINAL or sel.Nkeys is not 1.
Because of the modification to U32 that enalbed to specify multiple sel
keys, this condition is not valid anymore. This condition stops the
parsing of U32 fliter data with multiple attributes and this prevents
the users from getting all the necessary attributes, e.g., the class Id
of the filter.

Signed-off-by: Taku Fukushima <taku@soracom.jp>
2017-04-21 19:36:00 -07:00
Toke Høiland-Jørgensen
1d1fee5b18 AddrUpdate: Include flags, scope and lifetimes
Having the extra data available in the notification for new addresses is useful
to, for instance, filter out temporary addresses or keep track of address
lifetimes.

Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
2017-04-12 14:03:27 -07:00
Toke Høiland-Jørgensen
69df5c75fb addr: Parse address lifetime information from IFA_CACHEINFO attr
This adds parsing of the preferred and valid lifetime information from the
netlink IFA_CACHEINFO attribute. They are stored as PreferedLft and ValidLft in
the Addr struct if found.

Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk>
2017-04-12 11:24:37 -07:00