123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
#ifndef __NET_PSP_H
#define __NET_PSP_H
#include <linux/mutex.h>
#include <linux/refcount.h>
#include <net/net_trackers.h>
struct netlink_ext_ack;
#define PSP_DEFAULT_UDP_PORT 1000
struct psphdr {
u8 nexthdr;
u8 hdrlen;
u8 crypt_offset;
u8 verfl;
__be32 spi;
__be64 iv;
__be64 vc[];
};
#define PSP_ENCAP_HLEN (sizeof(struct udphdr) + sizeof(struct psphdr))
#define PSP_SPI_KEY_ID GENMASK(30, 0)
#define PSP_SPI_KEY_PHASE BIT(31)
#define PSPHDR_CRYPT_OFFSET GENMASK(5, 0)
#define PSPHDR_VERFL_SAMPLE BIT(7)
#define PSPHDR_VERFL_DROP BIT(6)
#define PSPHDR_VERFL_VERSION GENMASK(5, 2)
#define PSPHDR_VERFL_VIRT BIT(1)
#define PSPHDR_VERFL_ONE BIT(0)
#define PSP_HDRLEN_NOOPT ((sizeof(struct psphdr) - 8) / 8)
struct psp_dev_config {
u32 versions;
};
#define PSP_ASSOC_DEV_MAX 128
struct psp_assoc_dev {
struct list_head dev_list;
struct net_device *assoc_dev;
netdevice_tracker dev_tracker;
};
struct psp_dev {
struct net_device *main_netdev;
struct list_head assoc_dev_list;
int assoc_dev_cnt;
struct psp_dev_ops *ops;
struct psp_dev_caps *caps;
void *drv_priv;
struct mutex lock;
refcount_t refcnt;
u32 id;
u8 generation;
struct psp_dev_config config;
struct list_head active_assocs;
struct list_head prev_assocs;
struct list_head stale_assocs;
struct {
unsigned long rotations;
unsigned long stales;
} stats;
struct rcu_head rcu;
};
#define PSP_GEN_VALID_MASK 0x7f
struct psp_dev_caps {
u32 versions;
u32 assoc_drv_spc;
};
#define PSP_MAX_KEY 32
#define PSP_HDR_SIZE 16 /* We don't support optional fields, yet */
#define PSP_TRL_SIZE 16 /* AES-GCM/GMAC trailer size */
struct psp_skb_ext {
__be32 spi;
u16 dev_id;
u8 generation;
u8 version;
};
struct psp_key_parsed {
__be32 spi;
u8 key[PSP_MAX_KEY];
};
struct psp_assoc {
struct psp_dev *psd;
u16 dev_id;
u8 generation;
u8 version;
u8 peer_tx;
u32 upgrade_seq;
struct psp_key_parsed tx;
struct psp_key_parsed rx;
refcount_t refcnt;
struct rcu_head rcu;
struct work_struct work;
struct list_head assocs_list;
u8 drv_data[] __aligned(8);
};
struct psp_dev_stats {
union {
struct {
u64 rx_packets;
u64 rx_bytes;
u64 rx_auth_fail;
u64 rx_error;
u64 rx_bad;
u64 tx_packets;
u64 tx_bytes;
u64 tx_error;
};
DECLARE_FLEX_ARRAY(u64, required);
};
};
struct psp_dev_ops {
int (*set_config)(struct psp_dev *psd, struct psp_dev_config *conf,
struct netlink_ext_ack *extack);
int (*key_rotate)(struct psp_dev *psd, struct netlink_ext_ack *extack);
int (*rx_spi_alloc)(struct psp_dev *psd, u32 version,
struct psp_key_parsed *assoc,
struct netlink_ext_ack *extack);
int (*tx_key_add)(struct psp_dev *psd, struct psp_assoc *pas,
struct netlink_ext_ack *extack);
void (*tx_key_del)(struct psp_dev *psd, struct psp_assoc *pas);
void (*get_stats)(struct psp_dev *psd, struct psp_dev_stats *stats);
};
#endif /* __NET_PSP_H */