Skip to content

Commit

Permalink
net/core: Add help functions to udp/ipv4 tunnel xmit flow
Browse files Browse the repository at this point in the history
udp_tunnel_xmit_skb/ip_tunnel_xmit_skb functions prepare udp/ ipv4
headers accordingly and xmit the packet.

This patch separate the header preparation from packet transmitting and
adds 2 help functions: udp_tunnel_prepare_skb and iptunnel_prepare

The infrastructure change will be used by the rxe driver to allow icrc
calculation after the packet headers are built and before xmiting the
package.

Issue: 535827
Change-Id: Iecd377e84f5a69cd4f1f742e5d7329e6f6ab56c1
Signed-off-by: Hadar Hen Zion <[email protected]>
  • Loading branch information
hadarhenzion committed May 13, 2015
1 parent ab1d2cd commit 148a54f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
3 changes: 3 additions & 0 deletions include/net/ip_tunnels.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ static inline u8 ip_tunnel_ecn_encap(u8 tos, const struct iphdr *iph,
}

int iptunnel_pull_header(struct sk_buff *skb, int hdr_len, __be16 inner_proto);
void iptunnel_prepare(struct rtable *rt, struct sk_buff *skb,
__be32 src, __be32 dst, __u8 proto, __u8 tos, __u8 ttl,
__be16 df, bool xnet);
int iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,
__be32 src, __be32 dst, __u8 proto,
__u8 tos, __u8 ttl, __be16 df, bool xnet);
Expand Down
5 changes: 5 additions & 0 deletions include/net/udp_tunnel.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ struct udp_tunnel_sock_cfg {
void setup_udp_tunnel_sock(struct net *net, struct socket *sock,
struct udp_tunnel_sock_cfg *sock_cfg);

void udp_tunnel_prepare_skb(struct rtable *rt, struct sk_buff *skb,
__be32 src, __be32 dst, __u8 tos, __u8 ttl,
__be16 df, __be16 src_port, __be16 dst_port,
bool xnet, bool nocheck);

/* Transmit the skb using UDP encapsulation. */
int udp_tunnel_xmit_skb(struct rtable *rt, struct sock *sk, struct sk_buff *skb,
__be32 src, __be32 dst, __u8 tos, __u8 ttl,
Expand Down
19 changes: 14 additions & 5 deletions net/ipv4/ip_tunnel_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@
#include <net/netns/generic.h>
#include <net/rtnetlink.h>

int iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,
__be32 src, __be32 dst, __u8 proto,
__u8 tos, __u8 ttl, __be16 df, bool xnet)
void iptunnel_prepare(struct rtable *rt, struct sk_buff *skb,
__be32 src, __be32 dst, __u8 proto,
__u8 tos, __u8 ttl, __be16 df, bool xnet)
{
int pkt_len = skb->len;
struct iphdr *iph;
int err;

skb_scrub_packet(skb, xnet);

Expand All @@ -76,6 +74,17 @@ int iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,
iph->ttl = ttl;
__ip_select_ident(dev_net(rt->dst.dev), iph,
skb_shinfo(skb)->gso_segs ?: 1);
}
EXPORT_SYMBOL_GPL(iptunnel_prepare);

int iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,
__be32 src, __be32 dst, __u8 proto,
__u8 tos, __u8 ttl, __be16 df, bool xnet)
{
int err;
int pkt_len = skb->len;

iptunnel_prepare(rt, skb, src, dst, proto, tos, ttl, df, xnet);

err = ip_local_out_sk(sk, skb);
if (unlikely(net_xmit_eval(err)))
Expand Down
18 changes: 14 additions & 4 deletions net/ipv4/udp_tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ void setup_udp_tunnel_sock(struct net *net, struct socket *sock,
}
EXPORT_SYMBOL_GPL(setup_udp_tunnel_sock);

int udp_tunnel_xmit_skb(struct rtable *rt, struct sock *sk, struct sk_buff *skb,
__be32 src, __be32 dst, __u8 tos, __u8 ttl,
__be16 df, __be16 src_port, __be16 dst_port,
bool xnet, bool nocheck)
void udp_tunnel_prepare_skb(struct rtable *rt, struct sk_buff *skb,
__be32 src, __be32 dst, __u8 tos, __u8 ttl,
__be16 df, __be16 src_port, __be16 dst_port,
bool xnet, bool nocheck)
{
struct udphdr *uh;

Expand All @@ -99,6 +99,16 @@ int udp_tunnel_xmit_skb(struct rtable *rt, struct sock *sk, struct sk_buff *skb,
uh->len = htons(skb->len);

udp_set_csum(nocheck, skb, src, dst, skb->len);
}
EXPORT_SYMBOL_GPL(udp_tunnel_prepare_skb);

int udp_tunnel_xmit_skb(struct rtable *rt, struct sock *sk, struct sk_buff *skb,
__be32 src, __be32 dst, __u8 tos, __u8 ttl,
__be16 df, __be16 src_port, __be16 dst_port,
bool xnet, bool nocheck)
{
udp_tunnel_prepare_skb(rt, skb, src, dst, tos, ttl, df, src_port,
dst_port, xnet, nocheck);

return iptunnel_xmit(sk, rt, skb, src, dst, IPPROTO_UDP,
tos, ttl, df, xnet);
Expand Down

0 comments on commit 148a54f

Please sign in to comment.