Skip to content

Commit

Permalink
Buffer packets with sequence numbers in GTP header. (#132)
Browse files Browse the repository at this point in the history
* Buffer packets with sequence numbers in GTP header.

* add comments

* Update the position of GTP5G_BUFFER_SEQ_NUMBER.

---------

Co-authored-by: ycchen <[email protected]>
  • Loading branch information
chen042531 and ycchen authored Jan 14, 2025
1 parent 623ad6e commit 83306b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/encap.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum gtp5g_buffer_attrs {
GTP5G_BUFFER_ID,
GTP5G_BUFFER_SEID,
GTP5G_BUFFER_ACTION,
GTP5G_BUFFER_SEQ_NUMBER,

/* Add newly supported feature ON ABOVE
* for compatability with older version of
Expand Down
19 changes: 15 additions & 4 deletions src/gtpu/encap.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ static int gtp5g_buf_skb_encap(struct sk_buff *skb, struct net_device *dev,
GTP5G_ERR(dev, "Failed to pull GTP-U and UDP headers\n");
return PKT_DROPPED;
}
// Increment the sequence number for the packet
far->seq_number++;

if (pdr_addr_is_netlink(pdr)) {
if (netlink_send(pdr, far, skb, dev_net(dev), NULL, 0) < 0) {
Expand Down Expand Up @@ -414,10 +416,11 @@ static int netlink_send(struct pdr *pdr, struct far *far, struct sk_buff *skb_in
skb = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
} else {
skb = genlmsg_new(
nla_total_size_64bit(8) +
nla_total_size(2) +
nla_total_size(2) +
nla_total_size(skb_in->len),
nla_total_size_64bit(8) + // SEID
nla_total_size(2) + // PDR ID
nla_total_size(2) + // Action
nla_total_size(2) + // Sequence Num
nla_total_size(skb_in->len), // Buff Pkt Size
GFP_ATOMIC);
}

Expand Down Expand Up @@ -461,6 +464,12 @@ static int netlink_send(struct pdr *pdr, struct far *far, struct sk_buff *skb_in
return err;
}

err = nla_put_u16(skb, GTP5G_BUFFER_SEQ_NUMBER, far->seq_number);
if (err != 0) {
nlmsg_free(skb);
return err;
}

attr = nla_reserve(skb, GTP5G_BUFFER_PACKET, skb_in->len);
if (!attr) {
nlmsg_free(skb);
Expand Down Expand Up @@ -1022,6 +1031,8 @@ static int gtp5g_fwd_skb_ipv4(struct sk_buff *skb,
static int gtp5g_buf_skb_ipv4(struct sk_buff *skb, struct net_device *dev,
struct pdr *pdr, struct far *far)
{
// Increment the sequence number for the packet
far->seq_number++;
if (pdr_addr_is_netlink(pdr)) {
if (netlink_send(pdr, far, skb, dev_net(dev), NULL, 0) < 0) {
GTP5G_ERR(dev, "Failed to send skb to netlink socket PDR(%u)", pdr->id);
Expand Down

0 comments on commit 83306b0

Please sign in to comment.