Lines Matching +full:non +full:- +full:masked
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2007-2017 Nicira, Inc.
64 #define OVS_DEFERRED_ACTION_THRESHOLD (OVS_RECURSION_LIMIT - 2)
80 /* Make a clone of the 'key', using the pre-allocated percpu 'flow_keys'
90 key = &keys->key[level - 1]; in clone_key()
99 fifo->head = 0; in action_fifo_init()
100 fifo->tail = 0; in action_fifo_init()
105 return (fifo->head == fifo->tail); in action_fifo_is_empty()
113 return &fifo->fifo[fifo->tail++]; in action_fifo_get()
118 if (fifo->head >= DEFERRED_ACTION_FIFO_SIZE - 1) in action_fifo_put()
121 return &fifo->fifo[fifo->head++]; in action_fifo_put()
136 da->skb = skb; in add_deferred_actions()
137 da->actions = actions; in add_deferred_actions()
138 da->actions_len = actions_len; in add_deferred_actions()
139 da->pkt_key = *key; in add_deferred_actions()
147 key->mac_proto |= SW_FLOW_KEY_INVALID; in invalidate_flow_key()
152 return !(key->mac_proto & SW_FLOW_KEY_INVALID); in is_flow_key_valid()
175 key->mac_proto = MAC_PROTO_NONE; in push_mpls()
186 err = skb_mpls_pop(skb, ethertype, skb->mac_len, in pop_mpls()
192 key->mac_proto = MAC_PROTO_ETHERNET; in pop_mpls()
206 return -ENOMEM; in set_mpls()
209 lse = OVS_MASKED(stack->label_stack_entry, *mpls_lse, *mask); in set_mpls()
214 flow_key->mpls.lse[0] = lse; in set_mpls()
226 key->eth.vlan.tci = 0; in pop_vlan()
227 key->eth.vlan.tpid = 0; in pop_vlan()
238 key->eth.vlan.tci = vlan->vlan_tci; in push_vlan()
239 key->eth.vlan.tpid = vlan->vlan_tpid; in push_vlan()
241 return skb_vlan_push(skb, vlan->vlan_tpid, in push_vlan()
242 ntohs(vlan->vlan_tci) & ~VLAN_CFI_MASK); in push_vlan()
245 /* 'src' is already properly masked. */
269 ether_addr_copy_masked(eth_hdr(skb)->h_source, key->eth_src, in set_eth_addr()
270 mask->eth_src); in set_eth_addr()
271 ether_addr_copy_masked(eth_hdr(skb)->h_dest, key->eth_dst, in set_eth_addr()
272 mask->eth_dst); in set_eth_addr()
276 ether_addr_copy(flow_key->eth.src, eth_hdr(skb)->h_source); in set_eth_addr()
277 ether_addr_copy(flow_key->eth.dst, eth_hdr(skb)->h_dest); in set_eth_addr()
293 key->mac_proto = MAC_PROTO_NONE; in pop_eth()
303 err = skb_eth_push(skb, ethh->addresses.eth_dst, in push_eth()
304 ethh->addresses.eth_src); in push_eth()
309 key->mac_proto = MAC_PROTO_ETHERNET; in push_eth()
331 key->mac_proto = MAC_PROTO_NONE; in push_nsh()
345 if (skb->protocol == htons(ETH_P_TEB)) in pop_nsh()
346 key->mac_proto = MAC_PROTO_ETHERNET; in pop_nsh()
348 key->mac_proto = MAC_PROTO_NONE; in pop_nsh()
356 int transport_len = skb->len - skb_transport_offset(skb); in update_ip_l4_checksum()
358 if (nh->frag_off & htons(IP_OFFSET)) in update_ip_l4_checksum()
361 if (nh->protocol == IPPROTO_TCP) { in update_ip_l4_checksum()
363 inet_proto_csum_replace4(&tcp_hdr(skb)->check, skb, in update_ip_l4_checksum()
365 } else if (nh->protocol == IPPROTO_UDP) { in update_ip_l4_checksum()
369 if (uh->check || skb->ip_summed == CHECKSUM_PARTIAL) { in update_ip_l4_checksum()
370 inet_proto_csum_replace4(&uh->check, skb, in update_ip_l4_checksum()
372 if (!uh->check) in update_ip_l4_checksum()
373 uh->check = CSUM_MANGLED_0; in update_ip_l4_checksum()
383 csum_replace4(&nh->check, *addr, new_addr); in set_ip_addr()
392 int transport_len = skb->len - skb_transport_offset(skb); in update_ipv6_checksum()
396 inet_proto_csum_replace16(&tcp_hdr(skb)->check, skb, in update_ipv6_checksum()
402 if (uh->check || skb->ip_summed == CHECKSUM_PARTIAL) { in update_ipv6_checksum()
403 inet_proto_csum_replace16(&uh->check, skb, in update_ipv6_checksum()
405 if (!uh->check) in update_ipv6_checksum()
406 uh->check = CSUM_MANGLED_0; in update_ipv6_checksum()
411 inet_proto_csum_replace16(&icmp6_hdr(skb)->icmp6_cksum, in update_ipv6_checksum()
417 const __be32 mask[4], __be32 masked[4]) in mask_ipv6_addr()
419 masked[0] = OVS_MASKED(old[0], addr[0], mask[0]); in mask_ipv6_addr()
420 masked[1] = OVS_MASKED(old[1], addr[1], mask[1]); in mask_ipv6_addr()
421 masked[2] = OVS_MASKED(old[2], addr[2], mask[2]); in mask_ipv6_addr()
422 masked[3] = OVS_MASKED(old[3], addr[3], mask[3]); in mask_ipv6_addr()
443 if (skb->ip_summed == CHECKSUM_COMPLETE) in set_ipv6_dsfield()
444 csum_replace(&skb->csum, (__force __wsum)(old_ipv6_tclass << 12), in set_ipv6_dsfield()
454 ofl = nh->flow_lbl[0] << 16 | nh->flow_lbl[1] << 8 | nh->flow_lbl[2]; in set_ipv6_fl()
457 /* Bits 21-24 are always unmasked, so this retains their values. */ in set_ipv6_fl()
458 nh->flow_lbl[0] = (u8)(fl >> 16); in set_ipv6_fl()
459 nh->flow_lbl[1] = (u8)(fl >> 8); in set_ipv6_fl()
460 nh->flow_lbl[2] = (u8)fl; in set_ipv6_fl()
462 if (skb->ip_summed == CHECKSUM_COMPLETE) in set_ipv6_fl()
463 csum_replace(&skb->csum, (__force __wsum)htonl(ofl), (__force __wsum)htonl(fl)); in set_ipv6_fl()
468 new_ttl = OVS_MASKED(nh->hop_limit, new_ttl, mask); in set_ipv6_ttl()
470 if (skb->ip_summed == CHECKSUM_COMPLETE) in set_ipv6_ttl()
471 csum_replace(&skb->csum, (__force __wsum)(nh->hop_limit << 8), in set_ipv6_ttl()
473 nh->hop_limit = new_ttl; in set_ipv6_ttl()
479 new_ttl = OVS_MASKED(nh->ttl, new_ttl, mask); in set_ip_ttl()
481 csum_replace2(&nh->check, htons(nh->ttl << 8), htons(new_ttl << 8)); in set_ip_ttl()
482 nh->ttl = new_ttl; in set_ip_ttl()
504 if (mask->ipv4_src) { in set_ipv4()
505 new_addr = OVS_MASKED(nh->saddr, key->ipv4_src, mask->ipv4_src); in set_ipv4()
507 if (unlikely(new_addr != nh->saddr)) { in set_ipv4()
508 set_ip_addr(skb, nh, &nh->saddr, new_addr); in set_ipv4()
509 flow_key->ipv4.addr.src = new_addr; in set_ipv4()
512 if (mask->ipv4_dst) { in set_ipv4()
513 new_addr = OVS_MASKED(nh->daddr, key->ipv4_dst, mask->ipv4_dst); in set_ipv4()
515 if (unlikely(new_addr != nh->daddr)) { in set_ipv4()
516 set_ip_addr(skb, nh, &nh->daddr, new_addr); in set_ipv4()
517 flow_key->ipv4.addr.dst = new_addr; in set_ipv4()
520 if (mask->ipv4_tos) { in set_ipv4()
521 ipv4_change_dsfield(nh, ~mask->ipv4_tos, key->ipv4_tos); in set_ipv4()
522 flow_key->ip.tos = nh->tos; in set_ipv4()
524 if (mask->ipv4_ttl) { in set_ipv4()
525 set_ip_ttl(skb, nh, key->ipv4_ttl, mask->ipv4_ttl); in set_ipv4()
526 flow_key->ip.ttl = nh->ttl; in set_ipv4()
555 if (is_ipv6_mask_nonzero(mask->ipv6_src)) { in set_ipv6()
556 __be32 *saddr = (__be32 *)&nh->saddr; in set_ipv6()
557 __be32 masked[4]; in set_ipv6() local
559 mask_ipv6_addr(saddr, key->ipv6_src, mask->ipv6_src, masked); in set_ipv6()
561 if (unlikely(memcmp(saddr, masked, sizeof(masked)))) { in set_ipv6()
562 set_ipv6_addr(skb, flow_key->ip.proto, saddr, masked, in set_ipv6()
564 memcpy(&flow_key->ipv6.addr.src, masked, in set_ipv6()
565 sizeof(flow_key->ipv6.addr.src)); in set_ipv6()
568 if (is_ipv6_mask_nonzero(mask->ipv6_dst)) { in set_ipv6()
572 __be32 *daddr = (__be32 *)&nh->daddr; in set_ipv6()
573 __be32 masked[4]; in set_ipv6() local
575 mask_ipv6_addr(daddr, key->ipv6_dst, mask->ipv6_dst, masked); in set_ipv6()
577 if (unlikely(memcmp(daddr, masked, sizeof(masked)))) { in set_ipv6()
578 if (ipv6_ext_hdr(nh->nexthdr)) in set_ipv6()
584 set_ipv6_addr(skb, flow_key->ip.proto, daddr, masked, in set_ipv6()
586 memcpy(&flow_key->ipv6.addr.dst, masked, in set_ipv6()
587 sizeof(flow_key->ipv6.addr.dst)); in set_ipv6()
590 if (mask->ipv6_tclass) { in set_ipv6()
591 set_ipv6_dsfield(skb, nh, key->ipv6_tclass, mask->ipv6_tclass); in set_ipv6()
592 flow_key->ip.tos = ipv6_get_dsfield(nh); in set_ipv6()
594 if (mask->ipv6_label) { in set_ipv6()
595 set_ipv6_fl(skb, nh, ntohl(key->ipv6_label), in set_ipv6()
596 ntohl(mask->ipv6_label)); in set_ipv6()
597 flow_key->ipv6.label = in set_ipv6()
600 if (mask->ipv6_hlimit) { in set_ipv6()
601 set_ipv6_ttl(skb, nh, key->ipv6_hlimit, mask->ipv6_hlimit); in set_ipv6()
602 flow_key->ip.ttl = nh->hop_limit; in set_ipv6()
626 return -ENOMEM; in set_nsh()
641 flow_key->nsh.base.flags = flags; in set_nsh()
644 flow_key->nsh.base.ttl = ttl; in set_nsh()
646 nh->path_hdr = OVS_MASKED(nh->path_hdr, key.base.path_hdr, in set_nsh()
648 flow_key->nsh.base.path_hdr = nh->path_hdr; in set_nsh()
649 switch (nh->mdtype) { in set_nsh()
652 nh->md1.context[i] = in set_nsh()
653 OVS_MASKED(nh->md1.context[i], key.context[i], in set_nsh()
656 memcpy(flow_key->nsh.context, nh->md1.context, in set_nsh()
657 sizeof(nh->md1.context)); in set_nsh()
660 memset(flow_key->nsh.context, 0, in set_nsh()
661 sizeof(flow_key->nsh.context)); in set_nsh()
664 return -EINVAL; in set_nsh()
693 /* Either of the masks is non-zero, so do not bother checking them. */ in set_udp()
694 src = OVS_MASKED(uh->source, key->udp_src, mask->udp_src); in set_udp()
695 dst = OVS_MASKED(uh->dest, key->udp_dst, mask->udp_dst); in set_udp()
697 if (uh->check && skb->ip_summed != CHECKSUM_PARTIAL) { in set_udp()
698 if (likely(src != uh->source)) { in set_udp()
699 set_tp_port(skb, &uh->source, src, &uh->check); in set_udp()
700 flow_key->tp.src = src; in set_udp()
702 if (likely(dst != uh->dest)) { in set_udp()
703 set_tp_port(skb, &uh->dest, dst, &uh->check); in set_udp()
704 flow_key->tp.dst = dst; in set_udp()
707 if (unlikely(!uh->check)) in set_udp()
708 uh->check = CSUM_MANGLED_0; in set_udp()
710 uh->source = src; in set_udp()
711 uh->dest = dst; in set_udp()
712 flow_key->tp.src = src; in set_udp()
713 flow_key->tp.dst = dst; in set_udp()
736 src = OVS_MASKED(th->source, key->tcp_src, mask->tcp_src); in set_tcp()
737 if (likely(src != th->source)) { in set_tcp()
738 set_tp_port(skb, &th->source, src, &th->check); in set_tcp()
739 flow_key->tp.src = src; in set_tcp()
741 dst = OVS_MASKED(th->dest, key->tcp_dst, mask->tcp_dst); in set_tcp()
742 if (likely(dst != th->dest)) { in set_tcp()
743 set_tp_port(skb, &th->dest, dst, &th->check); in set_tcp()
744 flow_key->tp.dst = dst; in set_tcp()
765 old_csum = sh->checksum; in set_sctp()
768 sh->source = OVS_MASKED(sh->source, key->sctp_src, mask->sctp_src); in set_sctp()
769 sh->dest = OVS_MASKED(sh->dest, key->sctp_dst, mask->sctp_dst); in set_sctp()
774 sh->checksum = old_csum ^ old_correct_csum ^ new_csum; in set_sctp()
779 flow_key->tp.src = sh->source; in set_sctp()
780 flow_key->tp.dst = sh->dest; in set_sctp()
789 struct vport *vport = data->vport; in ovs_vport_output()
791 if (skb_cow_head(skb, data->l2_len) < 0) { in ovs_vport_output()
793 return -ENOMEM; in ovs_vport_output()
796 __skb_dst_copy(skb, data->dst); in ovs_vport_output()
797 *OVS_CB(skb) = data->cb; in ovs_vport_output()
798 skb->inner_protocol = data->inner_protocol; in ovs_vport_output()
799 if (data->vlan_tci & VLAN_CFI_MASK) in ovs_vport_output()
800 __vlan_hwaccel_put_tag(skb, data->vlan_proto, data->vlan_tci & ~VLAN_CFI_MASK); in ovs_vport_output()
805 skb_push(skb, data->l2_len); in ovs_vport_output()
806 memcpy(skb->data, &data->l2_data, data->l2_len); in ovs_vport_output()
807 skb_postpush_rcsum(skb, skb->data, data->l2_len); in ovs_vport_output()
810 if (eth_p_mpls(skb->protocol)) { in ovs_vport_output()
811 skb->inner_network_header = skb->network_header; in ovs_vport_output()
812 skb_set_network_header(skb, data->network_offset); in ovs_vport_output()
816 ovs_vport_send(vport, skb, data->mac_proto); in ovs_vport_output()
823 return dst->dev->mtu; in ovs_dst_get_mtu()
831 /* prepare_frag() is called once per (larger-than-MTU) frame; its inverse is
841 data->dst = skb->_skb_refdst; in prepare_frag()
842 data->vport = vport; in prepare_frag()
843 data->cb = *OVS_CB(skb); in prepare_frag()
844 data->inner_protocol = skb->inner_protocol; in prepare_frag()
845 data->network_offset = orig_network_offset; in prepare_frag()
847 data->vlan_tci = skb_vlan_tag_get(skb) | VLAN_CFI_MASK; in prepare_frag()
849 data->vlan_tci = 0; in prepare_frag()
850 data->vlan_proto = skb->vlan_proto; in prepare_frag()
851 data->mac_proto = mac_proto; in prepare_frag()
852 data->l2_len = hlen; in prepare_frag()
853 memcpy(&data->l2_data, skb->data, hlen); in prepare_frag()
866 if (eth_p_mpls(skb->protocol)) { in ovs_fragment()
868 skb->network_header = skb->inner_network_header; in ovs_fragment()
877 if (key->eth.type == htons(ETH_P_IP)) { in ovs_fragment()
885 ovs_rt.dst.dev = vport->dev; in ovs_fragment()
887 orig_dst = skb->_skb_refdst; in ovs_fragment()
889 IPCB(skb)->frag_max_size = mru; in ovs_fragment()
891 ip_do_fragment(net, skb->sk, skb, ovs_vport_output); in ovs_fragment()
893 } else if (key->eth.type == htons(ETH_P_IPV6)) { in ovs_fragment()
902 ovs_rt.dst.dev = vport->dev; in ovs_fragment()
904 orig_dst = skb->_skb_refdst; in ovs_fragment()
906 IP6CB(skb)->frag_max_size = mru; in ovs_fragment()
908 ipv6_stub->ipv6_fragment(net, skb->sk, skb, ovs_vport_output); in ovs_fragment()
911 WARN_ONCE(1, "Failed fragment ->%s: eth=%04x, MRU=%d, MTU=%d.", in ovs_fragment()
912 ovs_vport_name(vport), ntohs(key->eth.type), mru, in ovs_fragment()
913 vport->dev->mtu); in ovs_fragment()
928 if (likely(vport && netif_carrier_ok(vport->dev))) { in do_output()
929 u16 mru = OVS_CB(skb)->mru; in do_output()
930 u32 cutlen = OVS_CB(skb)->cutlen; in do_output()
933 if (skb->len - cutlen > ovs_mac_header_len(key)) in do_output()
934 pskb_trim(skb, skb->len - cutlen); in do_output()
940 (skb->len <= mru + vport->dev->hard_header_len))) { in do_output()
942 } else if (mru <= vport->dev->mtu) { in do_output()
943 struct net *net = read_pnet(&dp->net); in do_output()
965 upcall.mru = OVS_CB(skb)->mru; in output_userspace()
975 if (dp->user_features & in output_userspace()
992 err = dev_fill_metadata_dst(vport->dev, skb); in output_userspace()
1047 if ((arg->probability != U32_MAX) && in sample()
1048 (!arg->probability || get_random_u32() > arg->probability)) { in sample()
1054 clone_flow_key = !arg->exec; in sample()
1087 if (hash_act->hash_alg == OVS_HASH_ALG_L4) { in execute_hash()
1090 } else if (hash_act->hash_alg == OVS_HASH_ALG_SYM_L4) { in execute_hash()
1097 hash = jhash_1word(hash, hash_act->hash_basis); in execute_hash()
1101 key->ovs_flow_hash = hash; in execute_hash()
1113 dst_hold((struct dst_entry *)tun->tun_dst); in execute_set_action()
1114 skb_dst_set(skb, (struct dst_entry *)tun->tun_dst); in execute_set_action()
1118 return -EINVAL; in execute_set_action()
1132 OVS_SET_MASKED(skb->priority, nla_get_u32(a), in execute_masked_set_action()
1134 flow_key->phy.priority = skb->priority; in execute_masked_set_action()
1138 OVS_SET_MASKED(skb->mark, nla_get_u32(a), *get_mask(a, u32 *)); in execute_masked_set_action()
1139 flow_key->phy.skb_mark = skb->mark; in execute_masked_set_action()
1143 /* Masked data not supported for tunnel. */ in execute_masked_set_action()
1144 err = -EINVAL; in execute_masked_set_action()
1192 err = -EINVAL; in execute_masked_set_action()
1234 len = ovs_cb->mru ? ovs_cb->mru + skb->mac_len : skb->len; in execute_check_pkt_len()
1235 max_len = arg->pkt_len; in execute_check_pkt_len()
1243 clone_flow_key = !arg->exec_for_lesser_equal; in execute_check_pkt_len()
1250 clone_flow_key = !arg->exec_for_greater; in execute_check_pkt_len()
1261 if (skb->protocol == htons(ETH_P_IPV6)) { in execute_dec_ttl()
1271 if (nh->hop_limit <= 1) in execute_dec_ttl()
1272 return -EHOSTUNREACH; in execute_dec_ttl()
1274 key->ip.ttl = --nh->hop_limit; in execute_dec_ttl()
1275 } else if (skb->protocol == htons(ETH_P_IP)) { in execute_dec_ttl()
1285 if (nh->ttl <= 1) in execute_dec_ttl()
1286 return -EHOSTUNREACH; in execute_dec_ttl()
1288 old_ttl = nh->ttl--; in execute_dec_ttl()
1289 csum_replace2(&nh->check, htons(old_ttl << 8), in execute_dec_ttl()
1290 htons(nh->ttl << 8)); in execute_dec_ttl()
1291 key->ip.ttl = nh->ttl; in execute_dec_ttl()
1333 OVS_CB(skb)->cutlen = 0; in do_execute_actions()
1340 if (skb->len > trunc->max_len) in do_execute_actions()
1341 OVS_CB(skb)->cutlen = skb->len - trunc->max_len; in do_execute_actions()
1347 len, OVS_CB(skb)->cutlen); in do_execute_actions()
1348 OVS_CB(skb)->cutlen = 0; in do_execute_actions()
1362 err = push_mpls(skb, key, mpls->mpls_lse, in do_execute_actions()
1363 mpls->mpls_ethertype, skb->mac_len); in do_execute_actions()
1370 if (mpls->tun_flags & OVS_MPLS_L3_TUNNEL_FLAG_MASK) in do_execute_actions()
1371 mac_len = skb->mac_len; in do_execute_actions()
1373 err = push_mpls(skb, key, mpls->mpls_lse, in do_execute_actions()
1374 mpls->mpls_ethertype, mac_len); in do_execute_actions()
1434 return err == -EINPROGRESS ? 0 : err; in do_execute_actions()
1486 if (err == -EHOSTUNREACH) in do_execute_actions()
1552 clone->recirc_id = recirc_id; in clone_execute()
1562 key = &da->pkt_key; in clone_execute()
1563 key->recirc_id = recirc_id; in clone_execute()
1595 struct sk_buff *skb = da->skb; in process_deferred_actions()
1596 struct sw_flow_key *key = &da->pkt_key; in process_deferred_actions()
1597 const struct nlattr *actions = da->actions; in process_deferred_actions()
1598 int actions_len = da->actions_len; in process_deferred_actions()
1622 err = -ENETDOWN; in ovs_execute_actions()
1626 OVS_CB(skb)->acts_origlen = acts->orig_len; in ovs_execute_actions()
1628 acts->actions, acts->actions_len); in ovs_execute_actions()
1642 return -ENOMEM; in action_fifos_init()
1647 return -ENOMEM; in action_fifos_init()