Commit 24ec483c authored by Kevin 'ldir' Darbyshire-Bryant's avatar Kevin 'ldir' Darbyshire-Bryant Committed by David S. Miller

net: sched: Introduce act_ctinfo action

ctinfo is a new tc filter action module.  It is designed to restore
information contained in firewall conntrack marks to other packet fields
and is typically used on packet ingress paths.  At present it has two
independent sub-functions or operating modes, DSCP restoration mode &
skb mark restoration mode.

The DSCP restore mode:

This mode copies DSCP values that have been placed in the firewall
conntrack mark back into the IPv4/v6 diffserv fields of relevant
packets.

The DSCP restoration is intended for use and has been found useful for
restoring ingress classifications based on egress classifications across
links that bleach or otherwise change DSCP, typically home ISP Internet
links.  Restoring DSCP on ingress on the WAN link allows qdiscs such as
but by no means limited to CAKE to shape inbound packets according to
policies that are easier to set & mark on egress.

Ingress classification is traditionally a challenging task since
iptables rules haven't yet run and tc filter/eBPF programs are pre-NAT
lookups, hence are unable to see internal IPv4 addresses as used on the
typical home masquerading gateway.  Thus marking the connection in some
manner on egress for later restoration of classification on ingress is
easier to implement.

Parameters related to DSCP restore mode:

dscpmask - a 32 bit mask of 6 contiguous bits and indicate bits of the
conntrack mark field contain the DSCP value to be restored.

statemask - a 32 bit mask of (usually) 1 bit length, outside the area
specified by dscpmask.  This represents a conditional operation flag
whereby the DSCP is only restored if the flag is set.  This is useful to
implement a 'one shot' iptables based classification where the
'complicated' iptables rules are only run once to classify the
connection on initial (egress) packet and subsequent packets are all
marked/restored with the same DSCP.  A mask of zero disables the
conditional behaviour ie. the conntrack mark DSCP bits are always
restored to the ip diffserv field (assuming the conntrack entry is found
& the skb is an ipv4/ipv6 type)

e.g. dscpmask 0xfc000000 statemask 0x01000000

|----0xFC----conntrack mark----000000---|
| Bits 31-26 | bit 25 | bit24 |~~~ Bit 0|
| DSCP       | unused | flag  |unused   |
|-----------------------0x01---000000---|
      |                   |
      |                   |
      ---|             Conditional flag
         v             only restore if set
|-ip diffserv-|
| 6 bits      |
|-------------|

The skb mark restore mode (cpmark):

This mode copies the firewall conntrack mark to the skb's mark field.
It is completely the functional equivalent of the existing act_connmark
action with the additional feature of being able to apply a mask to the
restored value.

Parameters related to skb mark restore mode:

mask - a 32 bit mask applied to the firewall conntrack mark to mask out
bits unwanted for restoration.  This can be useful where the conntrack
mark is being used for different purposes by different applications.  If
not specified and by default the whole mark field is copied (i.e.
default mask of 0xffffffff)

e.g. mask 0x00ffffff to mask out the top 8 bits being used by the
aforementioned DSCP restore mode.

|----0x00----conntrack mark----ffffff---|
| Bits 31-24 |                          |
| DSCP & flag|      some value here     |
|---------------------------------------|
			|
			|
			v
|------------skb mark-------------------|
|            |                          |
|  zeroed    |                          |
|---------------------------------------|

Overall parameters:

zone - conntrack zone

