linux/drivers/net/macsec.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * drivers/net/macsec.c - MACsec device
 *
 * Copyright (c) 2015 Sabrina Dubroca <[email protected]>
 */

#include <linux/types.h>
#include <linux/skbuff.h>
#include <linux/socket.h>
#include <linux/module.h>
#include <crypto/aead.h>
#include <linux/etherdevice.h>
#include <linux/netdevice.h>
#include <linux/rtnetlink.h>
#include <linux/refcount.h>
#include <net/genetlink.h>
#include <net/sock.h>
#include <net/gro_cells.h>
#include <net/macsec.h>
#include <net/dst_metadata.h>
#include <linux/phy.h>
#include <linux/byteorder/generic.h>
#include <linux/if_arp.h>

#include <uapi/linux/if_macsec.h>

/* SecTAG length = macsec_eth_header without the optional SCI */
#define MACSEC_TAG_LEN

struct macsec_eth_header {} __packed;

/* minimum secure data length deemed "not short", see IEEE 802.1AE-2006 9.7 */
#define MIN_NON_SHORT_LEN

#define GCM_AES_IV_LEN

#define for_each_rxsc(secy, sc)
#define for_each_rxsc_rtnl(secy, sc)

#define pn_same_half(pn1, pn2)

struct gcm_iv_xpn {} __packed;

struct gcm_iv {};

#define MACSEC_VALIDATE_DEFAULT

struct pcpu_secy_stats {};

/**
 * struct macsec_dev - private data
 * @secy: SecY config
 * @real_dev: pointer to underlying netdevice
 * @dev_tracker: refcount tracker for @real_dev reference
 * @stats: MACsec device stats
 * @secys: linked list of SecY's on the underlying device
 * @gro_cells: pointer to the Generic Receive Offload cell
 * @offload: status of offloading on the MACsec device
 * @insert_tx_tag: when offloading, device requires to insert an
 *	additional tag
 */
struct macsec_dev {};

/**
 * struct macsec_rxh_data - rx_handler private argument
 * @secys: linked list of SecY's on this underlying device
 */
struct macsec_rxh_data {};

static struct macsec_dev *macsec_priv(const struct net_device *dev)
{}

static struct macsec_rxh_data *macsec_data_rcu(const struct net_device *dev)
{}

static struct macsec_rxh_data *macsec_data_rtnl(const struct net_device *dev)
{}

struct macsec_cb {};

static struct macsec_rx_sa *macsec_rxsa_get(struct macsec_rx_sa __rcu *ptr)
{}

static struct macsec_rx_sa *macsec_active_rxsa_get(struct macsec_rx_sc *rx_sc)
{}

static void free_rx_sc_rcu(struct rcu_head *head)
{}

static struct macsec_rx_sc *macsec_rxsc_get(struct macsec_rx_sc *sc)
{}

static void macsec_rxsc_put(struct macsec_rx_sc *sc)
{}

static void free_rxsa(struct rcu_head *head)
{}

static void macsec_rxsa_put(struct macsec_rx_sa *sa)
{}

static struct macsec_tx_sa *macsec_txsa_get(struct macsec_tx_sa __rcu *ptr)
{}

static void free_txsa(struct rcu_head *head)
{}

static void macsec_txsa_put(struct macsec_tx_sa *sa)
{}

static struct macsec_cb *macsec_skb_cb(struct sk_buff *skb)
{}

#define MACSEC_PORT_SCB
#define MACSEC_UNDEF_SCI
#define MACSEC_UNDEF_SSCI

#define MACSEC_GCM_AES_128_SAK_LEN
#define MACSEC_GCM_AES_256_SAK_LEN

#define DEFAULT_SAK_LEN
#define DEFAULT_XPN
#define DEFAULT_SEND_SCI
#define DEFAULT_ENCRYPT
#define DEFAULT_ENCODING_SA
#define MACSEC_XPN_MAX_REPLAY_WINDOW

static sci_t make_sci(const u8 *addr, __be16 port)
{}

static sci_t macsec_frame_sci(struct macsec_eth_header *hdr, bool sci_present)
{}

static unsigned int macsec_sectag_len(bool sci_present)
{}

static unsigned int macsec_hdr_len(bool sci_present)
{}

static unsigned int macsec_extra_len(bool sci_present)
{}

/* Fill SecTAG according to IEEE 802.1AE-2006 10.5.3 */
static void macsec_fill_sectag(struct macsec_eth_header *h,
			       const struct macsec_secy *secy, u32 pn,
			       bool sci_present)
{}

static void macsec_set_shortlen(struct macsec_eth_header *h, size_t data_len)
{}

