Skip to content

Commit 559101a

Browse files
committed
gtp: remove IPv4 and IPv6 header from context object
Based on the idea that ip_tunnel_get_dsfield() provides the tos field regardless the IP version, use either iph->tos or ipv6_get_dsfield(). This comes in preparation to support for IPv4-in-IPv6-GTP and IPv6-in-IPv4-GTP. Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent e075880 commit 559101a

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

drivers/net/gtp.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -927,10 +927,6 @@ static inline void gtp1_push_header(struct sk_buff *skb, struct pdp_ctx *pctx)
927927

928928
struct gtp_pktinfo {
929929
struct sock *sk;
930-
union {
931-
struct iphdr *iph;
932-
struct ipv6hdr *ip6h;
933-
};
934930
union {
935931
struct flowi4 fl4;
936932
struct flowi6 fl6;
@@ -941,6 +937,7 @@ struct gtp_pktinfo {
941937
};
942938
struct pdp_ctx *pctx;
943939
struct net_device *dev;
940+
__u8 tos;
944941
__be16 gtph_port;
945942
};
946943

@@ -959,27 +956,27 @@ static void gtp_push_header(struct sk_buff *skb, struct gtp_pktinfo *pktinfo)
959956
}
960957

961958
static inline void gtp_set_pktinfo_ipv4(struct gtp_pktinfo *pktinfo,
962-
struct sock *sk, struct iphdr *iph,
959+
struct sock *sk, __u8 tos,
963960
struct pdp_ctx *pctx, struct rtable *rt,
964961
struct flowi4 *fl4,
965962
struct net_device *dev)
966963
{
967964
pktinfo->sk = sk;
968-
pktinfo->iph = iph;
965+
pktinfo->tos = tos;
969966
pktinfo->pctx = pctx;
970967
pktinfo->rt = rt;
971968
pktinfo->fl4 = *fl4;
972969
pktinfo->dev = dev;
973970
}
974971

975972
static void gtp_set_pktinfo_ipv6(struct gtp_pktinfo *pktinfo,
976-
struct sock *sk, struct ipv6hdr *ip6h,
973+
struct sock *sk, __u8 tos,
977974
struct pdp_ctx *pctx, struct rt6_info *rt6,
978975
struct flowi6 *fl6,
979976
struct net_device *dev)
980977
{
981978
pktinfo->sk = sk;
982-
pktinfo->ip6h = ip6h;
979+
pktinfo->tos = tos;
983980
pktinfo->pctx = pctx;
984981
pktinfo->rt6 = rt6;
985982
pktinfo->fl6 = *fl6;
@@ -1057,7 +1054,7 @@ static int gtp_build_skb_ip4(struct sk_buff *skb, struct net_device *dev,
10571054
goto err_rt;
10581055
}
10591056

1060-
gtp_set_pktinfo_ipv4(pktinfo, pctx->sk, iph, pctx, rt, &fl4, dev);
1057+
gtp_set_pktinfo_ipv4(pktinfo, pctx->sk, iph->tos, pctx, rt, &fl4, dev);
10611058
gtp_push_header(skb, pktinfo);
10621059

10631060
netdev_dbg(dev, "gtp -> IP src: %pI4 dst: %pI4\n",
@@ -1080,6 +1077,7 @@ static int gtp_build_skb_ip6(struct sk_buff *skb, struct net_device *dev,
10801077
struct ipv6hdr *ip6h;
10811078
struct rt6_info *rt;
10821079
struct flowi6 fl6;
1080+
__u8 tos;
10831081
int mtu;
10841082

10851083
/* Read the IP destination address and resolve the PDP context.
@@ -1135,7 +1133,8 @@ static int gtp_build_skb_ip6(struct sk_buff *skb, struct net_device *dev,
11351133
goto err_rt;
11361134
}
11371135

1138-
gtp_set_pktinfo_ipv6(pktinfo, pctx->sk, ip6h, pctx, rt, &fl6, dev);
1136+
tos = ipv6_get_dsfield(ip6h);
1137+
gtp_set_pktinfo_ipv6(pktinfo, pctx->sk, tos, pctx, rt, &fl6, dev);
11391138
gtp_push_header(skb, pktinfo);
11401139

11411140
netdev_dbg(dev, "gtp -> IP src: %pI6 dst: %pI6\n",
@@ -1182,7 +1181,7 @@ static netdev_tx_t gtp_dev_xmit(struct sk_buff *skb, struct net_device *dev)
11821181
case ETH_P_IP:
11831182
udp_tunnel_xmit_skb(pktinfo.rt, pktinfo.sk, skb,
11841183
pktinfo.fl4.saddr, pktinfo.fl4.daddr,
1185-
pktinfo.iph->tos,
1184+
pktinfo.tos,
11861185
ip4_dst_hoplimit(&pktinfo.rt->dst),
11871186
0,
11881187
pktinfo.gtph_port, pktinfo.gtph_port,
@@ -1194,7 +1193,7 @@ static netdev_tx_t gtp_dev_xmit(struct sk_buff *skb, struct net_device *dev)
11941193
#if IS_ENABLED(CONFIG_IPV6)
11951194
udp_tunnel6_xmit_skb(&pktinfo.rt6->dst, pktinfo.sk, skb, dev,
11961195
&pktinfo.fl6.saddr, &pktinfo.fl6.daddr,
1197-
ipv6_get_dsfield(pktinfo.ip6h),
1196+
pktinfo.tos,
11981197
ip6_dst_hoplimit(&pktinfo.rt->dst),
11991198
0,
12001199
pktinfo.gtph_port, pktinfo.gtph_port,

0 commit comments

Comments
 (0)