Lines Matching +full:non +full:- +full:masked
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2007-2017 Nicira, Inc.
69 #define OVS_DEFERRED_ACTION_THRESHOLD (OVS_RECURSION_LIMIT - 2)
85 /* Make a clone of the 'key', using the pre-allocated percpu 'flow_keys'
95 key = &keys->key[level - 1]; in clone_key()
104 fifo->head = 0; in action_fifo_init()
105 fifo->tail = 0; in action_fifo_init()
110 return (fifo->head == fifo->tail); in action_fifo_is_empty()
118 return &fifo->fifo[fifo->tail++]; in action_fifo_get()
123 if (fifo->head >= DEFERRED_ACTION_FIFO_SIZE - 1) in action_fifo_put()
126 return &fifo->fifo[fifo->head++]; in action_fifo_put()
141 da->skb = skb; in add_deferred_actions()
142 da->actions = actions; in add_deferred_actions()
143 da->actions_len = actions_len; in add_deferred_actions()
144 da->pkt_key = *key; in add_deferred_actions()
152 key->mac_proto |= SW_FLOW_KEY_INVALID; in invalidate_flow_key()
157 return !(key->mac_proto & SW_FLOW_KEY_INVALID); in is_flow_key_valid()
180 key->mac_proto = MAC_PROTO_NONE; in push_mpls()
191 err = skb_mpls_pop(skb, ethertype, skb->mac_len, in pop_mpls()
197 key->mac_proto = MAC_PROTO_ETHERNET; in pop_mpls()
211 return -ENOMEM; in set_mpls()
214 lse = OVS_MASKED(stack->label_stack_entry, *mpls_lse, *mask); in set_mpls()
219 flow_key->mpls.lse[0] = lse; in set_mpls()
231 key->eth.vlan.tci = 0; in pop_vlan()
232 key->eth.vlan.tpid = 0; in pop_vlan()
245 key->eth.vlan.tci = vlan->vlan_tci; in push_vlan()
246 key->eth.vlan.tpid = vlan->vlan_tpid; in push_vlan()
248 err = skb_vlan_push(skb, vlan->vlan_tpid, in push_vlan()
249 ntohs(vlan->vlan_tci) & ~VLAN_CFI_MASK); in push_vlan()
254 /* 'src' is already properly masked. */
278 ether_addr_copy_masked(eth_hdr(skb)->h_source, key->eth_src, in set_eth_addr()
279 mask->eth_src); in set_eth_addr()
280 ether_addr_copy_masked(eth_hdr(skb)->h_dest, key->eth_dst, in set_eth_addr()
281 mask->eth_dst); in set_eth_addr()
285 ether_addr_copy(flow_key->eth.src, eth_hdr(skb)->h_source); in set_eth_addr()
286 ether_addr_copy(flow_key->eth.dst, eth_hdr(skb)->h_dest); in set_eth_addr()
302 key->mac_proto = MAC_PROTO_NONE; in pop_eth()
312 err = skb_eth_push(skb, ethh->addresses.eth_dst, in push_eth()
313 ethh->addresses.eth_src); in push_eth()
318 key->mac_proto = MAC_PROTO_ETHERNET; in push_eth()
340 key->mac_proto = MAC_PROTO_NONE; in push_nsh()
354 if (skb->protocol == htons(ETH_P_TEB)) in pop_nsh()
355 key->mac_proto = MAC_PROTO_ETHERNET; in pop_nsh()
357 key->mac_proto = MAC_PROTO_NONE; in pop_nsh()
365 int transport_len = skb->len - skb_transport_offset(skb); in update_ip_l4_checksum()
367 if (nh->frag_off & htons(IP_OFFSET)) in update_ip_l4_checksum()
370 if (nh->protocol == IPPROTO_TCP) { in update_ip_l4_checksum()
372 inet_proto_csum_replace4(&tcp_hdr(skb)->check, skb, in update_ip_l4_checksum()
374 } else if (nh->protocol == IPPROTO_UDP) { in update_ip_l4_checksum()
378 if (uh->check || skb->ip_summed == CHECKSUM_PARTIAL) { in update_ip_l4_checksum()
379 inet_proto_csum_replace4(&uh->check, skb, in update_ip_l4_checksum()
381 if (!uh->check) in update_ip_l4_checksum()
382 uh->check = CSUM_MANGLED_0; in update_ip_l4_checksum()
392 csum_replace4(&nh->check, *addr, new_addr); in set_ip_addr()
401 int transport_len = skb->len - skb_transport_offset(skb); in update_ipv6_checksum()
405 inet_proto_csum_replace16(&tcp_hdr(skb)->check, skb, in update_ipv6_checksum()
411 if (uh->check || skb->ip_summed == CHECKSUM_PARTIAL) { in update_ipv6_checksum()
412 inet_proto_csum_replace16(&uh->check, skb, in update_ipv6_checksum()
414 if (!uh->check) in update_ipv6_checksum()
415 uh->check = CSUM_MANGLED_0; in update_ipv6_checksum()
420 inet_proto_csum_replace16(&icmp6_hdr(skb)->icmp6_cksum, in update_ipv6_checksum()
426 const __be32 mask[4], __be32 masked[4]) in mask_ipv6_addr()
428 masked[0] = OVS_MASKED(old[0], addr[0], mask[0]); in mask_ipv6_addr()
429 masked[1] = OVS_MASKED(old[1], addr[1], mask[1]); in mask_ipv6_addr()
430 masked[2] = OVS_MASKED(old[2], addr[2], mask[2]); in mask_ipv6_addr()
431 masked[3] = OVS_MASKED(old[3], addr[3], mask[3]); in mask_ipv6_addr()
452 if (skb->ip_summed == CHECKSUM_COMPLETE) in set_ipv6_dsfield()
453 csum_replace(&skb->csum, (__force __wsum)(old_ipv6_tclass << 12), in set_ipv6_dsfield()
463 ofl = nh->flow_lbl[0] << 16 | nh->flow_lbl[1] << 8 | nh->flow_lbl[2]; in set_ipv6_fl()
466 /* Bits 21-24 are always unmasked, so this retains their values. */ in set_ipv6_fl()
467 nh->flow_lbl[0] = (u8)(fl >> 16); in set_ipv6_fl()
468 nh->flow_lbl[1] = (u8)(fl >> 8); in set_ipv6_fl()
469 nh->flow_lbl[2] = (u8)fl; in set_ipv6_fl()
471 if (skb->ip_summed == CHECKSUM_COMPLETE) in set_ipv6_fl()
472 csum_replace(&skb->csum, (__force __wsum)htonl(ofl), (__force __wsum)htonl(fl)); in set_ipv6_fl()
477 new_ttl = OVS_MASKED(nh->hop_limit, new_ttl, mask); in set_ipv6_ttl()
479 if (skb->ip_summed == CHECKSUM_COMPLETE) in set_ipv6_ttl()
480 csum_replace(&skb->csum, (__force __wsum)(nh->hop_limit << 8), in set_ipv6_ttl()
482 nh->hop_limit = new_ttl; in set_ipv6_ttl()
488 new_ttl = OVS_MASKED(nh->ttl, new_ttl, mask); in set_ip_ttl()
490 csum_replace2(&nh->check, htons(nh->ttl << 8), htons(new_ttl << 8)); in set_ip_ttl()
491 nh->ttl = new_ttl; in set_ip_ttl()
513 if (mask->ipv4_src) { in set_ipv4()
514 new_addr = OVS_MASKED(nh->saddr, key->ipv4_src, mask->ipv4_src); in set_ipv4()
516 if (unlikely(new_addr != nh->saddr)) { in set_ipv4()
517 set_ip_addr(skb, nh, &nh->saddr, new_addr); in set_ipv4()
518 flow_key->ipv4.addr.src = new_addr; in set_ipv4()
521 if (mask->ipv4_dst) { in set_ipv4()
522 new_addr = OVS_MASKED(nh->daddr, key->ipv4_dst, mask->ipv4_dst); in set_ipv4()
524 if (unlikely(new_addr != nh->daddr)) { in set_ipv4()
525 set_ip_addr(skb, nh, &nh->daddr, new_addr); in set_ipv4()
526 flow_key->ipv4.addr.dst = new_addr; in set_ipv4()
529 if (mask->ipv4_tos) { in set_ipv4()
530 ipv4_change_dsfield(nh, ~mask->ipv4_tos, key->ipv4_tos); in set_ipv4()
531 flow_key->ip.tos = nh->tos; in set_ipv4()
533 if (mask->ipv4_ttl) { in set_ipv4()
534 set_ip_ttl(skb, nh, key->ipv4_ttl, mask->ipv4_ttl); in set_ipv4()
535 flow_key->ip.ttl = nh->ttl; in set_ipv4()
564 if (is_ipv6_mask_nonzero(mask->ipv6_src)) { in set_ipv6()
565 __be32 *saddr = (__be32 *)&nh->saddr; in set_ipv6()
566 __be32 masked[4]; in set_ipv6() local
568 mask_ipv6_addr(saddr, key->ipv6_src, mask->ipv6_src, masked); in set_ipv6()
570 if (unlikely(memcmp(saddr, masked, sizeof(masked)))) { in set_ipv6()
571 set_ipv6_addr(skb, flow_key->ip.proto, saddr, masked, in set_ipv6()
573 memcpy(&flow_key->ipv6.addr.src, masked, in set_ipv6()
574 sizeof(flow_key->ipv6.addr.src)); in set_ipv6()
577 if (is_ipv6_mask_nonzero(mask->ipv6_dst)) { in set_ipv6()
581 __be32 *daddr = (__be32 *)&nh->daddr; in set_ipv6()
582 __be32 masked[4]; in set_ipv6() local
584 mask_ipv6_addr(daddr, key->ipv6_dst, mask->ipv6_dst, masked); in set_ipv6()
586 if (unlikely(memcmp(daddr, masked, sizeof(masked)))) { in set_ipv6()
587 if (ipv6_ext_hdr(nh->nexthdr)) in set_ipv6()
593 set_ipv6_addr(skb, flow_key->ip.proto, daddr, masked, in set_ipv6()
595 memcpy(&flow_key->ipv6.addr.dst, masked, in set_ipv6()
596 sizeof(flow_key->ipv6.addr.dst)); in set_ipv6()
599 if (mask->ipv6_tclass) { in set_ipv6()
600 set_ipv6_dsfield(skb, nh, key->ipv6_tclass, mask->ipv6_tclass); in set_ipv6()
601 flow_key->ip.tos = ipv6_get_dsfield(nh); in set_ipv6()
603 if (mask->ipv6_label) { in set_ipv6()
604 set_ipv6_fl(skb, nh, ntohl(key->ipv6_label), in set_ipv6()
605 ntohl(mask->ipv6_label)); in set_ipv6()
606 flow_key->ipv6.label = in set_ipv6()
609 if (mask->ipv6_hlimit) { in set_ipv6()
610 set_ipv6_ttl(skb, nh, key->ipv6_hlimit, mask->ipv6_hlimit); in set_ipv6()
611 flow_key->ip.ttl = nh->hop_limit; in set_ipv6()
635 return -ENOMEM; in set_nsh()
650 flow_key->nsh.base.flags = flags; in set_nsh()
653 flow_key->nsh.base.ttl = ttl; in set_nsh()
655 nh->path_hdr = OVS_MASKED(nh->path_hdr, key.base.path_hdr, in set_nsh()
657 flow_key->nsh.base.path_hdr = nh->path_hdr; in set_nsh()
658 switch (nh->mdtype) { in set_nsh()
661 nh->md1.context[i] = in set_nsh()
662 OVS_MASKED(nh->md1.context[i], key.context[i], in set_nsh()
665 memcpy(flow_key->nsh.context, nh->md1.context, in set_nsh()
666 sizeof(nh->md1.context)); in set_nsh()
669 memset(flow_key->nsh.context, 0, in set_nsh()
670 sizeof(flow_key->nsh.context)); in set_nsh()
673 return -EINVAL; in set_nsh()
702 /* Either of the masks is non-zero, so do not bother checking them. */ in set_udp()
703 src = OVS_MASKED(uh->source, key->udp_src, mask->udp_src); in set_udp()
704 dst = OVS_MASKED(uh->dest, key->udp_dst, mask->udp_dst); in set_udp()
706 if (uh->check && skb->ip_summed != CHECKSUM_PARTIAL) { in set_udp()
707 if (likely(src != uh->source)) { in set_udp()
708 set_tp_port(skb, &uh->source, src, &uh->check); in set_udp()
709 flow_key->tp.src = src; in set_udp()
711 if (likely(dst != uh->dest)) { in set_udp()
712 set_tp_port(skb, &uh->dest, dst, &uh->check); in set_udp()
713 flow_key->tp.dst = dst; in set_udp()
716 if (unlikely(!uh->check)) in set_udp()
717 uh->check = CSUM_MANGLED_0; in set_udp()
719 uh->source = src; in set_udp()
720 uh->dest = dst; in set_udp()
721 flow_key->tp.src = src; in set_udp()
722 flow_key->tp.dst = dst; in set_udp()
745 src = OVS_MASKED(th->source, key->tcp_src, mask->tcp_src); in set_tcp()
746 if (likely(src != th->source)) { in set_tcp()
747 set_tp_port(skb, &th->source, src, &th->check); in set_tcp()
748 flow_key->tp.src = src; in set_tcp()
750 dst = OVS_MASKED(th->dest, key->tcp_dst, mask->tcp_dst); in set_tcp()
751 if (likely(dst != th->dest)) { in set_tcp()
752 set_tp_port(skb, &th->dest, dst, &th->check); in set_tcp()
753 flow_key->tp.dst = dst; in set_tcp()
774 old_csum = sh->checksum; in set_sctp()
777 sh->source = OVS_MASKED(sh->source, key->sctp_src, mask->sctp_src); in set_sctp()
778 sh->dest = OVS_MASKED(sh->dest, key->sctp_dst, mask->sctp_dst); in set_sctp()
783 sh->checksum = old_csum ^ old_correct_csum ^ new_csum; in set_sctp()
788 flow_key->tp.src = sh->source; in set_sctp()
789 flow_key->tp.dst = sh->dest; in set_sctp()
798 struct vport *vport = data->vport; in ovs_vport_output()
800 if (skb_cow_head(skb, data->l2_len) < 0) { in ovs_vport_output()
802 return -ENOMEM; in ovs_vport_output()
805 __skb_dst_copy(skb, data->dst); in ovs_vport_output()
806 *OVS_CB(skb) = data->cb; in ovs_vport_output()
807 skb->inner_protocol = data->inner_protocol; in ovs_vport_output()
808 if (data->vlan_tci & VLAN_CFI_MASK) in ovs_vport_output()
809 __vlan_hwaccel_put_tag(skb, data->vlan_proto, data->vlan_tci & ~VLAN_CFI_MASK); in ovs_vport_output()
814 skb_push(skb, data->l2_len); in ovs_vport_output()
815 memcpy(skb->data, &data->l2_data, data->l2_len); in ovs_vport_output()
816 skb_postpush_rcsum(skb, skb->data, data->l2_len); in ovs_vport_output()
819 if (eth_p_mpls(skb->protocol)) { in ovs_vport_output()
820 skb->inner_network_header = skb->network_header; in ovs_vport_output()
821 skb_set_network_header(skb, data->network_offset); in ovs_vport_output()
825 ovs_vport_send(vport, skb, data->mac_proto); in ovs_vport_output()
832 return dst->dev->mtu; in ovs_dst_get_mtu()
840 /* prepare_frag() is called once per (larger-than-MTU) frame; its inverse is
850 data->dst = skb->_skb_refdst; in prepare_frag()
851 data->vport = vport; in prepare_frag()
852 data->cb = *OVS_CB(skb); in prepare_frag()
853 data->inner_protocol = skb->inner_protocol; in prepare_frag()
854 data->network_offset = orig_network_offset; in prepare_frag()
856 data->vlan_tci = skb_vlan_tag_get(skb) | VLAN_CFI_MASK; in prepare_frag()
858 data->vlan_tci = 0; in prepare_frag()
859 data->vlan_proto = skb->vlan_proto; in prepare_frag()
860 data->mac_proto = mac_proto; in prepare_frag()
861 data->l2_len = hlen; in prepare_frag()
862 memcpy(&data->l2_data, skb->data, hlen); in prepare_frag()
875 if (eth_p_mpls(skb->protocol)) { in ovs_fragment()
877 skb->network_header = skb->inner_network_header; in ovs_fragment()
886 if (key->eth.type == htons(ETH_P_IP)) { in ovs_fragment()
894 ovs_rt.dst.dev = vport->dev; in ovs_fragment()
896 orig_dst = skb->_skb_refdst; in ovs_fragment()
898 IPCB(skb)->frag_max_size = mru; in ovs_fragment()
900 ip_do_fragment(net, skb->sk, skb, ovs_vport_output); in ovs_fragment()
902 } else if (key->eth.type == htons(ETH_P_IPV6)) { in ovs_fragment()
911 ovs_rt.dst.dev = vport->dev; in ovs_fragment()
913 orig_dst = skb->_skb_refdst; in ovs_fragment()
915 IP6CB(skb)->frag_max_size = mru; in ovs_fragment()
917 ipv6_stub->ipv6_fragment(net, skb->sk, skb, ovs_vport_output); in ovs_fragment()
920 WARN_ONCE(1, "Failed fragment ->%s: eth=%04x, MRU=%d, MTU=%d.", in ovs_fragment()
921 ovs_vport_name(vport), ntohs(key->eth.type), mru, in ovs_fragment()
922 vport->dev->mtu); in ovs_fragment()
938 netif_running(vport->dev) && in do_output()
939 netif_carrier_ok(vport->dev))) { in do_output()
940 u16 mru = OVS_CB(skb)->mru; in do_output()
941 u32 cutlen = OVS_CB(skb)->cutlen; in do_output()
944 if (skb->len - cutlen > ovs_mac_header_len(key)) in do_output()
945 pskb_trim(skb, skb->len - cutlen); in do_output()
954 skb->pkt_type = PACKET_OUTGOING; in do_output()
957 (skb->len <= mru + vport->dev->hard_header_len))) { in do_output()
959 } else if (mru <= vport->dev->mtu) { in do_output()
960 struct net *net = read_pnet(&dp->net); in do_output()
982 upcall.mru = OVS_CB(skb)->mru; in output_userspace()
992 if (dp->user_features & in output_userspace()
1009 err = dev_fill_metadata_dst(vport->dev, skb); in output_userspace()
1065 init_probability = OVS_CB(skb)->probability; in sample()
1067 if ((arg->probability != U32_MAX) && in sample()
1068 (!arg->probability || get_random_u32() > arg->probability)) { in sample()
1074 OVS_CB(skb)->probability = arg->probability; in sample()
1076 clone_flow_key = !arg->exec; in sample()
1081 OVS_CB(skb)->probability = init_probability; in sample()
1114 if (hash_act->hash_alg == OVS_HASH_ALG_L4) { in execute_hash()
1117 } else if (hash_act->hash_alg == OVS_HASH_ALG_SYM_L4) { in execute_hash()
1124 hash = jhash_1word(hash, hash_act->hash_basis); in execute_hash()
1128 key->ovs_flow_hash = hash; in execute_hash()
1140 dst_hold((struct dst_entry *)tun->tun_dst); in execute_set_action()
1141 skb_dst_set(skb, (struct dst_entry *)tun->tun_dst); in execute_set_action()
1145 return -EINVAL; in execute_set_action()
1159 OVS_SET_MASKED(skb->priority, nla_get_u32(a), in execute_masked_set_action()
1161 flow_key->phy.priority = skb->priority; in execute_masked_set_action()
1165 OVS_SET_MASKED(skb->mark, nla_get_u32(a), *get_mask(a, u32 *)); in execute_masked_set_action()
1166 flow_key->phy.skb_mark = skb->mark; in execute_masked_set_action()
1170 /* Masked data not supported for tunnel. */ in execute_masked_set_action()
1171 err = -EINVAL; in execute_masked_set_action()
1219 err = -EINVAL; in execute_masked_set_action()
1261 len = ovs_cb->mru ? ovs_cb->mru + skb->mac_len : skb->len; in execute_check_pkt_len()
1262 max_len = arg->pkt_len; in execute_check_pkt_len()
1270 clone_flow_key = !arg->exec_for_lesser_equal; in execute_check_pkt_len()
1277 clone_flow_key = !arg->exec_for_greater; in execute_check_pkt_len()
1288 if (skb->protocol == htons(ETH_P_IPV6)) { in execute_dec_ttl()
1298 if (nh->hop_limit <= 1) in execute_dec_ttl()
1299 return -EHOSTUNREACH; in execute_dec_ttl()
1301 key->ip.ttl = --nh->hop_limit; in execute_dec_ttl()
1302 } else if (skb->protocol == htons(ETH_P_IP)) { in execute_dec_ttl()
1312 if (nh->ttl <= 1) in execute_dec_ttl()
1313 return -EHOSTUNREACH; in execute_dec_ttl()
1315 old_ttl = nh->ttl--; in execute_dec_ttl()
1316 csum_replace2(&nh->check, htons(old_ttl << 8), in execute_dec_ttl()
1317 htons(nh->ttl << 8)); in execute_dec_ttl()
1318 key->ip.ttl = nh->ttl; in execute_dec_ttl()
1347 md.in_ifindex = OVS_CB(skb)->input_vport->dev->ifindex; in execute_psample()
1348 md.trunc_size = skb->len - OVS_CB(skb)->cutlen; in execute_psample()
1351 rate = OVS_CB(skb)->probability ? OVS_CB(skb)->probability : U32_MAX; in execute_psample()
1398 OVS_CB(skb)->cutlen = 0; in do_execute_actions()
1405 if (skb->len > trunc->max_len) in do_execute_actions()
1406 OVS_CB(skb)->cutlen = skb->len - trunc->max_len; in do_execute_actions()
1412 len, OVS_CB(skb)->cutlen); in do_execute_actions()
1413 OVS_CB(skb)->cutlen = 0; in do_execute_actions()
1427 err = push_mpls(skb, key, mpls->mpls_lse, in do_execute_actions()
1428 mpls->mpls_ethertype, skb->mac_len); in do_execute_actions()
1435 if (mpls->tun_flags & OVS_MPLS_L3_TUNNEL_FLAG_MASK) in do_execute_actions()
1436 mac_len = skb->mac_len; in do_execute_actions()
1438 err = push_mpls(skb, key, mpls->mpls_lse, in do_execute_actions()
1439 mpls->mpls_ethertype, mac_len); in do_execute_actions()
1499 return err == -EINPROGRESS ? 0 : err; in do_execute_actions()
1551 if (err == -EHOSTUNREACH) in do_execute_actions()
1567 OVS_CB(skb)->cutlen = 0; in do_execute_actions()
1626 clone->recirc_id = recirc_id; in clone_execute()
1636 key = &da->pkt_key; in clone_execute()
1637 key->recirc_id = recirc_id; in clone_execute()
1669 struct sk_buff *skb = da->skb; in process_deferred_actions()
1670 struct sw_flow_key *key = &da->pkt_key; in process_deferred_actions()
1671 const struct nlattr *actions = da->actions; in process_deferred_actions()
1672 int actions_len = da->actions_len; in process_deferred_actions()
1696 err = -ENETDOWN; in ovs_execute_actions()
1700 OVS_CB(skb)->acts_origlen = acts->orig_len; in ovs_execute_actions()
1702 acts->actions, acts->actions_len); in ovs_execute_actions()
1716 return -ENOMEM; in action_fifos_init()
1721 return -ENOMEM; in action_fifos_init()