/* Checks if a MACsec interface is being offloaded to an hardware engine */
static bool macsec_is_offloaded(struct macsec_dev *macsec)
{}

/* Checks if underlying layers implement MACsec offloading functions. */
static bool macsec_check_offload(enum macsec_offload offload,
				 struct macsec_dev *macsec)
{}

static const struct macsec_ops *__macsec_get_ops(enum macsec_offload offload,
						 struct macsec_dev *macsec,
						 struct macsec_context *ctx)
{}

/* Returns a pointer to the MACsec ops struct if any and updates the MACsec
 * context device reference if provided.
 */
static const struct macsec_ops *macsec_get_ops(struct macsec_dev *macsec,
					       struct macsec_context *ctx)
{}

/* validate MACsec packet according to IEEE 802.1AE-2018 9.12 */
static bool macsec_validate_skb(struct sk_buff *skb, u16 icv_len, bool xpn)
{}

#define MACSEC_NEEDED_HEADROOM
#define MACSEC_NEEDED_TAILROOM

static void macsec_fill_iv_xpn(unsigned char *iv, ssci_t ssci, u64 pn,
			       salt_t salt)
{}

static void macsec_fill_iv(unsigned char *iv, sci_t sci, u32 pn)
{}

static struct macsec_eth_header *macsec_ethhdr(struct sk_buff *skb)
{}

static void __macsec_pn_wrapped(struct macsec_secy *secy,
				struct macsec_tx_sa *tx_sa)
{}

void macsec_pn_wrapped(struct macsec_secy *secy, struct macsec_tx_sa *tx_sa)
{}
EXPORT_SYMBOL_GPL();

static pn_t tx_sa_update_pn(struct macsec_tx_sa *tx_sa,
			    struct macsec_secy *secy)
{}

static void macsec_encrypt_finish(struct sk_buff *skb, struct net_device *dev)
{}

static unsigned int macsec_msdu_len(struct sk_buff *skb)
{}

static void macsec_count_tx(struct sk_buff *skb, struct macsec_tx_sc *tx_sc,
			    struct macsec_tx_sa *tx_sa)
{}

static void count_tx(struct net_device *dev, int ret, int len)
{}

static void macsec_encrypt_done(void *data, int err)
{}

static struct aead_request *macsec_alloc_req(struct crypto_aead *tfm,
					     unsigned char **iv,
					     struct scatterlist **sg,
					     int num_frags)
{}

static struct sk_buff *macsec_encrypt(struct sk_buff *skb,
				      struct net_device *dev)
{}

static bool macsec_post_decrypt(struct sk_buff *skb, struct macsec_secy *secy, u32 pn)
{}

static void macsec_reset_skb(struct sk_buff *skb, struct net_device *dev)
{}

static void macsec_finalize_skb(struct sk_buff *skb, u8 icv_len, u8 hdr_len)
{}

static void count_rx(struct net_device *dev, int len)
{}

static void macsec_decrypt_done(void *data, int err)
{}

static struct sk_buff *macsec_decrypt(struct sk_buff *skb,
				      struct net_device *dev,
				      struct macsec_rx_sa *rx_sa,
				      sci_t sci,
				      struct macsec_secy *secy)
{}

static struct macsec_rx_sc *find_rx_sc(struct macsec_secy *secy, sci_t sci)
{}

static struct macsec_rx_sc *find_rx_sc_rtnl(struct macsec_secy *secy, sci_t sci)
{}

static enum rx_handler_result handle_not_macsec(struct sk_buff *skb)
{}

static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
{}

static struct crypto_aead *macsec_alloc_tfm(char *key, int key_len, int icv_len)
{}

static int init_rx_sa(struct macsec_rx_sa *rx_sa, char *sak, int key_len,
		      int icv_len)
{}

static void clear_rx_sa(struct macsec_rx_sa *rx_sa)
{}

static void free_rx_sc(struct macsec_rx_sc *rx_sc)
{}

static struct macsec_rx_sc *del_rx_sc(struct macsec_secy *secy, sci_t sci)
{}

static struct macsec_rx_sc *create_rx_sc(struct net_device *dev, sci_t sci,
					 bool active)
{}

static int init_tx_sa(struct macsec_tx_sa *tx_sa, char *sak, int key_len,
		      int icv_len)
{}

static void clear_tx_sa(struct macsec_tx_sa *tx_sa)
{}

static struct genl_family macsec_fam;

static struct net_device *get_dev_from_nl(struct net *net,
					  struct nlattr **attrs)
{}

static enum macsec_offload nla_get_offload(const struct nlattr *nla)
{}

static sci_t nla_get_sci(const struct nlattr *nla)
{}

static int nla_put_sci(struct sk_buff *skb, int attrtype, sci_t value,
		       int padattr)
{}

static ssci_t nla_get_ssci(const struct nlattr *nla)
{}

static int nla_put_ssci(struct sk_buff *skb, int attrtype, ssci_t value)
{}

static struct macsec_tx_sa *get_txsa_from_nl(struct net *net,
					     struct nlattr **attrs,
					     struct nlattr **tb_sa,
					     struct net_device **devp,
					     struct macsec_secy **secyp,
					     struct macsec_tx_sc **scp,
					     u8 *assoc_num)
{}

static struct macsec_rx_sc *get_rxsc_from_nl(struct net *net,
					     struct nlattr **attrs,
					     struct nlattr **tb_rxsc,
					     struct net_device **devp,
					     struct macsec_secy **secyp)
{}

static struct macsec_rx_sa *get_rxsa_from_nl(struct net *net,
					     struct nlattr **attrs,
					     struct nlattr **tb_rxsc,
					     struct nlattr **tb_sa,
					     struct net_device **devp,
					     struct macsec_secy **secyp,
					     struct macsec_rx_sc **scp,
					     u8 *assoc_num)
{}

static const struct nla_policy macsec_genl_policy[NUM_MACSEC_ATTR] =;

static const struct nla_policy macsec_genl_rxsc_policy[NUM_MACSEC_RXSC_ATTR] =;

static const struct nla_policy macsec_genl_sa_policy[NUM_MACSEC_SA_ATTR] =;

static const struct nla_policy macsec_genl_offload_policy[NUM_MACSEC_OFFLOAD_ATTR] =;

/* Offloads an operation to a device driver */
static int macsec_offload(int (* const func)(struct macsec_context *),
			  struct macsec_context *ctx)
{}

static int parse_sa_config(struct nlattr **attrs, struct nlattr **tb_sa)
{}

static int parse_rxsc_config(struct nlattr **attrs, struct nlattr **tb_rxsc)
{}

static bool validate_add_rxsa(struct nlattr **attrs)
{}

static int macsec_add_rxsa(struct sk_buff *skb, struct genl_info *info)
{}

static bool validate_add_rxsc(struct nlattr **attrs)
{}

static int macsec_add_rxsc(struct sk_buff *skb, struct genl_info *info)
{}

static bool validate_add_txsa(struct nlattr **attrs)
{}

static int macsec_add_txsa(struct sk_buff *skb, struct genl_info *info)
{}

static int macsec_del_rxsa(struct sk_buff *skb, struct genl_info *info)
{}

static int macsec_del_rxsc(struct sk_buff *skb, struct genl_info *info)
{}

static int macsec_del_txsa(struct sk_buff *skb, struct genl_info *info)
{}

static bool validate_upd_sa(struct nlattr **attrs)
{}

static int macsec_upd_txsa(struct sk_buff *skb, struct genl_info *info)
{}

static int macsec_upd_rxsa(struct sk_buff *skb, struct genl_info *info)
{}

static int macsec_upd_rxsc(struct sk_buff *skb, struct genl_info *info)
{}

static bool macsec_is_configured(struct macsec_dev *macsec)
{}

static bool macsec_needs_tx_tag(struct macsec_dev *macsec,
				const struct macsec_ops *ops)
{}

static void macsec_set_head_tail_room(struct net_device *dev)
{}

static int macsec_update_offload(struct net_device *dev, enum macsec_offload offload)
{}

static int macsec_upd_offload(struct sk_buff *skb, struct genl_info *info)
{}

static void get_tx_sa_stats(struct net_device *dev, int an,
			    struct macsec_tx_sa *tx_sa,
			    struct macsec_tx_sa_stats *sum)
{}

static int copy_tx_sa_stats(struct sk_buff *skb, struct macsec_tx_sa_stats *sum)
{}

static void get_rx_sa_stats(struct net_device *dev,
			    struct macsec_rx_sc *rx_sc, int an,
			    struct macsec_rx_sa *rx_sa,
			    struct macsec_rx_sa_stats *sum)
{}

static int copy_rx_sa_stats(struct sk_buff *skb,
			    struct macsec_rx_sa_stats *sum)
{}

static void get_rx_sc_stats(struct net_device *dev,
			    struct macsec_rx_sc *rx_sc,
			    struct macsec_rx_sc_stats *sum)
{}

static int copy_rx_sc_stats(struct sk_buff *skb, struct macsec_rx_sc_stats *sum)
{}

static void get_tx_sc_stats(struct net_device *dev,
			    struct macsec_tx_sc_stats *sum)
{}

