linux/net/sched/em_meta.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * net/sched/em_meta.c	Metadata ematch
 *
 * Authors:	Thomas Graf <[email protected]>
 *
 * ==========================================================================
 *
 * 	The metadata ematch compares two meta objects where each object
 * 	represents either a meta value stored in the kernel or a static
 * 	value provided by userspace. The objects are not provided by
 * 	userspace itself but rather a definition providing the information
 * 	to build them. Every object is of a certain type which must be
 * 	equal to the object it is being compared to.
 *
 * 	The definition of a objects conists of the type (meta type), a
 * 	identifier (meta id) and additional type specific information.
 * 	The meta id is either TCF_META_TYPE_VALUE for values provided by
 * 	userspace or a index to the meta operations table consisting of
 * 	function pointers to type specific meta data collectors returning
 * 	the value of the requested meta value.
 *
 * 	         lvalue                                   rvalue
 * 	      +-----------+                           +-----------+
 * 	      | type: INT |                           | type: INT |
 * 	 def  | id: DEV   |                           | id: VALUE |
 * 	      | data:     |                           | data: 3   |
 * 	      +-----------+                           +-----------+
 * 	            |                                       |
 * 	            ---> meta_ops[INT][DEV](...)            |
 *	                      |                             |
 * 	            -----------                             |
 * 	            V                                       V
 * 	      +-----------+                           +-----------+
 * 	      | type: INT |                           | type: INT |
 * 	 obj  | id: DEV |                             | id: VALUE |
 * 	      | data: 2   |<--data got filled out     | data: 3   |
 * 	      +-----------+                           +-----------+
 * 	            |                                         |
 * 	            --------------> 2  equals 3 <--------------
 *
 * 	This is a simplified schema, the complexity varies depending
 * 	on the meta type. Obviously, the length of the data must also
 * 	be provided for non-numeric types.
 *
 * 	Additionally, type dependent modifiers such as shift operators
 * 	or mask may be applied to extend the functionality. As of now,
 * 	the variable length type supports shifting the byte string to
 * 	the right, eating up any number of octets and thus supporting
 * 	wildcard interface name comparisons such as "ppp%" matching
 * 	ppp0..9.
 *
 * 	NOTE: Certain meta values depend on other subsystems and are
 * 	      only available if that subsystem is enabled in the kernel.
 */

#include <linux/slab.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/sched/loadavg.h>
#include <linux/string.h>
#include <linux/skbuff.h>
#include <linux/random.h>
#include <linux/if_vlan.h>
#include <linux/tc_ematch/tc_em_meta.h>
#include <net/dst.h>
#include <net/route.h>
#include <net/pkt_cls.h>
#include <net/sock.h>

struct meta_obj {};

struct meta_value {};

struct meta_match {};

static inline int meta_id(struct meta_value *v)
{}

static inline int meta_type(struct meta_value *v)
{}

#define META_COLLECTOR(FUNC)

/**************************************************************************
 * System status & misc
 **************************************************************************/

META_COLLECTOR(int_random)
{}

static inline unsigned long fixed_loadavg(int load)
{}

META_COLLECTOR(int_loadavg_0)
{}

META_COLLECTOR(int_loadavg_1)
{}

META_COLLECTOR(int_loadavg_2)
{}

/**************************************************************************
 * Device names & indices
 **************************************************************************/

static inline int int_dev(struct net_device *dev, struct meta_obj *dst)
{}

static inline int var_dev(struct net_device *dev, struct meta_obj *dst)
{}

META_COLLECTOR(int_dev)
{}

META_COLLECTOR(var_dev)
{}

/**************************************************************************
 * vlan tag
 **************************************************************************/

META_COLLECTOR(int_vlan_tag)
{}



/**************************************************************************
 * skb attributes
 **************************************************************************/

META_COLLECTOR(int_priority)
{}

META_COLLECTOR(int_protocol)
{}

META_COLLECTOR(int_pkttype)
{}

META_COLLECTOR(int_pktlen)
{}

META_COLLECTOR(int_datalen)
{}

META_COLLECTOR(int_maclen)
{}

META_COLLECTOR(int_rxhash)
{}

/**************************************************************************
 * Netfilter
 **************************************************************************/

META_COLLECTOR(int_mark)
{}

/**************************************************************************
 * Traffic Control
 **************************************************************************/

META_COLLECTOR(int_tcindex)
{}

/**************************************************************************
 * Routing
 **************************************************************************/

META_COLLECTOR(int_rtclassid)
{}

META_COLLECTOR(int_rtiif)
{}

/**************************************************************************
 * Socket Attributes
 **************************************************************************/

#define skip_nonlocal(skb)

META_COLLECTOR(int_sk_family)
{}

META_COLLECTOR(int_sk_state)
{}

