libgtpnl: add flow id support

Add new attribute to the gtp tunnel object, this extension is required
by GTPv0 since the same flowid needs to be used for uplink and downlink
packet.
This commit is contained in:
Pablo Neira Ayuso 2014-03-20 13:56:55 +01:00
parent a03b3754d6
commit e83f70671e
6 changed files with 27 additions and 11 deletions

View File

@ -13,11 +13,13 @@ void gtp_tunnel_set_ms_ip4(struct gtp_tunnel *t, struct in_addr *ms_addr);
void gtp_tunnel_set_sgsn_ip4(struct gtp_tunnel *t, struct in_addr *sgsn_addr);
void gtp_tunnel_set_version(struct gtp_tunnel *t, uint32_t version);
void gtp_tunnel_set_tid(struct gtp_tunnel *t, uint64_t tid);
void gtp_tunnel_set_flowid(struct gtp_tunnel *t, uint16_t flowid);
const uint32_t gtp_tunnel_get_ifidx(struct gtp_tunnel *t);
const struct in_addr *gtp_tunnel_get_ms_ip4(struct gtp_tunnel *t);
const struct in_addr *gtp_tunnel_get_sgsn_ip4(struct gtp_tunnel *t);
int gtp_tunnel_get_version(struct gtp_tunnel *t);
uint64_t gtp_tunnel_get_tid(struct gtp_tunnel *t);
uint16_t gtp_tunnel_get_flowid(struct gtp_tunnel *t);
#endif

View File

@ -39,6 +39,7 @@ enum gtp_attrs {
GTPA_TID, /* 64 bits for GTPv1 */
GTPA_SGSN_ADDRESS,
GTPA_MS_ADDRESS,
GTPA_FLOWID, /* only for GTPv0 */
__GTPA_MAX,
};
#define GTPA_MAX (__GTPA_MAX + 1)

View File

@ -19,15 +19,14 @@
#include "internal.h"
static void gtp_build_payload(struct nlmsghdr *nlh, uint64_t tid,
uint32_t ifidx, uint32_t sgsn_addr,
uint32_t ms_addr, uint32_t version)
static void gtp_build_payload(struct nlmsghdr *nlh, struct gtp_tunnel *t)
{
mnl_attr_put_u32(nlh, GTPA_VERSION, version);
mnl_attr_put_u32(nlh, GTPA_LINK, ifidx);
mnl_attr_put_u32(nlh, GTPA_SGSN_ADDRESS, sgsn_addr);
mnl_attr_put_u32(nlh, GTPA_MS_ADDRESS, ms_addr);
mnl_attr_put_u64(nlh, GTPA_TID, tid);
mnl_attr_put_u32(nlh, GTPA_VERSION, t->gtp_version);
mnl_attr_put_u32(nlh, GTPA_LINK, t->ifidx);
mnl_attr_put_u32(nlh, GTPA_SGSN_ADDRESS, t->sgsn_addr.s_addr);
mnl_attr_put_u32(nlh, GTPA_MS_ADDRESS, t->ms_addr.s_addr);
mnl_attr_put_u64(nlh, GTPA_TID, t->tid);
mnl_attr_put_u16(nlh, GTPA_FLOWID, t->flowid);
}
int gtp_add_tunnel(int genl_id, struct mnl_socket *nl, struct gtp_tunnel *t)
@ -44,8 +43,7 @@ int gtp_add_tunnel(int genl_id, struct mnl_socket *nl, struct gtp_tunnel *t)
nlh = genl_nlmsg_build_hdr(buf, genl_id, NLM_F_EXCL | NLM_F_ACK, ++seq,
GTP_CMD_TUNNEL_NEW);
gtp_build_payload(nlh, t->tid, t->ifidx, t->sgsn_addr.s_addr,
t->ms_addr.s_addr, t->gtp_version);
gtp_build_payload(nlh, t);
if (genl_socket_talk(nl, nlh, seq, NULL, NULL) < 0)
perror("genl_socket_talk");
@ -62,7 +60,7 @@ int gtp_del_tunnel(int genl_id, struct mnl_socket *nl, struct gtp_tunnel *t)
nlh = genl_nlmsg_build_hdr(buf, genl_id, NLM_F_ACK, ++seq,
GTP_CMD_TUNNEL_DELETE);
gtp_build_payload(nlh, t->tid, t->ifidx, 0, 0, t->gtp_version);
gtp_build_payload(nlh, t);
if (genl_socket_talk(nl, nlh, seq, NULL, NULL) < 0)
perror("genl_socket_talk");

View File

@ -47,6 +47,12 @@ void gtp_tunnel_set_tid(struct gtp_tunnel *t, uint64_t tid)
}
EXPORT_SYMBOL(gtp_tunnel_set_tid);
void gtp_tunnel_set_flowid(struct gtp_tunnel *t, uint16_t flowid)
{
t->flowid = flowid;
}
EXPORT_SYMBOL(gtp_tunnel_set_flowid);
const uint32_t gtp_tunnel_get_ifidx(struct gtp_tunnel *t)
{
return t->ifidx;
@ -76,3 +82,9 @@ uint64_t gtp_tunnel_get_tid(struct gtp_tunnel *t)
return t->tid;
}
EXPORT_SYMBOL(gtp_tunnel_get_tid);
uint16_t gtp_tunnel_get_flowid(struct gtp_tunnel *t)
{
return t->flowid;
}
EXPORT_SYMBOL(gtp_tunnel_get_flowid);

View File

@ -17,6 +17,7 @@ struct gtp_tunnel {
struct in_addr ms_addr;
struct in_addr sgsn_addr;
uint64_t tid;
uint16_t flowid;
int gtp_version;
};

View File

@ -19,11 +19,13 @@ global:
gtp_tunnel_set_sgsn_ip4;
gtp_tunnel_set_version;
gtp_tunnel_set_tid;
gtp_tunnel_set_flowid;
gtp_tunnel_get_ifidx;
gtp_tunnel_get_ms_ip4;
gtp_tunnel_get_sgsn_ip4;
gtp_tunnel_get_version;
gtp_tunnel_get_tid;
gtp_tunnel_get_flowid;
local: *;
};