Lines Matching full:key
382 static int parse_ipv6hdr(struct sk_buff *skb, struct sw_flow_key *key) in parse_ipv6hdr() argument
397 get_ipv6_ext_hdrs(skb, nh, &key->ipv6.exthdrs); in parse_ipv6hdr()
399 key->ip.proto = NEXTHDR_NONE; in parse_ipv6hdr()
400 key->ip.tos = ipv6_get_dsfield(nh); in parse_ipv6hdr()
401 key->ip.ttl = nh->hop_limit; in parse_ipv6hdr()
402 key->ipv6.label = *(__be32 *)nh & htonl(IPV6_FLOWINFO_FLOWLABEL); in parse_ipv6hdr()
403 key->ipv6.addr.src = nh->saddr; in parse_ipv6hdr()
404 key->ipv6.addr.dst = nh->daddr; in parse_ipv6hdr()
409 key->ip.frag = OVS_FRAG_TYPE_LATER; in parse_ipv6hdr()
410 key->ip.proto = NEXTHDR_FRAGMENT; in parse_ipv6hdr()
413 key->ip.frag = OVS_FRAG_TYPE_FIRST; in parse_ipv6hdr()
415 key->ip.frag = OVS_FRAG_TYPE_NONE; in parse_ipv6hdr()
420 * used to set key->ip.frag above. in parse_ipv6hdr()
427 key->ip.proto = nexthdr; in parse_ipv6hdr()
483 static void clear_vlan(struct sw_flow_key *key) in clear_vlan() argument
485 key->eth.vlan.tci = 0; in clear_vlan()
486 key->eth.vlan.tpid = 0; in clear_vlan()
487 key->eth.cvlan.tci = 0; in clear_vlan()
488 key->eth.cvlan.tpid = 0; in clear_vlan()
491 static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key) in parse_vlan() argument
496 key->eth.vlan.tci = htons(skb->vlan_tci) | htons(VLAN_CFI_MASK); in parse_vlan()
497 key->eth.vlan.tpid = skb->vlan_proto; in parse_vlan()
500 res = parse_vlan_tag(skb, &key->eth.vlan, true); in parse_vlan()
506 res = parse_vlan_tag(skb, &key->eth.cvlan, false); in parse_vlan()
551 static int parse_icmpv6(struct sk_buff *skb, struct sw_flow_key *key, in parse_icmpv6() argument
559 key->tp.src = htons(icmp->icmp6_type); in parse_icmpv6()
560 key->tp.dst = htons(icmp->icmp6_code); in parse_icmpv6()
561 memset(&key->ipv6.nd, 0, sizeof(key->ipv6.nd)); in parse_icmpv6()
580 key->ipv6.nd.target = nd->target; in parse_icmpv6()
598 if (unlikely(!is_zero_ether_addr(key->ipv6.nd.sll))) in parse_icmpv6()
600 ether_addr_copy(key->ipv6.nd.sll, in parse_icmpv6()
604 if (unlikely(!is_zero_ether_addr(key->ipv6.nd.tll))) in parse_icmpv6()
606 ether_addr_copy(key->ipv6.nd.tll, in parse_icmpv6()
618 memset(&key->ipv6.nd.target, 0, sizeof(key->ipv6.nd.target)); in parse_icmpv6()
619 memset(key->ipv6.nd.sll, 0, sizeof(key->ipv6.nd.sll)); in parse_icmpv6()
620 memset(key->ipv6.nd.tll, 0, sizeof(key->ipv6.nd.tll)); in parse_icmpv6()
625 static int parse_nsh(struct sk_buff *skb, struct sw_flow_key *key) in parse_nsh() argument
648 key->nsh.base.flags = nsh_get_flags(nh); in parse_nsh()
649 key->nsh.base.ttl = nsh_get_ttl(nh); in parse_nsh()
650 key->nsh.base.mdtype = nh->mdtype; in parse_nsh()
651 key->nsh.base.np = nh->np; in parse_nsh()
652 key->nsh.base.path_hdr = nh->path_hdr; in parse_nsh()
653 switch (key->nsh.base.mdtype) { in parse_nsh()
657 memcpy(key->nsh.context, nh->md1.context, in parse_nsh()
661 memset(key->nsh.context, 0, in parse_nsh()
675 * @key: output flow key
679 static int key_extract_l3l4(struct sk_buff *skb, struct sw_flow_key *key) in key_extract_l3l4() argument
684 if (key->eth.type == htons(ETH_P_IP)) { in key_extract_l3l4()
690 memset(&key->ip, 0, sizeof(key->ip)); in key_extract_l3l4()
691 memset(&key->ipv4, 0, sizeof(key->ipv4)); in key_extract_l3l4()
700 key->ipv4.addr.src = nh->saddr; in key_extract_l3l4()
701 key->ipv4.addr.dst = nh->daddr; in key_extract_l3l4()
703 key->ip.proto = nh->protocol; in key_extract_l3l4()
704 key->ip.tos = nh->tos; in key_extract_l3l4()
705 key->ip.ttl = nh->ttl; in key_extract_l3l4()
709 key->ip.frag = OVS_FRAG_TYPE_LATER; in key_extract_l3l4()
710 memset(&key->tp, 0, sizeof(key->tp)); in key_extract_l3l4()
715 key->ip.frag = OVS_FRAG_TYPE_FIRST; in key_extract_l3l4()
717 key->ip.frag = OVS_FRAG_TYPE_NONE; in key_extract_l3l4()
720 if (key->ip.proto == IPPROTO_TCP) { in key_extract_l3l4()
723 key->tp.src = tcp->source; in key_extract_l3l4()
724 key->tp.dst = tcp->dest; in key_extract_l3l4()
725 key->tp.flags = TCP_FLAGS_BE16(tcp); in key_extract_l3l4()
727 memset(&key->tp, 0, sizeof(key->tp)); in key_extract_l3l4()
730 } else if (key->ip.proto == IPPROTO_UDP) { in key_extract_l3l4()
733 key->tp.src = udp->source; in key_extract_l3l4()
734 key->tp.dst = udp->dest; in key_extract_l3l4()
736 memset(&key->tp, 0, sizeof(key->tp)); in key_extract_l3l4()
738 } else if (key->ip.proto == IPPROTO_SCTP) { in key_extract_l3l4()
741 key->tp.src = sctp->source; in key_extract_l3l4()
742 key->tp.dst = sctp->dest; in key_extract_l3l4()
744 memset(&key->tp, 0, sizeof(key->tp)); in key_extract_l3l4()
746 } else if (key->ip.proto == IPPROTO_ICMP) { in key_extract_l3l4()
752 key->tp.src = htons(icmp->type); in key_extract_l3l4()
753 key->tp.dst = htons(icmp->code); in key_extract_l3l4()
755 memset(&key->tp, 0, sizeof(key->tp)); in key_extract_l3l4()
759 } else if (key->eth.type == htons(ETH_P_ARP) || in key_extract_l3l4()
760 key->eth.type == htons(ETH_P_RARP)) { in key_extract_l3l4()
774 key->ip.proto = ntohs(arp->ar_op); in key_extract_l3l4()
776 key->ip.proto = 0; in key_extract_l3l4()
778 memcpy(&key->ipv4.addr.src, arp->ar_sip, sizeof(key->ipv4.addr.src)); in key_extract_l3l4()
779 memcpy(&key->ipv4.addr.dst, arp->ar_tip, sizeof(key->ipv4.addr.dst)); in key_extract_l3l4()
780 ether_addr_copy(key->ipv4.arp.sha, arp->ar_sha); in key_extract_l3l4()
781 ether_addr_copy(key->ipv4.arp.tha, arp->ar_tha); in key_extract_l3l4()
783 memset(&key->ip, 0, sizeof(key->ip)); in key_extract_l3l4()
784 memset(&key->ipv4, 0, sizeof(key->ipv4)); in key_extract_l3l4()
786 } else if (eth_p_mpls(key->eth.type)) { in key_extract_l3l4()
789 memset(&key->mpls, 0, sizeof(key->mpls)); in key_extract_l3l4()
802 memcpy(&key->mpls.lse[label_count - 1], &lse, in key_extract_l3l4()
815 key->mpls.num_labels_mask = GENMASK(label_count - 1, 0); in key_extract_l3l4()
816 } else if (key->eth.type == htons(ETH_P_IPV6)) { in key_extract_l3l4()
819 nh_len = parse_ipv6hdr(skb, key); in key_extract_l3l4()
823 memset(&key->ip, 0, sizeof(key->ip)); in key_extract_l3l4()
824 memset(&key->ipv6.addr, 0, sizeof(key->ipv6.addr)); in key_extract_l3l4()
836 if (key->ip.frag == OVS_FRAG_TYPE_LATER) { in key_extract_l3l4()
837 memset(&key->tp, 0, sizeof(key->tp)); in key_extract_l3l4()
841 key->ip.frag = OVS_FRAG_TYPE_FIRST; in key_extract_l3l4()
844 if (key->ip.proto == NEXTHDR_TCP) { in key_extract_l3l4()
847 key->tp.src = tcp->source; in key_extract_l3l4()
848 key->tp.dst = tcp->dest; in key_extract_l3l4()
849 key->tp.flags = TCP_FLAGS_BE16(tcp); in key_extract_l3l4()
851 memset(&key->tp, 0, sizeof(key->tp)); in key_extract_l3l4()
853 } else if (key->ip.proto == NEXTHDR_UDP) { in key_extract_l3l4()
856 key->tp.src = udp->source; in key_extract_l3l4()
857 key->tp.dst = udp->dest; in key_extract_l3l4()
859 memset(&key->tp, 0, sizeof(key->tp)); in key_extract_l3l4()
861 } else if (key->ip.proto == NEXTHDR_SCTP) { in key_extract_l3l4()
864 key->tp.src = sctp->source; in key_extract_l3l4()
865 key->tp.dst = sctp->dest; in key_extract_l3l4()
867 memset(&key->tp, 0, sizeof(key->tp)); in key_extract_l3l4()
869 } else if (key->ip.proto == NEXTHDR_ICMP) { in key_extract_l3l4()
871 error = parse_icmpv6(skb, key, nh_len); in key_extract_l3l4()
875 memset(&key->tp, 0, sizeof(key->tp)); in key_extract_l3l4()
878 } else if (key->eth.type == htons(ETH_P_NSH)) { in key_extract_l3l4()
879 error = parse_nsh(skb, key); in key_extract_l3l4()
887 * key_extract - extracts a flow key from an Ethernet frame.
890 * @key: output flow key
901 * - skb->transport_header: If key->eth.type is ETH_P_IP or ETH_P_IPV6
904 * For other key->eth.type values it is left untouched.
907 * Equals to key->eth.type.
911 static int key_extract(struct sk_buff *skb, struct sw_flow_key *key) in key_extract() argument
916 key->tp.flags = 0; in key_extract()
921 clear_vlan(key); in key_extract()
922 if (ovs_key_mac_proto(key) == MAC_PROTO_NONE) { in key_extract()
927 key->eth.type = skb->protocol; in key_extract()
930 ether_addr_copy(key->eth.src, eth->h_source); in key_extract()
931 ether_addr_copy(key->eth.dst, eth->h_dest); in key_extract()
938 if (unlikely(parse_vlan(skb, key))) in key_extract()
941 key->eth.type = parse_ethertype(skb); in key_extract()
942 if (unlikely(key->eth.type == htons(0))) in key_extract()
949 if (key->eth.cvlan.tci & htons(VLAN_CFI_MASK)) in key_extract()
950 skb->protocol = key->eth.cvlan.tpid; in key_extract()
952 skb->protocol = key->eth.type; in key_extract()
960 /* Fill out L3/L4 key info, if any */ in key_extract()
961 return key_extract_l3l4(skb, key); in key_extract()
967 int ovs_flow_key_update_l3l4(struct sk_buff *skb, struct sw_flow_key *key) in ovs_flow_key_update_l3l4() argument
969 return key_extract_l3l4(skb, key); in ovs_flow_key_update_l3l4()
972 int ovs_flow_key_update(struct sk_buff *skb, struct sw_flow_key *key) in ovs_flow_key_update() argument
976 res = key_extract(skb, key); in ovs_flow_key_update()
978 key->mac_proto &= ~SW_FLOW_KEY_INVALID; in ovs_flow_key_update()
998 struct sk_buff *skb, struct sw_flow_key *key) in ovs_flow_key_extract() argument
1009 key->tun_proto = ip_tunnel_info_af(tun_info); in ovs_flow_key_extract()
1010 memcpy(&key->tun_key, &tun_info->key, sizeof(key->tun_key)); in ovs_flow_key_extract()
1015 > sizeof(key->tun_opts)); in ovs_flow_key_extract()
1017 ip_tunnel_info_opts_get(TUN_METADATA_OPTS(key, tun_info->options_len), in ovs_flow_key_extract()
1019 key->tun_opts_len = tun_info->options_len; in ovs_flow_key_extract()
1021 key->tun_opts_len = 0; in ovs_flow_key_extract()
1024 key->tun_proto = 0; in ovs_flow_key_extract()
1025 key->tun_opts_len = 0; in ovs_flow_key_extract()
1026 memset(&key->tun_key, 0, sizeof(key->tun_key)); in ovs_flow_key_extract()
1029 key->phy.priority = skb->priority; in ovs_flow_key_extract()
1030 key->phy.in_port = OVS_CB(skb)->input_vport->port_no; in ovs_flow_key_extract()
1031 key->phy.skb_mark = skb->mark; in ovs_flow_key_extract()
1032 key->ovs_flow_hash = 0; in ovs_flow_key_extract()
1036 key->mac_proto = res; in ovs_flow_key_extract()
1041 key->recirc_id = tc_ext ? tc_ext->chain : 0; in ovs_flow_key_extract()
1048 key->recirc_id = 0; in ovs_flow_key_extract()
1051 key->recirc_id = 0; in ovs_flow_key_extract()
1054 err = key_extract(skb, key); in ovs_flow_key_extract()
1056 ovs_ct_fill_key(skb, key, post_ct); /* Must be after key_extract(). */ in ovs_flow_key_extract()
1059 key->ct_zone = zone; in ovs_flow_key_extract()
1062 key->ct_state &= ~OVS_CS_F_DST_NAT; in ovs_flow_key_extract()
1064 key->ct_state &= ~OVS_CS_F_SRC_NAT; in ovs_flow_key_extract()
1073 struct sw_flow_key *key, bool log) in ovs_flow_key_extract_userspace() argument
1084 err = ovs_nla_get_flow_metadata(net, a, attrs, key, log); in ovs_flow_key_extract_userspace()
1093 * For L2 packet key eth type would be zero. skb protocol in ovs_flow_key_extract_userspace()
1094 * would be set to correct value later during key-extact. in ovs_flow_key_extract_userspace()
1097 skb->protocol = key->eth.type; in ovs_flow_key_extract_userspace()
1098 err = key_extract(skb, key); in ovs_flow_key_extract_userspace()
1103 * for packets for which it makes sense. Otherwise the key may be in ovs_flow_key_extract_userspace()
1104 * corrupted due to overlapping key fields. in ovs_flow_key_extract_userspace()
1107 key->eth.type != htons(ETH_P_IP)) in ovs_flow_key_extract_userspace()
1110 (key->eth.type != htons(ETH_P_IPV6) || in ovs_flow_key_extract_userspace()
1111 sw_flow_key_is_nd(key))) in ovs_flow_key_extract_userspace()