control - action related control (reclassify | pipe | drop | continue |
ok | goto chain <CHAIN_INDEX>)
Signed-off-by: default avatarKevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
Reviewed-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
Acked-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a6851c61
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __NET_TC_CTINFO_H
#define __NET_TC_CTINFO_H
#include <net/act_api.h>
struct tcf_ctinfo_params {
struct rcu_head rcu;
struct net *net;
u32 dscpmask;
u32 dscpstatemask;
u32 cpmarkmask;
u16 zone;
u8 mode;
u8 dscpmaskshift;
};
struct tcf_ctinfo {
struct tc_action common;
struct tcf_ctinfo_params __rcu *params;
u64 stats_dscp_set;
u64 stats_dscp_error;
u64 stats_cpmark_set;
};
#define to_ctinfo(a) ((struct tcf_ctinfo *)a)
#endif /* __NET_TC_CTINFO_H */
...@@ -105,6 +105,7 @@ enum tca_id { ...@@ -105,6 +105,7 @@ enum tca_id {
TCA_ID_IFE = TCA_ACT_IFE, TCA_ID_IFE = TCA_ACT_IFE,
TCA_ID_SAMPLE = TCA_ACT_SAMPLE, TCA_ID_SAMPLE = TCA_ACT_SAMPLE,
/* other actions go here */ /* other actions go here */
TCA_ID_CTINFO,
__TCA_ID_MAX = 255 __TCA_ID_MAX = 255
}; };
......
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
#ifndef __UAPI_TC_CTINFO_H
#define __UAPI_TC_CTINFO_H
#include <linux/types.h>
#include <linux/pkt_cls.h>
struct tc_ctinfo {
tc_gen;
};
enum {
TCA_CTINFO_UNSPEC,
TCA_CTINFO_PAD,
TCA_CTINFO_TM,
TCA_CTINFO_ACT,
TCA_CTINFO_ZONE,
TCA_CTINFO_PARMS_DSCP_MASK,
TCA_CTINFO_PARMS_DSCP_STATEMASK,
TCA_CTINFO_PARMS_CPMARK_MASK,
TCA_CTINFO_STATS_DSCP_SET,
TCA_CTINFO_STATS_DSCP_ERROR,
TCA_CTINFO_STATS_CPMARK_SET,
__TCA_CTINFO_MAX
};
#define TCA_CTINFO_MAX (__TCA_CTINFO_MAX - 1)
enum {
CTINFO_MODE_DSCP = BIT(0),
CTINFO_MODE_CPMARK = BIT(1)
};
#endif
...@@ -877,6 +877,23 @@ config NET_ACT_CONNMARK ...@@ -877,6 +877,23 @@ config NET_ACT_CONNMARK
To compile this code as a module, choose M here: the To compile this code as a module, choose M here: the
module will be called act_connmark. module will be called act_connmark.
config NET_ACT_CTINFO
tristate "Netfilter Connection Mark Actions"
depends on NET_CLS_ACT && NETFILTER && IP_NF_IPTABLES
depends on NF_CONNTRACK && NF_CONNTRACK_MARK
help
Say Y here to allow transfer of a connmark stored information.
Current actions transfer connmark stored DSCP into
ipv4/v6 diffserv and/or to transfer connmark to packet
mark. Both are useful for restoring egress based marks
back onto ingress connections for qdisc priority mapping
purposes.
If unsure, say N.
To compile this code as a module, choose M here: the
module will be called act_ctinfo.
config NET_ACT_SKBMOD config NET_ACT_SKBMOD
tristate "skb data modification action" tristate "skb data modification action"
depends on NET_CLS_ACT depends on NET_CLS_ACT
......
...@@ -21,6 +21,7 @@ obj-$(CONFIG_NET_ACT_CSUM) += act_csum.o ...@@ -21,6 +21,7 @@ obj-$(CONFIG_NET_ACT_CSUM) += act_csum.o
obj-$(CONFIG_NET_ACT_VLAN) += act_vlan.o obj-$(CONFIG_NET_ACT_VLAN) += act_vlan.o
obj-$(CONFIG_NET_ACT_BPF) += act_bpf.o obj-$(CONFIG_NET_ACT_BPF) += act_bpf.o
obj-$(CONFIG_NET_ACT_CONNMARK) += act_connmark.o obj-$(CONFIG_NET_ACT_CONNMARK) += act_connmark.o
obj-$(CONFIG_NET_ACT_CTINFO) += act_ctinfo.o
obj-$(CONFIG_NET_ACT_SKBMOD) += act_skbmod.o obj-$(CONFIG_NET_ACT_SKBMOD) += act_skbmod.o
obj-$(CONFIG_NET_ACT_IFE) += act_ife.o obj-$(CONFIG_NET_ACT_IFE) += act_ife.o
obj-$(CONFIG_NET_IFE_SKBMARK) += act_meta_mark.o obj-$(CONFIG_NET_IFE_SKBMARK) += act_meta_mark.o
......
This diff is collapsed.
...@@ -38,6 +38,7 @@ CONFIG_NET_ACT_CSUM=m ...@@ -38,6 +38,7 @@ CONFIG_NET_ACT_CSUM=m
CONFIG_NET_ACT_VLAN=m CONFIG_NET_ACT_VLAN=m
CONFIG_NET_ACT_BPF=m CONFIG_NET_ACT_BPF=m
CONFIG_NET_ACT_CONNMARK=m CONFIG_NET_ACT_CONNMARK=m
CONFIG_NET_ACT_CTINFO=m
CONFIG_NET_ACT_SKBMOD=m CONFIG_NET_ACT_SKBMOD=m
CONFIG_NET_ACT_IFE=m CONFIG_NET_ACT_IFE=m
CONFIG_NET_ACT_TUNNEL_KEY=m CONFIG_NET_ACT_TUNNEL_KEY=m
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment