Commit d4ac05ff authored by Jiri Benc's avatar Jiri Benc Committed by David S. Miller

vxlan: introduce vxlan_hdr

Currently, pointer to the vxlan header is kept in a local variable. It has
to be reloaded whenever the pskb pull operations are performed which usually
happens somewhere deep in called functions.

Create a vxlan_hdr function and use it to reference the vxlan header
instead.
Signed-off-by: default avatarJiri Benc <jbenc@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d8ef0347
...@@ -1257,7 +1257,6 @@ static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb) ...@@ -1257,7 +1257,6 @@ static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
{ {
struct metadata_dst *tun_dst = NULL; struct metadata_dst *tun_dst = NULL;
struct vxlan_sock *vs; struct vxlan_sock *vs;
struct vxlanhdr *vxh;
u32 flags, vni; u32 flags, vni;
struct vxlan_metadata _md; struct vxlan_metadata _md;
struct vxlan_metadata *md = &_md; struct vxlan_metadata *md = &_md;
...@@ -1266,9 +1265,8 @@ static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb) ...@@ -1266,9 +1265,8 @@ static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
if (!pskb_may_pull(skb, VXLAN_HLEN)) if (!pskb_may_pull(skb, VXLAN_HLEN))
goto error; goto error;
vxh = (struct vxlanhdr *)(udp_hdr(skb) + 1); flags = ntohl(vxlan_hdr(skb)->vx_flags);
flags = ntohl(vxh->vx_flags); vni = ntohl(vxlan_hdr(skb)->vx_vni);
vni = ntohl(vxh->vx_vni);
if (flags & VXLAN_HF_VNI) { if (flags & VXLAN_HF_VNI) {
flags &= ~VXLAN_HF_VNI; flags &= ~VXLAN_HF_VNI;
...@@ -1279,16 +1277,14 @@ static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb) ...@@ -1279,16 +1277,14 @@ static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
if (iptunnel_pull_header(skb, VXLAN_HLEN, htons(ETH_P_TEB))) if (iptunnel_pull_header(skb, VXLAN_HLEN, htons(ETH_P_TEB)))
goto drop; goto drop;
vxh = (struct vxlanhdr *)(udp_hdr(skb) + 1);
vs = rcu_dereference_sk_user_data(sk); vs = rcu_dereference_sk_user_data(sk);
if (!vs) if (!vs)
goto drop; goto drop;
if ((flags & VXLAN_HF_RCO) && (vs->flags & VXLAN_F_REMCSUM_RX)) { if ((flags & VXLAN_HF_RCO) && (vs->flags & VXLAN_F_REMCSUM_RX)) {
vxh = vxlan_remcsum(skb, vxh, sizeof(struct vxlanhdr), vni, if (!vxlan_remcsum(skb, vxlan_hdr(skb), sizeof(struct vxlanhdr), vni,
!!(vs->flags & VXLAN_F_REMCSUM_NOPARTIAL)); !!(vs->flags & VXLAN_F_REMCSUM_NOPARTIAL)))
if (!vxh)
goto drop; goto drop;
flags &= ~VXLAN_HF_RCO; flags &= ~VXLAN_HF_RCO;
...@@ -1313,7 +1309,7 @@ static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb) ...@@ -1313,7 +1309,7 @@ static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
if ((flags & VXLAN_HF_GBP) && (vs->flags & VXLAN_F_GBP)) { if ((flags & VXLAN_HF_GBP) && (vs->flags & VXLAN_F_GBP)) {
struct vxlanhdr_gbp *gbp; struct vxlanhdr_gbp *gbp;
gbp = (struct vxlanhdr_gbp *)vxh; gbp = (struct vxlanhdr_gbp *)vxlan_hdr(skb);
md->gbp = ntohs(gbp->policy_id); md->gbp = ntohs(gbp->policy_id);
if (tun_dst) if (tun_dst)
...@@ -1351,7 +1347,8 @@ static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb) ...@@ -1351,7 +1347,8 @@ static int vxlan_udp_encap_recv(struct sock *sk, struct sk_buff *skb)
bad_flags: bad_flags:
netdev_dbg(skb->dev, "invalid vxlan flags=%#x vni=%#x\n", netdev_dbg(skb->dev, "invalid vxlan flags=%#x vni=%#x\n",
ntohl(vxh->vx_flags), ntohl(vxh->vx_vni)); ntohl(vxlan_hdr(skb)->vx_flags),
ntohl(vxlan_hdr(skb)->vx_vni));
error: error:
if (tun_dst) if (tun_dst)
......
...@@ -262,6 +262,11 @@ static inline netdev_features_t vxlan_features_check(struct sk_buff *skb, ...@@ -262,6 +262,11 @@ static inline netdev_features_t vxlan_features_check(struct sk_buff *skb,
/* IPv6 header + UDP + VXLAN + Ethernet header */ /* IPv6 header + UDP + VXLAN + Ethernet header */
#define VXLAN6_HEADROOM (40 + 8 + 8 + 14) #define VXLAN6_HEADROOM (40 + 8 + 8 + 14)
static inline struct vxlanhdr *vxlan_hdr(struct sk_buff *skb)
{
return (struct vxlanhdr *)(udp_hdr(skb) + 1);
}
#if IS_ENABLED(CONFIG_VXLAN) #if IS_ENABLED(CONFIG_VXLAN)
void vxlan_get_rx_port(struct net_device *netdev); void vxlan_get_rx_port(struct net_device *netdev);
#else #else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment