Skip to content

Commit 9d802da

Browse files
amorenozdavem330
authored andcommitted
net: openvswitch: add last-action drop reason
Create a new drop reason subsystem for openvswitch and add the first drop reason to represent last-action drops. Last-action drops happen when a flow has an empty action list or there is no action that consumes the packet (output, userspace, recirc, etc). It is the most common way in which OVS drops packets. Implementation-wise, most of these skb-consuming actions already call "consume_skb" internally and return directly from within the do_execute_actions() loop so with minimal changes we can assume that any skb that exits the loop normally is a packet drop. Signed-off-by: Adrian Moreno <amorenoz@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent afb0c19 commit 9d802da

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

include/net/dropreason.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ enum skb_drop_reason_subsys {
2323
*/
2424
SKB_DROP_REASON_SUBSYS_MAC80211_MONITOR,
2525

26+
/**
27+
* @SKB_DROP_REASON_SUBSYS_OPENVSWITCH: openvswitch drop reasons,
28+
* see net/openvswitch/drop.h
29+
*/
30+
SKB_DROP_REASON_SUBSYS_OPENVSWITCH,
31+
2632
/** @SKB_DROP_REASON_SUBSYS_NUM: number of subsystems defined */
2733
SKB_DROP_REASON_SUBSYS_NUM
2834
};

net/openvswitch/actions.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <net/sctp/checksum.h>
2828

2929
#include "datapath.h"
30+
#include "drop.h"
3031
#include "flow.h"
3132
#include "conntrack.h"
3233
#include "vport.h"
@@ -1036,7 +1037,7 @@ static int sample(struct datapath *dp, struct sk_buff *skb,
10361037
if ((arg->probability != U32_MAX) &&
10371038
(!arg->probability || get_random_u32() > arg->probability)) {
10381039
if (last)
1039-
consume_skb(skb);
1040+
ovs_kfree_skb_reason(skb, OVS_DROP_LAST_ACTION);
10401041
return 0;
10411042
}
10421043

@@ -1297,6 +1298,9 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
12971298
if (trace_ovs_do_execute_action_enabled())
12981299
trace_ovs_do_execute_action(dp, skb, key, a, rem);
12991300

1301+
/* Actions that rightfully have to consume the skb should do it
1302+
* and return directly.
1303+
*/
13001304
switch (nla_type(a)) {
13011305
case OVS_ACTION_ATTR_OUTPUT: {
13021306
int port = nla_get_u32(a);
@@ -1332,6 +1336,10 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
13321336
output_userspace(dp, skb, key, a, attr,
13331337
len, OVS_CB(skb)->cutlen);
13341338
OVS_CB(skb)->cutlen = 0;
1339+
if (nla_is_last(a, rem)) {
1340+
consume_skb(skb);
1341+
return 0;
1342+
}
13351343
break;
13361344

13371345
case OVS_ACTION_ATTR_HASH:
@@ -1485,7 +1493,7 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
14851493
}
14861494
}
14871495

1488-
consume_skb(skb);
1496+
ovs_kfree_skb_reason(skb, OVS_DROP_LAST_ACTION);
14891497
return 0;
14901498
}
14911499

net/openvswitch/datapath.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <net/pkt_cls.h>
4242

4343
#include "datapath.h"
44+
#include "drop.h"
4445
#include "flow.h"
4546
#include "flow_table.h"
4647
#include "flow_netlink.h"
@@ -2702,6 +2703,17 @@ static struct pernet_operations ovs_net_ops = {
27022703
.size = sizeof(struct ovs_net),
27032704
};
27042705

2706+
static const char * const ovs_drop_reasons[] = {
2707+
#define S(x) (#x),
2708+
OVS_DROP_REASONS(S)
2709+
#undef S
2710+
};
2711+
2712+
static struct drop_reason_list drop_reason_list_ovs = {
2713+
.reasons = ovs_drop_reasons,
2714+
.n_reasons = ARRAY_SIZE(ovs_drop_reasons),
2715+
};
2716+
27052717
static int __init dp_init(void)
27062718
{
27072719
int err;
@@ -2743,6 +2755,9 @@ static int __init dp_init(void)
27432755
if (err < 0)
27442756
goto error_unreg_netdev;
27452757

2758+
drop_reasons_register_subsys(SKB_DROP_REASON_SUBSYS_OPENVSWITCH,
2759+
&drop_reason_list_ovs);
2760+
27462761
return 0;
27472762

27482763
error_unreg_netdev:
@@ -2769,6 +2784,7 @@ static void dp_cleanup(void)
27692784
ovs_netdev_exit();
27702785
unregister_netdevice_notifier(&ovs_dp_device_notifier);
27712786
unregister_pernet_device(&ovs_net_ops);
2787+
drop_reasons_unregister_subsys(SKB_DROP_REASON_SUBSYS_OPENVSWITCH);
27722788
rcu_barrier();
27732789
ovs_vport_exit();
27742790
ovs_flow_exit();

net/openvswitch/drop.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* OpenvSwitch drop reason list.
4+
*/
5+
6+
#ifndef OPENVSWITCH_DROP_H
7+
#define OPENVSWITCH_DROP_H
8+
#include <linux/skbuff.h>
9+
#include <net/dropreason.h>
10+
11+
#define OVS_DROP_REASONS(R) \
12+
R(OVS_DROP_LAST_ACTION) \
13+
/* deliberate comment for trailing \ */
14+
15+
enum ovs_drop_reason {
16+
__OVS_DROP_REASON = SKB_DROP_REASON_SUBSYS_OPENVSWITCH <<
17+
SKB_DROP_REASON_SUBSYS_SHIFT,
18+
#define ENUM(x) x,
19+
OVS_DROP_REASONS(ENUM)
20+
#undef ENUM
21+
22+
OVS_DROP_MAX,
23+
};
24+
25+
static inline void
26+
ovs_kfree_skb_reason(struct sk_buff *skb, enum ovs_drop_reason reason)
27+
{
28+
kfree_skb_reason(skb, (u32)reason);
29+
}
30+
31+
#endif /* OPENVSWITCH_DROP_H */

0 commit comments

Comments
 (0)