Skip to content

Commit ed246ce

Browse files
jahurleydavem330
authored andcommitted
net: core: move pop MPLS functionality from OvS to core helper
Open vSwitch provides code to pop an MPLS header to a packet. In preparation for supporting this in TC, move the pop code to an skb helper that can be reused. Remove the, now unused, update_ethertype static function from OvS. Signed-off-by: John Hurley <john.hurley@netronome.com> Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Simon Horman <simon.horman@netronome.com> Reviewed-by: Willem de Bruijn <willemb@google.com> Acked-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8822e27 commit ed246ce

3 files changed

Lines changed: 45 additions & 35 deletions

File tree

‎include/linux/skbuff.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3448,6 +3448,7 @@ int __skb_vlan_pop(struct sk_buff *skb, u16 *vlan_tci);
34483448
int skb_vlan_pop(struct sk_buff *skb);
34493449
int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci);
34503450
int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto);
3451+
int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto);
34513452
struct sk_buff *pskb_extract(struct sk_buff *skb, int off, int to_copy,
34523453
gfp_t gfp);
34533454

‎net/core/skbuff.c‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5489,6 +5489,48 @@ int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto)
54895489
}
54905490
EXPORT_SYMBOL_GPL(skb_mpls_push);
54915491

5492+
/**
5493+
* skb_mpls_pop() - pop the outermost MPLS header
5494+
*
5495+
* @skb: buffer
5496+
* @next_proto: ethertype of header after popped MPLS header
5497+
*
5498+
* Expects skb->data at mac header.
5499+
*
5500+
* Returns 0 on success, -errno otherwise.
5501+
*/
5502+
int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto)
5503+
{
5504+
int err;
5505+
5506+
if (unlikely(!eth_p_mpls(skb->protocol)))
5507+
return -EINVAL;
5508+
5509+
err = skb_ensure_writable(skb, skb->mac_len + MPLS_HLEN);
5510+
if (unlikely(err))
5511+
return err;
5512+
5513+
skb_postpull_rcsum(skb, mpls_hdr(skb), MPLS_HLEN);
5514+
memmove(skb_mac_header(skb) + MPLS_HLEN, skb_mac_header(skb),
5515+
skb->mac_len);
5516+
5517+
__skb_pull(skb, MPLS_HLEN);
5518+
skb_reset_mac_header(skb);
5519+
skb_set_network_header(skb, skb->mac_len);
5520+
5521+
if (skb->dev && skb->dev->type == ARPHRD_ETHER) {
5522+
struct ethhdr *hdr;
5523+
5524+
/* use mpls_hdr() to get ethertype to account for VLANs. */
5525+
hdr = (struct ethhdr *)((void *)mpls_hdr(skb) - ETH_HLEN);
5526+
skb_mod_eth_type(skb, hdr, next_proto);
5527+
}
5528+
skb->protocol = next_proto;
5529+
5530+
return 0;
5531+
}
5532+
EXPORT_SYMBOL_GPL(skb_mpls_pop);
5533+
54925534
/**
54935535
* alloc_skb_with_frags - allocate skb with page frags
54945536
*

‎net/openvswitch/actions.c‎

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,6 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
160160
struct sw_flow_key *key,
161161
const struct nlattr *attr, int len);
162162

163-
static void update_ethertype(struct sk_buff *skb, struct ethhdr *hdr,
164-
__be16 ethertype)
165-
{
166-
if (skb->ip_summed == CHECKSUM_COMPLETE) {
167-
__be16 diff[] = { ~(hdr->h_proto), ethertype };
168-
169-
skb->csum = csum_partial((char *)diff, sizeof(diff), skb->csum);
170-
}
171-
172-
hdr->h_proto = ethertype;
173-
}
174-
175163
static int push_mpls(struct sk_buff *skb, struct sw_flow_key *key,
176164
const struct ovs_action_push_mpls *mpls)
177165
{
@@ -190,31 +178,10 @@ static int pop_mpls(struct sk_buff *skb, struct sw_flow_key *key,
190178
{
191179
int err;
192180

193-
err = skb_ensure_writable(skb, skb->mac_len + MPLS_HLEN);
194-
if (unlikely(err))
181+
err = skb_mpls_pop(skb, ethertype);
182+
if (err)
195183
return err;
196184

197-
skb_postpull_rcsum(skb, mpls_hdr(skb), MPLS_HLEN);
198-
199-
memmove(skb_mac_header(skb) + MPLS_HLEN, skb_mac_header(skb),
200-
skb->mac_len);
201-
202-
__skb_pull(skb, MPLS_HLEN);
203-
skb_reset_mac_header(skb);
204-
skb_set_network_header(skb, skb->mac_len);
205-
206-
if (ovs_key_mac_proto(key) == MAC_PROTO_ETHERNET) {
207-
struct ethhdr *hdr;
208-
209-
/* mpls_hdr() is used to locate the ethertype field correctly in the
210-
* presence of VLAN tags.
211-
*/
212-
hdr = (struct ethhdr *)((void *)mpls_hdr(skb) - ETH_HLEN);
213-
update_ethertype(skb, hdr, ethertype);
214-
}
215-
if (eth_p_mpls(skb->protocol))
216-
skb->protocol = ethertype;
217-
218185
invalidate_flow_key(key);
219186
return 0;
220187
}

0 commit comments

Comments
 (0)