META_COLLECTOR(int_sk_reuse)
{}

META_COLLECTOR(int_sk_bound_if)
{}

META_COLLECTOR(var_sk_bound_if)
{}

META_COLLECTOR(int_sk_refcnt)
{}

META_COLLECTOR(int_sk_rcvbuf)
{}

META_COLLECTOR(int_sk_shutdown)
{}

META_COLLECTOR(int_sk_proto)
{}

META_COLLECTOR(int_sk_type)
{}

META_COLLECTOR(int_sk_rmem_alloc)
{}

META_COLLECTOR(int_sk_wmem_alloc)
{}

META_COLLECTOR(int_sk_omem_alloc)
{}

META_COLLECTOR(int_sk_rcv_qlen)
{}

META_COLLECTOR(int_sk_snd_qlen)
{}

META_COLLECTOR(int_sk_wmem_queued)
{}

META_COLLECTOR(int_sk_fwd_alloc)
{}

META_COLLECTOR(int_sk_sndbuf)
{}

META_COLLECTOR(int_sk_alloc)
{}

META_COLLECTOR(int_sk_hash)
{}

META_COLLECTOR(int_sk_lingertime)
{}

META_COLLECTOR(int_sk_err_qlen)
{}

META_COLLECTOR(int_sk_ack_bl)
{}

META_COLLECTOR(int_sk_max_ack_bl)
{}

META_COLLECTOR(int_sk_prio)
{}

META_COLLECTOR(int_sk_rcvlowat)
{}

META_COLLECTOR(int_sk_rcvtimeo)
{}

META_COLLECTOR(int_sk_sndtimeo)
{}

META_COLLECTOR(int_sk_sendmsg_off)
{}

META_COLLECTOR(int_sk_write_pend)
{}

/**************************************************************************
 * Meta value collectors assignment table
 **************************************************************************/

struct meta_ops {};

#define META_ID(name)
#define META_FUNC(name)

/* Meta value operations table listing all meta value collectors and
 * assigns them to a type and meta id. */
static struct meta_ops __meta_ops[TCF_META_TYPE_MAX + 1][TCF_META_ID_MAX + 1] =;

static inline struct meta_ops *meta_ops(struct meta_value *val)
{}

/**************************************************************************
 * Type specific operations for TCF_META_TYPE_VAR
 **************************************************************************/

static int meta_var_compare(struct meta_obj *a, struct meta_obj *b)
{}

static int meta_var_change(struct meta_value *dst, struct nlattr *nla)
{}

static void meta_var_destroy(struct meta_value *v)
{}

static void meta_var_apply_extras(struct meta_value *v,
				  struct meta_obj *dst)
{}

static int meta_var_dump(struct sk_buff *skb, struct meta_value *v, int tlv)
{}

/**************************************************************************
 * Type specific operations for TCF_META_TYPE_INT
 **************************************************************************/

static int meta_int_compare(struct meta_obj *a, struct meta_obj *b)
{}

static int meta_int_change(struct meta_value *dst, struct nlattr *nla)
{}

static void meta_int_apply_extras(struct meta_value *v,
				  struct meta_obj *dst)
{}

static int meta_int_dump(struct sk_buff *skb, struct meta_value *v, int tlv)
{}

/**************************************************************************
 * Type specific operations table
 **************************************************************************/

struct meta_type_ops {};

static const struct meta_type_ops __meta_type_ops[TCF_META_TYPE_MAX + 1] =;

static inline const struct meta_type_ops *meta_type_ops(struct meta_value *v)
{}

/**************************************************************************
 * Core
 **************************************************************************/

static int meta_get(struct sk_buff *skb, struct tcf_pkt_info *info,
		    struct meta_value *v, struct meta_obj *dst)
{}

static int em_meta_match(struct sk_buff *skb, struct tcf_ematch *m,
			 struct tcf_pkt_info *info)
{}

static void meta_delete(struct meta_match *meta)
{}

static inline int meta_change_data(struct meta_value *dst, struct nlattr *nla)
{}

static inline int meta_is_supported(struct meta_value *val)
{}

static const struct nla_policy meta_policy[TCA_EM_META_MAX + 1] =;

static int em_meta_change(struct net *net, void *data, int len,
			  struct tcf_ematch *m)
{}

static void em_meta_destroy(struct tcf_ematch *m)
{}

static int em_meta_dump(struct sk_buff *skb, struct tcf_ematch *em)
{}

static struct tcf_ematch_ops em_meta_ops =;

static int __init init_em_meta(void)
{}

static void __exit exit_em_meta(void)
{}

MODULE_DESCRIPTION();
MODULE_LICENSE();

module_init();
module_exit(exit_em_meta);

MODULE_ALIAS_TCF_EMATCH();