The package level var native (holding the native endianness) is
initialized at package load time. Thus there is no need to re-initalize
it in functions using it, e.g. (*Handle).filterModify, parseU32Data,
parseFwData, parseBpfData and parseMatchAllData.
This fixes a data race between these functions and any read access of
var native, e.g. in LinkDeserialize as reported in issue #633.
Also don't re-declare local variables shadowing the global package-level
var.
Fixes#633
Signed-off-by: Tobias Klauser <tobias@cilium.io>
Currently, it's cumbersome to get a link by an IP addr - one needs to
list all links and then call AddrList() for each of them.
Considering that ifindex is already available to to the parseAddr()
helper function, we can expose it to a user via the newly added
Addr.LinkIndex field. This makes the retrieving link by IP addr much
more simple.
Signed-off-by: Martynas Pumputis <m@lambda.lt>
iproute2's own netlink library asserts that the sockaddr sender pid
has to be the one of the kernel [0]. It also doesn't bail out on pid
mismatch but only skips the message instead. We've seen cases where
the latter had a pid 0; in such case we should skip to the next nl
message instead of hard bail out.
[0] https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/tree/lib/libnetlink.c
rtnl_dump_filter_l(), __rtnl_talk_iov()
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
From libnl addr.c comment:
IPv6 sends the local address as IFA_ADDRESS with no
IFA_LOCAL, IPv4 sends both IFA_LOCAL and IFA_ADDRESS
with IFA_ADDRESS being the peer address if they differ
But obviously, IPv6 sends IFA_LOCAL in case of PtP.
From iproute2 manual:
If a peer address is specified, the local address
cannot have a prefix length. The network prefix is
associated with the peer rather than with the local
address.
Currently, Validity and preference information values are ignored in
addrHandle. This adds them to the netlink message when they are passed
by the caller
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).
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.
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.
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>
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>
- Package methods only need an empty handle.
Not a regular Handle with a couple of
sockets creation/delete.
Signed-off-by: Alessandro Boch <aboch@docker.com>
- Ties to a netlink socket. All client requests
will re-use same socket. Socket released at
handle deletion.
- Also network namespace can be specified during
handle creation. Socket will be opened on the
specified network namespace.
Signed-off-by: Alessandro Boch <aboch@docker.com>
IFA_LOCAL and IFA_ADDRESS are the same for bcast interfaces,
however for point-to-point links, IFA_ADDRESS is the remote
address while IFA_LOCAL is the interface address.