gtp_build_payload(): Support absent peer and SGSN address

When deleting a PDP context via "gtp-tunnel delete", we specify only
the gtp netdevice, the gtp version and the TID/TEI.  However, the
gtp_build_payload() function unconditionally created the netlink
attributes for GTPA_PEER_ADDRESS and GTPA_MS_ADDRESS, having their
addresses set to zero.  The kernel then tried to find a PDP context with
MS and PEER address of 0.0.0.0, and always failed with ENOENT.

The same problem also occurred with OsmoGGSN and OpenGGSN: PDP contexts
could be added but never removed.

The corresponding kernel change that requires this userland change
is the following commit introduced in 4.12-rc1:

commit d9e2dd122637034a0697bf268eed9233701b9dca
Author: Andreas Schultz <aschultz@tpip.net>
Date:   Thu Mar 9 17:43:00 2017 +0100

    gtp: unify genl_find_pdp and prepare for per socket lookup

Older kernels will work with libgtpnl both before and after this commit,
as they internally will simply disregard any attributes beyond TID/TEI.

Change-Id: Ie2ceb2cd6d2fb009bba01a05b5480c1ad775d619
This commit is contained in:
Harald Welte 2017-11-12 22:01:13 +09:00
parent 134d0a386d
commit 03cb4c2d66
1 changed files with 4 additions and 2 deletions

View File

@ -48,8 +48,10 @@ static void gtp_build_payload(struct nlmsghdr *nlh, struct gtp_tunnel *t)
if (t->ifns >= 0)
mnl_attr_put_u32(nlh, GTPA_NET_NS_FD, t->ifns);
mnl_attr_put_u32(nlh, GTPA_LINK, t->ifidx);
mnl_attr_put_u32(nlh, GTPA_PEER_ADDRESS, t->sgsn_addr.s_addr);
mnl_attr_put_u32(nlh, GTPA_MS_ADDRESS, t->ms_addr.s_addr);
if (t->sgsn_addr.s_addr)
mnl_attr_put_u32(nlh, GTPA_PEER_ADDRESS, t->sgsn_addr.s_addr);
if (t->ms_addr.s_addr)
mnl_attr_put_u32(nlh, GTPA_MS_ADDRESS, t->ms_addr.s_addr);
if (t->gtp_version == GTP_V0) {
mnl_attr_put_u64(nlh, GTPA_TID, t->u.v0.tid);
mnl_attr_put_u16(nlh, GTPA_FLOW, t->u.v0.flowid);