1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 3 #ifndef __PSP_PSP_H 4 #define __PSP_PSP_H 5 6 #include <linux/list.h> 7 #include <linux/lockdep.h> 8 #include <linux/mutex.h> 9 #include <net/netns/generic.h> 10 #include <net/psp.h> 11 #include <net/sock.h> 12 13 extern struct xarray psp_devs; 14 extern struct mutex psp_devs_lock; 15 16 void psp_dev_free(struct psp_dev *psd); 17 int psp_dev_check_access(struct psp_dev *psd, struct net *net); 18 19 void psp_nl_notify_dev(struct psp_dev *psd, u32 cmd); 20 21 struct psp_assoc *psp_assoc_create(struct psp_dev *psd); 22 struct psp_dev *psp_dev_get_for_sock(struct sock *sk); 23 void psp_dev_tx_key_del(struct psp_dev *psd, struct psp_assoc *pas); 24 int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas, 25 struct psp_key_parsed *key, 26 struct netlink_ext_ack *extack); 27 int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd, 28 u32 version, struct psp_key_parsed *key, 29 struct netlink_ext_ack *extack); 30 void psp_assocs_key_rotated(struct psp_dev *psd); 31 32 static inline void psp_dev_get(struct psp_dev *psd) 33 { 34 refcount_inc(&psd->refcnt); 35 } 36 37 static inline bool psp_dev_tryget(struct psp_dev *psd) 38 { 39 return refcount_inc_not_zero(&psd->refcnt); 40 } 41 42 static inline void psp_dev_put(struct psp_dev *psd) 43 { 44 if (refcount_dec_and_test(&psd->refcnt)) 45 psp_dev_free(psd); 46 } 47 48 static inline bool psp_dev_is_registered(struct psp_dev *psd) 49 { 50 lockdep_assert_held(&psd->lock); 51 return !!psd->ops; 52 } 53 54 #endif /* __PSP_PSP_H */ 55