Lines Matching refs:skb
91 static struct deferred_action *add_deferred_actions(struct sk_buff *skb,
101 da->skb = skb;
120 static int clone_execute(struct datapath *dp, struct sk_buff *skb,
126 static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
130 static int push_mpls(struct sk_buff *skb, struct sw_flow_key *key,
135 err = skb_mpls_push(skb, mpls_lse, mpls_ethertype, mac_len, !!mac_len);
146 static int pop_mpls(struct sk_buff *skb, struct sw_flow_key *key,
151 err = skb_mpls_pop(skb, ethertype, skb->mac_len,
163 static int set_mpls(struct sk_buff *skb, struct sw_flow_key *flow_key,
170 if (!pskb_may_pull(skb, skb_network_offset(skb) + MPLS_HLEN))
173 stack = mpls_hdr(skb);
175 err = skb_mpls_update_lse(skb, lse);
183 static int pop_vlan(struct sk_buff *skb, struct sw_flow_key *key)
187 err = skb_vlan_pop(skb);
188 if (skb_vlan_tag_present(skb)) {
197 static int push_vlan(struct sk_buff *skb, struct sw_flow_key *key,
202 if (skb_vlan_tag_present(skb)) {
208 err = skb_vlan_push(skb, vlan->vlan_tpid,
210 skb_reset_mac_len(skb);
226 static int set_eth_addr(struct sk_buff *skb, struct sw_flow_key *flow_key,
232 err = skb_ensure_writable(skb, ETH_HLEN);
236 skb_postpull_rcsum(skb, eth_hdr(skb), ETH_ALEN * 2);
238 ether_addr_copy_masked(eth_hdr(skb)->h_source, key->eth_src,
240 ether_addr_copy_masked(eth_hdr(skb)->h_dest, key->eth_dst,
243 skb_postpush_rcsum(skb, eth_hdr(skb), ETH_ALEN * 2);
245 ether_addr_copy(flow_key->eth.src, eth_hdr(skb)->h_source);
246 ether_addr_copy(flow_key->eth.dst, eth_hdr(skb)->h_dest);
253 static int pop_eth(struct sk_buff *skb, struct sw_flow_key *key)
257 err = skb_eth_pop(skb);
267 static int push_eth(struct sk_buff *skb, struct sw_flow_key *key,
272 err = skb_eth_push(skb, ethh->addresses.eth_dst,
283 static noinline_for_stack int push_nsh(struct sk_buff *skb,
295 err = nsh_push(skb, nh);
305 static int pop_nsh(struct sk_buff *skb, struct sw_flow_key *key)
309 err = nsh_pop(skb);
314 if (skb->protocol == htons(ETH_P_TEB))
322 static void update_ip_l4_checksum(struct sk_buff *skb, struct iphdr *nh,
325 int transport_len = skb->len - skb_transport_offset(skb);
332 inet_proto_csum_replace4(&tcp_hdr(skb)->check, skb,
336 struct udphdr *uh = udp_hdr(skb);
338 if (uh->check || skb->ip_summed == CHECKSUM_PARTIAL) {
339 inet_proto_csum_replace4(&uh->check, skb,
348 static void set_ip_addr(struct sk_buff *skb, struct iphdr *nh,
351 update_ip_l4_checksum(skb, nh, *addr, new_addr);
353 skb_clear_hash(skb);
354 ovs_ct_clear(skb, NULL);
358 static void update_ipv6_checksum(struct sk_buff *skb, u8 l4_proto,
361 int transport_len = skb->len - skb_transport_offset(skb);
365 inet_proto_csum_replace16(&tcp_hdr(skb)->check, skb,
369 struct udphdr *uh = udp_hdr(skb);
371 if (uh->check || skb->ip_summed == CHECKSUM_PARTIAL) {
372 inet_proto_csum_replace16(&uh->check, skb,
380 inet_proto_csum_replace16(&icmp6_hdr(skb)->icmp6_cksum,
381 skb, addr, new_addr, true);
394 static void set_ipv6_addr(struct sk_buff *skb, u8 l4_proto,
399 update_ipv6_checksum(skb, l4_proto, addr, new_addr);
401 skb_clear_hash(skb);
402 ovs_ct_clear(skb, NULL);
406 static void set_ipv6_dsfield(struct sk_buff *skb, struct ipv6hdr *nh, u8 ipv6_tclass, u8 mask)
412 if (skb->ip_summed == CHECKSUM_COMPLETE)
413 csum_replace(&skb->csum, (__force __wsum)(old_ipv6_tclass << 12),
419 static void set_ipv6_fl(struct sk_buff *skb, struct ipv6hdr *nh, u32 fl, u32 mask)
431 if (skb->ip_summed == CHECKSUM_COMPLETE)
432 csum_replace(&skb->csum, (__force __wsum)htonl(ofl), (__force __wsum)htonl(fl));
435 static void set_ipv6_ttl(struct sk_buff *skb, struct ipv6hdr *nh, u8 new_ttl, u8 mask)
439 if (skb->ip_summed == CHECKSUM_COMPLETE)
440 csum_replace(&skb->csum, (__force __wsum)(nh->hop_limit << 8),
445 static void set_ip_ttl(struct sk_buff *skb, struct iphdr *nh, u8 new_ttl,
454 static int set_ipv4(struct sk_buff *skb, struct sw_flow_key *flow_key,
462 err = skb_ensure_writable(skb, skb_network_offset(skb) +
467 nh = ip_hdr(skb);
477 set_ip_addr(skb, nh, &nh->saddr, new_addr);
485 set_ip_addr(skb, nh, &nh->daddr, new_addr);
494 set_ip_ttl(skb, nh, key->ipv4_ttl, mask->ipv4_ttl);
506 static int set_ipv6(struct sk_buff *skb, struct sw_flow_key *flow_key,
513 err = skb_ensure_writable(skb, skb_network_offset(skb) +
518 nh = ipv6_hdr(skb);
531 set_ipv6_addr(skb, flow_key->ip.proto, saddr, masked,
548 recalc_csum = (ipv6_find_hdr(skb, &offset,
553 set_ipv6_addr(skb, flow_key->ip.proto, daddr, masked,
560 set_ipv6_dsfield(skb, nh, key->ipv6_tclass, mask->ipv6_tclass);
564 set_ipv6_fl(skb, nh, ntohl(key->ipv6_label),
570 set_ipv6_ttl(skb, nh, key->ipv6_hlimit, mask->ipv6_hlimit);
576 /* Must follow skb_ensure_writable() since that can move the skb data. */
577 static void set_tp_port(struct sk_buff *skb, __be16 *port,
580 ovs_ct_clear(skb, NULL);
581 inet_proto_csum_replace2(check, skb, *port, new_port, false);
585 static int set_udp(struct sk_buff *skb, struct sw_flow_key *flow_key,
593 err = skb_ensure_writable(skb, skb_transport_offset(skb) +
598 uh = udp_hdr(skb);
603 if (uh->check && skb->ip_summed != CHECKSUM_PARTIAL) {
605 set_tp_port(skb, &uh->source, src, &uh->check);
609 set_tp_port(skb, &uh->dest, dst, &uh->check);
620 ovs_ct_clear(skb, NULL);
623 skb_clear_hash(skb);
628 static int set_tcp(struct sk_buff *skb, struct sw_flow_key *flow_key,
636 err = skb_ensure_writable(skb, skb_transport_offset(skb) +
641 th = tcp_hdr(skb);
644 set_tp_port(skb, &th->source, src, &th->check);
649 set_tp_port(skb, &th->dest, dst, &th->check);
652 skb_clear_hash(skb);
657 static int set_sctp(struct sk_buff *skb, struct sw_flow_key *flow_key,
661 unsigned int sctphoff = skb_transport_offset(skb);
666 err = skb_ensure_writable(skb, sctphoff + sizeof(struct sctphdr));
670 sh = sctp_hdr(skb);
672 old_correct_csum = sctp_compute_cksum(skb, sctphoff);
677 new_csum = sctp_compute_cksum(skb, sctphoff);
682 skb_clear_hash(skb);
683 ovs_ct_clear(skb, NULL);
692 struct sk_buff *skb)
697 if (skb_cow_head(skb, data->l2_len) < 0) {
698 kfree_skb_reason(skb, SKB_DROP_REASON_NOMEM);
702 __skb_dst_copy(skb, data->dst);
703 *OVS_CB(skb) = data->cb;
704 skb->inner_protocol = data->inner_protocol;
706 __vlan_hwaccel_put_tag(skb, data->vlan_proto, data->vlan_tci & ~VLAN_CFI_MASK);
708 __vlan_hwaccel_clear_tag(skb);
711 skb_push(skb, data->l2_len);
712 memcpy(skb->data, &data->l2_data, data->l2_len);
713 skb_postpush_rcsum(skb, skb->data, data->l2_len);
714 skb_reset_mac_header(skb);
716 if (eth_p_mpls(skb->protocol)) {
717 skb->inner_network_header = skb->network_header;
718 skb_set_network_header(skb, data->network_offset);
719 skb_reset_mac_len(skb);
722 ovs_vport_send(vport, skb, data->mac_proto);
740 static void prepare_frag(struct vport *vport, struct sk_buff *skb,
743 unsigned int hlen = skb_network_offset(skb);
747 data->dst = skb->_skb_refdst;
749 data->cb = *OVS_CB(skb);
750 data->inner_protocol = skb->inner_protocol;
752 if (skb_vlan_tag_present(skb))
753 data->vlan_tci = skb_vlan_tag_get(skb) | VLAN_CFI_MASK;
756 data->vlan_proto = skb->vlan_proto;
759 memcpy(&data->l2_data, skb->data, hlen);
761 memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));
762 skb_pull(skb, hlen);
766 struct sk_buff *skb, u16 mru,
772 if (eth_p_mpls(skb->protocol)) {
773 orig_network_offset = skb_network_offset(skb);
774 skb->network_header = skb->inner_network_header;
777 if (skb_network_offset(skb) > MAX_L2_LEN) {
787 prepare_frag(vport, skb, orig_network_offset,
793 orig_dst = skb->_skb_refdst;
794 skb_dst_set_noref(skb, &ovs_rt.dst);
795 IPCB(skb)->frag_max_size = mru;
797 ip_do_fragment(net, skb->sk, skb, ovs_vport_output);
803 prepare_frag(vport, skb, orig_network_offset,
810 orig_dst = skb->_skb_refdst;
811 skb_dst_set_noref(skb, &ovs_rt.dst);
812 IP6CB(skb)->frag_max_size = mru;
814 ip6_fragment(net, skb->sk, skb, ovs_vport_output);
826 ovs_kfree_skb_reason(skb, reason);
829 static void do_output(struct datapath *dp, struct sk_buff *skb, int out_port,
837 u16 mru = OVS_CB(skb)->mru;
838 u32 cutlen = OVS_CB(skb)->cutlen;
841 if (skb->len - cutlen > ovs_mac_header_len(key))
842 pskb_trim(skb, skb->len - cutlen);
844 pskb_trim(skb, ovs_mac_header_len(key));
848 (skb->len <= mru + vport->dev->hard_header_len))) {
849 ovs_vport_send(vport, skb, ovs_key_mac_proto(key));
853 ovs_fragment(net, vport, skb, mru, key);
855 kfree_skb_reason(skb, SKB_DROP_REASON_PKT_TOO_BIG);
858 kfree_skb_reason(skb, SKB_DROP_REASON_DEV_READY);
862 static int output_userspace(struct datapath *dp, struct sk_buff *skb,
873 upcall.mru = OVS_CB(skb)->mru;
882 if (OVS_CB(skb)->upcall_pid)
883 upcall.portid = OVS_CB(skb)->upcall_pid;
901 err = dev_fill_metadata_dst(vport->dev, skb);
903 upcall.egress_tun_info = skb_tunnel_info(skb);
919 return ovs_dp_upcall(dp, skb, key, &upcall, cutlen);
922 static int dec_ttl_exception_handler(struct datapath *dp, struct sk_buff *skb,
930 return clone_execute(dp, skb, key, 0, nla_data(actions),
933 ovs_kfree_skb_reason(skb, OVS_DROP_IP_TTL);
937 /* When 'last' is true, sample() should always consume the 'skb'.
938 * Otherwise, sample() should keep 'skb' intact regardless what
941 static int sample(struct datapath *dp, struct sk_buff *skb,
957 init_probability = OVS_CB(skb)->probability;
962 ovs_kfree_skb_reason(skb, OVS_DROP_LAST_ACTION);
966 OVS_CB(skb)->probability = arg->probability;
969 err = clone_execute(dp, skb, key, 0, actions, rem, last,
973 OVS_CB(skb)->probability = init_probability;
978 /* When 'last' is true, clone() should always consume the 'skb'.
979 * Otherwise, clone() should keep 'skb' intact regardless what
982 static int clone(struct datapath *dp, struct sk_buff *skb,
996 return clone_execute(dp, skb, key, 0, actions, rem, last,
1000 static void execute_hash(struct sk_buff *skb, struct sw_flow_key *key,
1008 hash = skb_get_hash(skb);
1013 hash = __skb_get_hash_symmetric(skb);
1023 static int execute_set_action(struct sk_buff *skb,
1031 skb_dst_drop(skb);
1033 skb_dst_set(skb, (struct dst_entry *)tun->tun_dst);
1043 static int execute_masked_set_action(struct sk_buff *skb,
1051 OVS_SET_MASKED(skb->priority, nla_get_u32(a),
1053 flow_key->phy.priority = skb->priority;
1057 OVS_SET_MASKED(skb->mark, nla_get_u32(a), *get_mask(a, u32 *));
1058 flow_key->phy.skb_mark = skb->mark;
1067 err = set_eth_addr(skb, flow_key, nla_data(a),
1072 err = set_ipv4(skb, flow_key, nla_data(a),
1077 err = set_ipv6(skb, flow_key, nla_data(a),
1082 err = set_tcp(skb, flow_key, nla_data(a),
1087 err = set_udp(skb, flow_key, nla_data(a),
1092 err = set_sctp(skb, flow_key, nla_data(a),
1097 err = set_mpls(skb, flow_key, nla_data(a), get_mask(a,
1115 static int execute_recirc(struct datapath *dp, struct sk_buff *skb,
1124 err = ovs_flow_key_update(skb, key);
1131 return clone_execute(dp, skb, key, recirc_id, NULL, 0, last, true);
1134 static int execute_check_pkt_len(struct datapath *dp, struct sk_buff *skb,
1138 struct ovs_skb_cb *ovs_cb = OVS_CB(skb);
1150 len = ovs_cb->mru ? ovs_cb->mru + skb->mac_len : skb->len;
1153 if ((skb_is_gso(skb) && skb_gso_validate_mac_len(skb, max_len)) ||
1169 return clone_execute(dp, skb, key, 0, nla_data(actions),
1173 static int execute_dec_ttl(struct sk_buff *skb, struct sw_flow_key *key)
1177 if (skb->protocol == htons(ETH_P_IPV6)) {
1180 err = skb_ensure_writable(skb, skb_network_offset(skb) +
1185 nh = ipv6_hdr(skb);
1191 } else if (skb->protocol == htons(ETH_P_IP)) {
1195 err = skb_ensure_writable(skb, skb_network_offset(skb) +
1200 nh = ip_hdr(skb);
1213 static void execute_psample(struct datapath *dp, struct sk_buff *skb,
1236 md.in_ifindex = OVS_CB(skb)->input_vport->dev->ifindex;
1237 md.trunc_size = skb->len - OVS_CB(skb)->cutlen;
1240 rate = OVS_CB(skb)->probability ? OVS_CB(skb)->probability : U32_MAX;
1242 psample_sample_packet(&psample_group, skb, rate, &md);
1245 static void execute_psample(struct datapath *dp, struct sk_buff *skb,
1250 /* Execute a list of actions against 'skb'. */
1251 static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
1263 trace_ovs_do_execute_action(dp, skb, key, a, rem);
1265 /* Actions that rightfully have to consume the skb should do it
1274 * of 'skb', In case the output action is the
1278 do_output(dp, skb, port, key);
1279 /* 'skb' has been used for output.
1284 clone = skb_clone(skb, GFP_ATOMIC);
1287 OVS_CB(skb)->cutlen = 0;
1294 if (skb->len > trunc->max_len)
1295 OVS_CB(skb)->cutlen = skb->len - trunc->max_len;
1300 output_userspace(dp, skb, key, a, attr,
1301 len, OVS_CB(skb)->cutlen);
1302 OVS_CB(skb)->cutlen = 0;
1304 consume_skb(skb);
1310 execute_hash(skb, key, a);
1316 err = push_mpls(skb, key, mpls->mpls_lse,
1317 mpls->mpls_ethertype, skb->mac_len);
1325 mac_len = skb->mac_len;
1327 err = push_mpls(skb, key, mpls->mpls_lse,
1332 err = pop_mpls(skb, key, nla_get_be16(a));
1336 err = push_vlan(skb, key, nla_data(a));
1340 err = pop_vlan(skb, key);
1346 err = execute_recirc(dp, skb, key, a, last);
1348 /* If this is the last action, the skb has
1358 err = execute_set_action(skb, key, nla_data(a));
1363 err = execute_masked_set_action(skb, key, nla_data(a));
1369 err = sample(dp, skb, key, a, last);
1378 err = ovs_flow_key_update(skb, key);
1383 err = ovs_ct_execute(ovs_dp_get_net(dp), skb, key,
1392 err = ovs_ct_clear(skb, key);
1396 err = push_eth(skb, key, nla_data(a));
1400 err = pop_eth(skb, key);
1404 err = push_nsh(skb, key, nla_data(a));
1408 err = pop_nsh(skb, key);
1412 if (ovs_meter_execute(dp, skb, key, nla_get_u32(a))) {
1413 ovs_kfree_skb_reason(skb, OVS_DROP_METER);
1421 err = clone(dp, skb, key, a, last);
1431 err = execute_check_pkt_len(dp, skb, key, a, last);
1439 err = execute_dec_ttl(skb, key);
1441 return dec_ttl_exception_handler(dp, skb,
1450 ovs_kfree_skb_reason(skb, reason);
1455 execute_psample(dp, skb, a);
1456 OVS_CB(skb)->cutlen = 0;
1458 consume_skb(skb);
1465 ovs_kfree_skb_reason(skb, OVS_DROP_ACTION_ERROR);
1470 ovs_kfree_skb_reason(skb, OVS_DROP_LAST_ACTION);
1475 * execution does not affect the original 'skb' nor the original 'key'.
1480 static int clone_execute(struct datapath *dp, struct sk_buff *skb,
1488 skb = last ? skb : skb_clone(skb, GFP_ATOMIC);
1489 if (!skb) {
1508 err = do_execute_actions(dp, skb, clone,
1515 ovs_dp_process_packet(skb, clone);
1521 da = add_deferred_actions(skb, key, actions, len);
1528 /* Out of per CPU action FIFO space. Drop the 'skb' and
1531 ovs_kfree_skb_reason(skb, OVS_DROP_DEFERRED_LIMIT);
1557 struct sk_buff *skb = da->skb;
1563 do_execute_actions(dp, skb, key, actions, actions_len);
1565 ovs_dp_process_packet(skb, key);
1572 /* Execute a list of actions against 'skb'. */
1573 int ovs_execute_actions(struct datapath *dp, struct sk_buff *skb,
1583 ovs_kfree_skb_reason(skb, OVS_DROP_RECURSION_LIMIT);
1588 OVS_CB(skb)->acts_origlen = acts->orig_len;
1589 err = do_execute_actions(dp, skb, key,