398
404
if (unlikely(!is_zero_ether_addr(key->ipv6.nd.sll)))
400
406
ether_addr_copy(key->ipv6.nd.sll,
401
&nd->opt[offset+sizeof(*nd_opt)]);
407
&nd->opt[offset+sizeof(*nd_opt)]);
402
408
} else if (nd_opt->nd_opt_type == ND_OPT_TARGET_LL_ADDR
403
409
&& opt_len == 8) {
404
410
if (unlikely(!is_zero_ether_addr(key->ipv6.nd.tll)))
406
412
ether_addr_copy(key->ipv6.nd.tll,
407
&nd->opt[offset+sizeof(*nd_opt)]);
413
&nd->opt[offset+sizeof(*nd_opt)]);
410
416
icmp_len -= opt_len;
513
529
key->tp.src = tcp->source;
514
530
key->tp.dst = tcp->dest;
515
531
key->tp.flags = TCP_FLAGS_BE16(tcp);
533
memset(&key->tp, 0, sizeof(key->tp));
517
536
} else if (key->ip.proto == IPPROTO_UDP) {
518
537
if (udphdr_ok(skb)) {
519
538
struct udphdr *udp = udp_hdr(skb);
520
539
key->tp.src = udp->source;
521
540
key->tp.dst = udp->dest;
542
memset(&key->tp, 0, sizeof(key->tp));
523
544
} else if (key->ip.proto == IPPROTO_SCTP) {
524
545
if (sctphdr_ok(skb)) {
525
546
struct sctphdr *sctp = sctp_hdr(skb);
526
547
key->tp.src = sctp->source;
527
548
key->tp.dst = sctp->dest;
550
memset(&key->tp, 0, sizeof(key->tp));
529
552
} else if (key->ip.proto == IPPROTO_ICMP) {
530
553
if (icmphdr_ok(skb)) {
531
554
struct icmphdr *icmp = icmp_hdr(skb);
532
555
/* The ICMP type and code fields use the 16-bit
533
556
* transport port fields, so we need to store
534
* them in 16-bit network byte order. */
557
* them in 16-bit network byte order.
535
559
key->tp.src = htons(icmp->type);
536
560
key->tp.dst = htons(icmp->code);
562
memset(&key->tp, 0, sizeof(key->tp));
540
} else if ((key->eth.type == htons(ETH_P_ARP) ||
541
key->eth.type == htons(ETH_P_RARP)) && arphdr_ok(skb)) {
566
} else if (key->eth.type == htons(ETH_P_ARP) ||
567
key->eth.type == htons(ETH_P_RARP)) {
568
struct arp_eth_header *arp;
542
569
bool arp_available = arphdr_ok(skb);
543
struct arp_eth_header *arp;
545
571
arp = (struct arp_eth_header *)skb_network_header(skb);
549
575
arp->ar_pro == htons(ETH_P_IP) &&
550
576
arp->ar_hln == ETH_ALEN &&
551
577
arp->ar_pln == 4) {
552
579
/* We only match on the lower 8 bits of the opcode. */
553
580
if (ntohs(arp->ar_op) <= 0xff)
554
581
key->ip.proto = ntohs(arp->ar_op);
555
585
memcpy(&key->ipv4.addr.src, arp->ar_sip, sizeof(key->ipv4.addr.src));
556
586
memcpy(&key->ipv4.addr.dst, arp->ar_tip, sizeof(key->ipv4.addr.dst));
557
587
ether_addr_copy(key->ipv4.arp.sha, arp->ar_sha);
558
588
ether_addr_copy(key->ipv4.arp.tha, arp->ar_tha);
590
memset(&key->ip, 0, sizeof(key->ip));
591
memset(&key->ipv4, 0, sizeof(key->ipv4));
593
} else if (eth_p_mpls(key->eth.type)) {
594
size_t stack_len = MPLS_HLEN;
596
/* In the presence of an MPLS label stack the end of the L2
597
* header and the beginning of the L3 header differ.
599
* Advance network_header to the beginning of the L3
600
* header. mac_len corresponds to the end of the L2 header.
605
error = check_header(skb, skb->mac_len + stack_len);
609
memcpy(&lse, skb_network_header(skb), MPLS_HLEN);
611
if (stack_len == MPLS_HLEN)
612
memcpy(&key->mpls.top_lse, &lse, MPLS_HLEN);
614
skb_set_network_header(skb, skb->mac_len + stack_len);
615
if (lse & htonl(MPLS_LS_S_MASK))
618
stack_len += MPLS_HLEN;
560
620
} else if (key->eth.type == htons(ETH_P_IPV6)) {
561
621
int nh_len; /* IPv6 Header + Extensions */
563
623
nh_len = parse_ipv6hdr(skb, key);
564
624
if (unlikely(nh_len < 0)) {
625
memset(&key->ip, 0, sizeof(key->ip));
626
memset(&key->ipv6.addr, 0, sizeof(key->ipv6.addr));
565
627
if (nh_len == -EINVAL) {
566
628
skb->transport_header = skb->network_header;
583
645
key->tp.src = tcp->source;
584
646
key->tp.dst = tcp->dest;
585
647
key->tp.flags = TCP_FLAGS_BE16(tcp);
649
memset(&key->tp, 0, sizeof(key->tp));
587
651
} else if (key->ip.proto == NEXTHDR_UDP) {
588
652
if (udphdr_ok(skb)) {
589
653
struct udphdr *udp = udp_hdr(skb);
590
654
key->tp.src = udp->source;
591
655
key->tp.dst = udp->dest;
657
memset(&key->tp, 0, sizeof(key->tp));
593
659
} else if (key->ip.proto == NEXTHDR_SCTP) {
594
660
if (sctphdr_ok(skb)) {
595
661
struct sctphdr *sctp = sctp_hdr(skb);
596
662
key->tp.src = sctp->source;
597
663
key->tp.dst = sctp->dest;
665
memset(&key->tp, 0, sizeof(key->tp));
599
667
} else if (key->ip.proto == NEXTHDR_ICMP) {
600
668
if (icmp6hdr_ok(skb)) {
601
669
error = parse_icmpv6(skb, key, nh_len);
673
memset(&key->tp, 0, sizeof(key->tp));
611
int ovs_flow_key_extract(struct sk_buff *skb, struct sw_flow_key *key)
680
int ovs_flow_key_update(struct sk_buff *skb, struct sw_flow_key *key)
682
return key_extract(skb, key);
685
int ovs_flow_key_extract(const struct ovs_tunnel_info *tun_info,
686
struct sk_buff *skb, struct sw_flow_key *key)
613
688
/* Extract metadata from packet. */
615
memset(key, 0, sizeof(*key));
616
if (OVS_CB(skb)->tun_key)
617
memcpy(&key->tun_key, OVS_CB(skb)->tun_key, sizeof(key->tun_key));
690
memcpy(&key->tun_key, &tun_info->tunnel, sizeof(key->tun_key));
692
BUILD_BUG_ON(((1 << (sizeof(tun_info->options_len) * 8)) - 1) >
693
sizeof(key->tun_opts));
695
if (tun_info->options) {
696
memcpy(TUN_METADATA_OPTS(key, tun_info->options_len),
697
tun_info->options, tun_info->options_len);
698
key->tun_opts_len = tun_info->options_len;
700
key->tun_opts_len = 0;
703
key->tun_opts_len = 0;
704
memset(&key->tun_key, 0, sizeof(key->tun_key));
619
707
key->phy.priority = skb->priority;
620
708
key->phy.in_port = OVS_CB(skb)->input_vport->port_no;
621
709
key->phy.skb_mark = skb->mark;
710
key->ovs_flow_hash = 0;
623
713
return key_extract(skb, key);
626
716
int ovs_flow_key_extract_userspace(const struct nlattr *attr,
627
717
struct sk_buff *skb,
628
struct sw_flow_key *key)
718
struct sw_flow_key *key, bool log)
632
memset(key, 0, sizeof(*key));
633
722
/* Extract metadata from netlink attributes. */
634
err = ovs_nla_get_flow_metadata(attr, key);
723
err = ovs_nla_get_flow_metadata(attr, key, log);
638
727
return key_extract(skb, key);
641
int ovs_flow_key_extract_recirc(u32 recirc_id,
642
const struct sw_flow_key *key,
644
struct sw_flow_key *new_key)
646
memset(new_key, 0, sizeof(*new_key));
647
memcpy(new_key, key, OVS_SW_FLOW_KEY_METADATA_SIZE);
648
new_key->recirc_id = recirc_id;
649
return key_extract(skb, new_key);