static int copy_tx_sc_stats(struct sk_buff *skb, struct macsec_tx_sc_stats *sum)
{}

static void get_secy_stats(struct net_device *dev, struct macsec_dev_stats *sum)
{}

static int copy_secy_stats(struct sk_buff *skb, struct macsec_dev_stats *sum)
{}

static int nla_put_secy(struct macsec_secy *secy, struct sk_buff *skb)
{}

static noinline_for_stack int
dump_secy(struct macsec_secy *secy, struct net_device *dev,
	  struct sk_buff *skb, struct netlink_callback *cb)
{}

static int macsec_generation =; /* protected by RTNL */

static int macsec_dump_txsc(struct sk_buff *skb, struct netlink_callback *cb)
{}

static const struct genl_small_ops macsec_genl_ops[] =;

static struct genl_family macsec_fam __ro_after_init =;

static struct sk_buff *macsec_insert_tx_tag(struct sk_buff *skb,
					    struct net_device *dev)
{}

static netdev_tx_t macsec_start_xmit(struct sk_buff *skb,
				     struct net_device *dev)
{}

#define MACSEC_FEATURES

static int macsec_dev_init(struct net_device *dev)
{}

static void macsec_dev_uninit(struct net_device *dev)
{}

static netdev_features_t macsec_fix_features(struct net_device *dev,
					     netdev_features_t features)
{}

static int macsec_dev_open(struct net_device *dev)
{}

static int macsec_dev_stop(struct net_device *dev)
{}

static void macsec_dev_change_rx_flags(struct net_device *dev, int change)
{}

static void macsec_dev_set_rx_mode(struct net_device *dev)
{}

static int macsec_set_mac_address(struct net_device *dev, void *p)
{}

static int macsec_change_mtu(struct net_device *dev, int new_mtu)
{}

static void macsec_get_stats64(struct net_device *dev,
			       struct rtnl_link_stats64 *s)
{}

static int macsec_get_iflink(const struct net_device *dev)
{}

static const struct net_device_ops macsec_netdev_ops =;

static const struct device_type macsec_type =;

static const struct nla_policy macsec_rtnl_policy[IFLA_MACSEC_MAX + 1] =;

static void macsec_free_netdev(struct net_device *dev)
{}

static void macsec_setup(struct net_device *dev)
{}

static int macsec_changelink_common(struct net_device *dev,
				    struct nlattr *data[])
{}

static int macsec_changelink(struct net_device *dev, struct nlattr *tb[],
			     struct nlattr *data[],
			     struct netlink_ext_ack *extack)
{}

static void macsec_del_dev(struct macsec_dev *macsec)
{}

static void macsec_common_dellink(struct net_device *dev, struct list_head *head)
{}

static void macsec_dellink(struct net_device *dev, struct list_head *head)
{}

static int register_macsec_dev(struct net_device *real_dev,
			       struct net_device *dev)
{}

static bool sci_exists(struct net_device *dev, sci_t sci)
{}

static sci_t dev_to_sci(struct net_device *dev, __be16 port)
{}

static int macsec_add_dev(struct net_device *dev, sci_t sci, u8 icv_len)
{}

static struct lock_class_key macsec_netdev_addr_lock_key;

static int macsec_newlink(struct net *net, struct net_device *dev,
			  struct nlattr *tb[], struct nlattr *data[],
			  struct netlink_ext_ack *extack)
{}

static int macsec_validate_attr(struct nlattr *tb[], struct nlattr *data[],
				struct netlink_ext_ack *extack)
{}

static struct net *macsec_get_link_net(const struct net_device *dev)
{}

struct net_device *macsec_get_real_dev(const struct net_device *dev)
{}
EXPORT_SYMBOL_GPL();

bool macsec_netdev_is_offloaded(struct net_device *dev)
{}
EXPORT_SYMBOL_GPL();

static size_t macsec_get_size(const struct net_device *dev)
{}

static int macsec_fill_info(struct sk_buff *skb,
			    const struct net_device *dev)
{}

static struct rtnl_link_ops macsec_link_ops __read_mostly =;

static bool is_macsec_master(struct net_device *dev)
{}

static int macsec_notify(struct notifier_block *this, unsigned long event,
			 void *ptr)
{}

static struct notifier_block macsec_notifier =;

static int __init macsec_init(void)
{}

static void __exit macsec_exit(void)
{}

module_init();
module_exit(macsec_exit);

MODULE_ALIAS_RTNL_LINK();
MODULE_ALIAS_GENL_FAMILY();

MODULE_DESCRIPTION();
MODULE_LICENSE();