/
usr
/
src
/
linux-headers-5.15.0-181
/
include
/
net
/
/usr/src/linux-headers-5.15.0-181/include/net
mkdir
upload
Name
Size
Mode
Actions
9p/
-
0755
rm
bluetooth/
-
0755
rm
caif/
-
0755
rm
iucv/
-
0755
rm
netfilter/
-
0755
rm
netns/
-
0755
rm
nfc/
-
0755
rm
phonet/
-
0755
rm
sctp/
-
0755
rm
tc_act/
-
0755
rm
6lowpan.h
10270
0644
edit
dl
rm
act_api.h
8647
0644
edit
dl
rm
addrconf.h
14594
0644
edit
dl
rm
af_ieee802154.h
1220
0644
edit
dl
rm
af_rxrpc.h
2798
0644
edit
dl
rm
af_unix.h
3375
0644
edit
dl
rm
af_vsock.h
7592
0644
edit
dl
rm
ah.h
382
0644
edit
dl
rm
arp.h
2141
0644
edit
dl
rm
atmclip.h
1515
0644
edit
dl
rm
ax25.h
15443
0644
edit
dl
rm
ax88796.h
1440
0644
edit
dl
rm
bareudp.h
572
0644
edit
dl
rm
bonding.h
20263
0644
edit
dl
rm
bond_3ad.h
9706
0644
edit
dl
rm
bond_alb.h
6251
0644
edit
dl
rm
bond_options.h
3876
0644
edit
dl
rm
bpf_sk_storage.h
1780
0644
edit
dl
rm
busy_poll.h
3959
0644
edit
dl
rm
calipso.h
1590
0644
edit
dl
rm
cfg80211-wext.h
1854
0644
edit
dl
rm
cfg80211.h
301317
0644
edit
dl
rm
cfg802154.h
10779
0644
edit
dl
rm
checksum.h
4869
0644
edit
dl
rm
cipso_ipv4.h
7548
0644
edit
dl
rm
cls_cgroup.h
2086
0644
edit
dl
rm
codel.h
5782
0644
edit
dl
rm
codel_impl.h
8167
0644
edit
dl
rm
codel_qdisc.h
2973
0644
edit
dl
rm
compat.h
2586
0644
edit
dl
rm
datalink.h
619
0644
edit
dl
rm
dcbevent.h
742
0644
edit
dl
rm
dcbnl.h
4317
0644
edit
dl
rm
devlink.h
63593
0644
edit
dl
rm
dsa.h
36231
0644
edit
dl
rm
dsfield.h
1147
0644
edit
dl
rm
dst.h
15153
0644
edit
dl
rm
dst_cache.h
3031
0644
edit
dl
rm
dst_metadata.h
5521
0644
edit
dl
rm
dst_ops.h
2125
0644
edit
dl
rm
erspan.h
9180
0644
edit
dl
rm
esp.h
1190
0644
edit
dl
rm
espintcp.h
966
0644
edit
dl
rm
ethoc.h
391
0644
edit
dl
rm
failover.h
1178
0644
edit
dl
rm
fib_notifier.h
1384
0644
edit
dl
rm
fib_rules.h
6450
0644
edit
dl
rm
firewire.h
636
0644
edit
dl
rm
flow.h
5119
0644
edit
dl
rm
flow_dissector.h
10517
0644
edit
dl
rm
flow_offload.h
15938
0644
edit
dl
rm
fou.h
549
0644
edit
dl
rm
fq.h
2528
0644
edit
dl
rm
fq_impl.h
8076
0644
edit
dl
rm
garp.h
2678
0644
edit
dl
rm
genetlink.h
13854
0644
edit
dl
rm
geneve.h
1898
0644
edit
dl
rm
gen_stats.h
2889
0644
edit
dl
rm
gre.h
3369
0644
edit
dl
rm
gro.h
783
0644
edit
dl
rm
gro_cells.h
443
0644
edit
dl
rm
gtp.h
633
0644
edit
dl
rm
gue.h
3313
0644
edit
dl
rm
hwbm.h
969
0644
edit
dl
rm
icmp.h
1918
0644
edit
dl
rm
ieee80211_radiotap.h
13518
0644
edit
dl
rm
ieee802154_netdev.h
10095
0644
edit
dl
rm
ife.h
1057
0644
edit
dl
rm
if_inet6.h
6692
0644
edit
dl
rm
ila.h
291
0644
edit
dl
rm
inet6_connection_sock.h
765
0644
edit
dl
rm
inet6_hashtables.h
4259
0644
edit
dl
rm
inetpeer.h
3372
0644
edit
dl
rm
inet_common.h
2614
0644
edit
dl
rm
inet_connection_sock.h
11519
0644
edit
dl
rm
inet_ecn.h
7625
0644
edit
dl
rm
inet_frag.h
5046
0644
edit
dl
rm
inet_hashtables.h
12532
0644
edit
dl
rm
inet_sock.h
9994
0644
edit
dl
rm
inet_timewait_sock.h
3735
0644
edit
dl
rm
ioam6.h
1199
0644
edit
dl
rm
ip.h
22759
0644
edit
dl
rm
ip6_checksum.h
2770
0644
edit
dl
rm
ip6_fib.h
16280
0644
edit
dl
rm
ip6_route.h
10230
0644
edit
dl
rm
ip6_tunnel.h
5096
0644
edit
dl
rm
ipcomp.h
659
0644
edit
dl
rm
ipconfig.h
811
0644
edit
dl
rm
ipv6.h
36182
0644
edit
dl
rm
ipv6_frag.h
3361
0644
edit
dl
rm
ipv6_stubs.h
3482
0644
edit
dl
rm
ip_fib.h
16346
0644
edit
dl
rm
ip_tunnels.h
15949
0644
edit
dl
rm
ip_vs.h
50588
0644
edit
dl
rm
iw_handler.h
21413
0644
edit
dl
rm
kcm.h
4961
0644
edit
dl
rm
l3mdev.h
7202
0644
edit
dl
rm
lag.h
409
0644
edit
dl
rm
lapb.h
4938
0644
edit
dl
rm
lib80211.h
4017
0644
edit
dl
rm
llc.h
4514
0644
edit
dl
rm
llc_conn.h
4155
0644
edit
dl
rm
llc_c_ac.h
9537
0644
edit
dl
rm
llc_c_ev.h
10940
0644
edit
dl
rm
llc_c_st.h
1762
0644
edit
dl
rm
llc_if.h
2210
0644
edit
dl
rm
llc_pdu.h
14697
0644
edit
dl
rm
llc_sap.h
1108
0644
edit
dl
rm
llc_s_ac.h
1591
0644
edit
dl
rm
llc_s_ev.h
2255
0644
edit
dl
rm
llc_s_st.h
947
0644
edit
dl
rm
lwtunnel.h
6806
0644
edit
dl
rm
mac80211.h
273972
0644
edit
dl
rm
mac802154.h
15235
0644
edit
dl
rm
macsec.h
7084
0644
edit
dl
rm
mctp.h
6155
0644
edit
dl
rm
mctpdevice.h
841
0644
edit
dl
rm
mip6.h
1016
0644
edit
dl
rm
mld.h
2918
0644
edit
dl
rm
mpls.h
943
0644
edit
dl
rm
mpls_iptunnel.h
429
0644
edit
dl
rm
mptcp.h
6776
0644
edit
dl
rm
mrp.h
3119
0644
edit
dl
rm
ncsi.h
1964
0644
edit
dl
rm
ndisc.h
15150
0644
edit
dl
rm
neighbour.h
16099
0644
edit
dl
rm
netevent.h
1044
0644
edit
dl
rm
netlabel.h
20676
0644
edit
dl
rm
netlink.h
61656
0644
edit
dl
rm
netprio_cgroup.h
1047
0644
edit
dl
rm
netrom.h
7895
0644
edit
dl
rm
net_failover.h
1023
0644
edit
dl
rm
net_namespace.h
12795
0644
edit
dl
rm
net_ratelimit.h
220
0644
edit
dl
rm
nexthop.h
12565
0644
edit
dl
rm
nl802154.h
12384
0644
edit
dl
rm
nsh.h
12602
0644
edit
dl
rm
p8022.h
447
0644
edit
dl
rm
page_pool.h
8646
0644
edit
dl
rm
pie.h
3684
0644
edit
dl
rm
ping.h
2970
0644
edit
dl
rm
pkt_cls.h
24431
0644
edit
dl
rm
pkt_sched.h
6042
0644
edit
dl
rm
pptp.h
557
0644
edit
dl
rm
protocol.h
3900
0644
edit
dl
rm
psample.h
1083
0644
edit
dl
rm
psnap.h
351
0644
edit
dl
rm
raw.h
2136
0644
edit
dl
rm
rawv6.h
854
0644
edit
dl
rm
red.h
11654
0644
edit
dl
rm
regulatory.h
10901
0644
edit
dl
rm
request_sock.h
6660
0644
edit
dl
rm
rose.h
7802
0644
edit
dl
rm
route.h
11582
0644
edit
dl
rm
rpl.h
839
0644
edit
dl
rm
rsi_91x.h
1710
0644
edit
dl
rm
rtnetlink.h
7638
0644
edit
dl
rm
rtnh.h
859
0644
edit
dl
rm
sch_generic.h
34720
0644
edit
dl
rm
scm.h
3877
0644
edit
dl
rm
secure_seq.h
855
0644
edit
dl
rm
seg6.h
2237
0644
edit
dl
rm
seg6_hmac.h
1473
0644
edit
dl
rm
seg6_local.h
644
0644
edit
dl
rm
selftests.h
582
0644
edit
dl
rm
slhc_vj.h
6831
0644
edit
dl
rm
smc.h
2513
0644
edit
dl
rm
snmp.h
5268
0644
edit
dl
rm
sock.h
86351
0644
edit
dl
rm
sock_reuseport.h
1873
0644
edit
dl
rm
Space.h
737
0644
edit
dl
rm
stp.h
383
0644
edit
dl
rm
strparser.h
4250
0644
edit
dl
rm
switchdev.h
14614
0644
edit
dl
rm
tcp.h
75246
0644
edit
dl
rm
tcp_states.h
1225
0644
edit
dl
rm
timewait_sock.h
925
0644
edit
dl
rm
tipc.h
2405
0644
edit
dl
rm
tls.h
21465
0644
edit
dl
rm
tls_toe.h
3006
0644
edit
dl
rm
transp_v6.h
1996
0644
edit
dl
rm
tso.h
566
0644
edit
dl
rm
tun_proto.h
988
0644
edit
dl
rm
udp.h
17035
0644
edit
dl
rm
udplite.h
3762
0644
edit
dl
rm
udp_tunnel.h
12201
0644
edit
dl
rm
vsock_addr.h
662
0644
edit
dl
rm
vxlan.h
14424
0644
edit
dl
rm
wext.h
1510
0644
edit
dl
rm
x25.h
9718
0644
edit
dl
rm
x25device.h
387
0644
edit
dl
rm
xdp.h
8829
0644
edit
dl
rm
xdp_priv.h
446
0644
edit
dl
rm
xdp_sock.h
2094
0644
edit
dl
rm
xdp_sock_drv.h
5607
0644
edit
dl
rm
xfrm.h
56304
0644
edit
dl
rm
xsk_buff_pool.h
5138
0644
edit
dl
rm
Edit:
/usr/src/linux-headers-5.15.0-181/include/net/tls.h
(21465B)
/* * Copyright (c) 2016-2017, Mellanox Technologies. All rights reserved. * Copyright (c) 2016-2017, Dave Watson <davejwatson@fb.com>. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU * General Public License (GPL) Version 2, available from the file * COPYING in the main directory of this source tree, or the * OpenIB.org BSD license below: * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * * - Redistributions of source code must retain the above * copyright notice, this list of conditions and the following * disclaimer. * * - Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #ifndef _TLS_OFFLOAD_H #define _TLS_OFFLOAD_H #include <linux/types.h> #include <asm/byteorder.h> #include <linux/crypto.h> #include <linux/socket.h> #include <linux/tcp.h> #include <linux/skmsg.h> #include <linux/mutex.h> #include <linux/netdevice.h> #include <linux/rcupdate.h> #include <net/net_namespace.h> #include <net/tcp.h> #include <net/strparser.h> #include <crypto/aead.h> #include <uapi/linux/tls.h> /* Maximum data size carried in a TLS record */ #define TLS_MAX_PAYLOAD_SIZE ((size_t)1 << 14) #define TLS_HEADER_SIZE 5 #define TLS_NONCE_OFFSET TLS_HEADER_SIZE #define TLS_CRYPTO_INFO_READY(info) ((info)->cipher_type) #define TLS_RECORD_TYPE_DATA 0x17 #define TLS_AAD_SPACE_SIZE 13 #define MAX_IV_SIZE 16 #define TLS_MAX_REC_SEQ_SIZE 8 /* For AES-CCM, the full 16-bytes of IV is made of '4' fields of given sizes. * * IV[16] = b0[1] || implicit nonce[4] || explicit nonce[8] || length[3] * * The field 'length' is encoded in field 'b0' as '(length width - 1)'. * Hence b0 contains (3 - 1) = 2. */ #define TLS_AES_CCM_IV_B0_BYTE 2 #define __TLS_INC_STATS(net, field) \ __SNMP_INC_STATS((net)->mib.tls_statistics, field) #define TLS_INC_STATS(net, field) \ SNMP_INC_STATS((net)->mib.tls_statistics, field) #define TLS_DEC_STATS(net, field) \ SNMP_DEC_STATS((net)->mib.tls_statistics, field) enum { TLS_BASE, TLS_SW, TLS_HW, TLS_HW_RECORD, TLS_NUM_CONFIG, }; /* TLS records are maintained in 'struct tls_rec'. It stores the memory pages * allocated or mapped for each TLS record. After encryption, the records are * stores in a linked list. */ struct tls_rec { struct list_head list; int tx_ready; int tx_flags; struct sk_msg msg_plaintext; struct sk_msg msg_encrypted; /* AAD | msg_plaintext.sg.data | sg_tag */ struct scatterlist sg_aead_in[2]; /* AAD | msg_encrypted.sg.data (data contains overhead for hdr & iv & tag) */ struct scatterlist sg_aead_out[2]; char content_type; struct scatterlist sg_content_type; char aad_space[TLS_AAD_SPACE_SIZE]; u8 iv_data[MAX_IV_SIZE]; struct aead_request aead_req; u8 aead_req_ctx[]; }; struct tx_work { struct delayed_work work; struct sock *sk; }; struct tls_sw_context_tx { struct crypto_aead *aead_send; struct crypto_wait async_wait; struct tx_work tx_work; struct tls_rec *open_rec; struct list_head tx_list; atomic_t encrypt_pending; u8 async_capable:1; #define BIT_TX_SCHEDULED 0 #define BIT_TX_CLOSING 1 unsigned long tx_bitmask; }; struct tls_sw_context_rx { struct crypto_aead *aead_recv; struct crypto_wait async_wait; struct strparser strp; struct sk_buff_head rx_list; /* list of decrypted 'data' records */ void (*saved_data_ready)(struct sock *sk); struct sk_buff *recv_pkt; u8 reader_present; u8 async_capable:1; u8 reader_contended:1; atomic_t decrypt_pending; struct wait_queue_head wq; }; struct tls_record_info { struct list_head list; u32 end_seq; int len; int num_frags; skb_frag_t frags[MAX_SKB_FRAGS]; }; struct tls_offload_context_tx { struct crypto_aead *aead_send; spinlock_t lock; /* protects records list */ struct list_head records_list; struct tls_record_info *open_record; struct tls_record_info *retransmit_hint; u64 hint_record_sn; u64 unacked_record_sn; struct scatterlist sg_tx_data[MAX_SKB_FRAGS]; void (*sk_destruct)(struct sock *sk); struct work_struct destruct_work; struct tls_context *ctx; u8 driver_state[] __aligned(8); /* The TLS layer reserves room for driver specific state * Currently the belief is that there is not enough * driver specific state to justify another layer of indirection */ #define TLS_DRIVER_STATE_SIZE_TX 16 }; #define TLS_OFFLOAD_CONTEXT_SIZE_TX \ (sizeof(struct tls_offload_context_tx) + TLS_DRIVER_STATE_SIZE_TX) enum tls_context_flags { /* tls_device_down was called after the netdev went down, device state * was released, and kTLS works in software, even though rx_conf is * still TLS_HW (needed for transition). */ TLS_RX_DEV_DEGRADED = 0, /* Unlike RX where resync is driven entirely by the core in TX only * the driver knows when things went out of sync, so we need the flag * to be atomic. */ TLS_TX_SYNC_SCHED = 1, /* tls_dev_del was called for the RX side, device state was released, * but tls_ctx->netdev might still be kept, because TX-side driver * resources might not be released yet. Used to prevent the second * tls_dev_del call in tls_device_down if it happens simultaneously. */ TLS_RX_DEV_CLOSED = 2, }; struct cipher_context { char *iv; char *rec_seq; }; union tls_crypto_context { struct tls_crypto_info info; union { struct tls12_crypto_info_aes_gcm_128 aes_gcm_128; struct tls12_crypto_info_aes_gcm_256 aes_gcm_256; struct tls12_crypto_info_chacha20_poly1305 chacha20_poly1305; }; }; struct tls_prot_info { u16 version; u16 cipher_type; u16 prepend_size; u16 tag_size; u16 overhead_size; u16 iv_size; u16 salt_size; u16 rec_seq_size; u16 aad_size; u16 tail_size; }; struct tls_context { /* read-only cache line */ struct tls_prot_info prot_info; u8 tx_conf:3; u8 rx_conf:3; int (*push_pending_record)(struct sock *sk, int flags); void (*sk_write_space)(struct sock *sk); void *priv_ctx_tx; void *priv_ctx_rx; struct net_device *netdev; /* rw cache line */ struct cipher_context tx; struct cipher_context rx; struct scatterlist *partially_sent_record; u16 partially_sent_offset; bool in_tcp_sendpages; bool pending_open_record_frags; struct mutex tx_lock; /* protects partially_sent_* fields and * per-type TX fields */ unsigned long flags; /* cache cold stuff */ struct proto *sk_proto; struct sock *sk; void (*sk_destruct)(struct sock *sk); union tls_crypto_context crypto_send; union tls_crypto_context crypto_recv; struct list_head list; refcount_t refcount; struct rcu_head rcu; }; enum tls_offload_ctx_dir { TLS_OFFLOAD_CTX_DIR_RX, TLS_OFFLOAD_CTX_DIR_TX, }; struct tlsdev_ops { int (*tls_dev_add)(struct net_device *netdev, struct sock *sk, enum tls_offload_ctx_dir direction, struct tls_crypto_info *crypto_info, u32 start_offload_tcp_sn); void (*tls_dev_del)(struct net_device *netdev, struct tls_context *ctx, enum tls_offload_ctx_dir direction); int (*tls_dev_resync)(struct net_device *netdev, struct sock *sk, u32 seq, u8 *rcd_sn, enum tls_offload_ctx_dir direction); }; enum tls_offload_sync_type { TLS_OFFLOAD_SYNC_TYPE_DRIVER_REQ = 0, TLS_OFFLOAD_SYNC_TYPE_CORE_NEXT_HINT = 1, TLS_OFFLOAD_SYNC_TYPE_DRIVER_REQ_ASYNC = 2, }; #define TLS_DEVICE_RESYNC_NH_START_IVAL 2 #define TLS_DEVICE_RESYNC_NH_MAX_IVAL 128 #define TLS_DEVICE_RESYNC_ASYNC_LOGMAX 13 struct tls_offload_resync_async { atomic64_t req; u16 loglen; u16 rcd_delta; u32 log[TLS_DEVICE_RESYNC_ASYNC_LOGMAX]; }; struct tls_offload_context_rx { /* sw must be the first member of tls_offload_context_rx */ struct tls_sw_context_rx sw; enum tls_offload_sync_type resync_type; /* this member is set regardless of resync_type, to avoid branches */ u8 resync_nh_reset:1; /* CORE_NEXT_HINT-only member, but use the hole here */ u8 resync_nh_do_now:1; union { /* TLS_OFFLOAD_SYNC_TYPE_DRIVER_REQ */ struct { atomic64_t resync_req; }; /* TLS_OFFLOAD_SYNC_TYPE_CORE_NEXT_HINT */ struct { u32 decrypted_failed; u32 decrypted_tgt; } resync_nh; /* TLS_OFFLOAD_SYNC_TYPE_DRIVER_REQ_ASYNC */ struct { struct tls_offload_resync_async *resync_async; }; }; u8 driver_state[] __aligned(8); /* The TLS layer reserves room for driver specific state * Currently the belief is that there is not enough * driver specific state to justify another layer of indirection */ #define TLS_DRIVER_STATE_SIZE_RX 8 }; #define TLS_OFFLOAD_CONTEXT_SIZE_RX \ (sizeof(struct tls_offload_context_rx) + TLS_DRIVER_STATE_SIZE_RX) struct tls_context *tls_ctx_create(struct sock *sk); void tls_ctx_free(struct sock *sk, struct tls_context *ctx); void update_sk_prot(struct sock *sk, struct tls_context *ctx); int wait_on_pending_writer(struct sock *sk, long *timeo); int tls_sk_query(struct sock *sk, int optname, char __user *optval, int __user *optlen); int tls_sk_attach(struct sock *sk, int optname, char __user *optval, unsigned int optlen); void tls_err_abort(struct sock *sk, int err); int tls_set_sw_offload(struct sock *sk, struct tls_context *ctx, int tx); void tls_sw_strparser_arm(struct sock *sk, struct tls_context *ctx); void tls_sw_strparser_done(struct tls_context *tls_ctx); int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size); int tls_sw_sendpage_locked(struct sock *sk, struct page *page, int offset, size_t size, int flags); int tls_sw_sendpage(struct sock *sk, struct page *page, int offset, size_t size, int flags); void tls_sw_cancel_work_tx(struct tls_context *tls_ctx); void tls_sw_release_resources_tx(struct sock *sk); void tls_sw_free_ctx_tx(struct tls_context *tls_ctx); void tls_sw_free_resources_rx(struct sock *sk); void tls_sw_release_resources_rx(struct sock *sk); void tls_sw_free_ctx_rx(struct tls_context *tls_ctx); int tls_sw_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonblock, int flags, int *addr_len); bool tls_sw_sock_is_readable(struct sock *sk); ssize_t tls_sw_splice_read(struct socket *sock, loff_t *ppos, struct pipe_inode_info *pipe, size_t len, unsigned int flags); int tls_device_sendmsg(struct sock *sk, struct msghdr *msg, size_t size); int tls_device_sendpage(struct sock *sk, struct page *page, int offset, size_t size, int flags); int tls_tx_records(struct sock *sk, int flags); struct tls_record_info *tls_get_record(struct tls_offload_context_tx *context, u32 seq, u64 *p_record_sn); static inline bool tls_record_is_start_marker(struct tls_record_info *rec) { return rec->len == 0; } static inline u32 tls_record_start_seq(struct tls_record_info *rec) { return rec->end_seq - rec->len; } int tls_push_sg(struct sock *sk, struct tls_context *ctx, struct scatterlist *sg, u16 first_offset, int flags); int tls_push_partial_record(struct sock *sk, struct tls_context *ctx, int flags); void tls_free_partial_record(struct sock *sk, struct tls_context *ctx); static inline struct tls_msg *tls_msg(struct sk_buff *skb) { struct sk_skb_cb *scb = (struct sk_skb_cb *)skb->cb; return &scb->tls; } static inline bool tls_is_partially_sent_record(struct tls_context *ctx) { return !!ctx->partially_sent_record; } static inline bool tls_is_pending_open_record(struct tls_context *tls_ctx) { return tls_ctx->pending_open_record_frags; } static inline bool is_tx_ready(struct tls_sw_context_tx *ctx) { struct tls_rec *rec; rec = list_first_entry_or_null(&ctx->tx_list, struct tls_rec, list); if (!rec) return false; return READ_ONCE(rec->tx_ready); } static inline u16 tls_user_config(struct tls_context *ctx, bool tx) { u16 config = tx ? ctx->tx_conf : ctx->rx_conf; switch (config) { case TLS_BASE: return TLS_CONF_BASE; case TLS_SW: return TLS_CONF_SW; case TLS_HW: return TLS_CONF_HW; case TLS_HW_RECORD: return TLS_CONF_HW_RECORD; } return 0; } struct sk_buff * tls_validate_xmit_skb(struct sock *sk, struct net_device *dev, struct sk_buff *skb); struct sk_buff * tls_validate_xmit_skb_sw(struct sock *sk, struct net_device *dev, struct sk_buff *skb); static inline bool tls_is_sk_tx_device_offloaded(struct sock *sk) { #ifdef CONFIG_SOCK_VALIDATE_XMIT return sk_fullsock(sk) && (smp_load_acquire(&sk->sk_validate_xmit_skb) == &tls_validate_xmit_skb); #else return false; #endif } static inline bool tls_bigint_increment(unsigned char *seq, int len) { int i; for (i = len - 1; i >= 0; i--) { ++seq[i]; if (seq[i] != 0) break; } return (i == -1); } static inline void tls_bigint_subtract(unsigned char *seq, int n) { u64 rcd_sn; __be64 *p; BUILD_BUG_ON(TLS_MAX_REC_SEQ_SIZE != 8); p = (__be64 *)seq; rcd_sn = be64_to_cpu(*p); *p = cpu_to_be64(rcd_sn - n); } static inline struct tls_context *tls_get_ctx(const struct sock *sk) { struct inet_connection_sock *icsk = inet_csk(sk); /* Use RCU on icsk_ulp_data only for sock diag code, * TLS data path doesn't need rcu_dereference(). */ return (__force void *)icsk->icsk_ulp_data; } static inline void tls_advance_record_sn(struct sock *sk, struct tls_prot_info *prot, struct cipher_context *ctx) { if (tls_bigint_increment(ctx->rec_seq, prot->rec_seq_size)) tls_err_abort(sk, -EBADMSG); if (prot->version != TLS_1_3_VERSION && prot->cipher_type != TLS_CIPHER_CHACHA20_POLY1305) tls_bigint_increment(ctx->iv + prot->salt_size, prot->iv_size); } static inline void tls_fill_prepend(struct tls_context *ctx, char *buf, size_t plaintext_len, unsigned char record_type) { struct tls_prot_info *prot = &ctx->prot_info; size_t pkt_len, iv_size = prot->iv_size; pkt_len = plaintext_len + prot->tag_size; if (prot->version != TLS_1_3_VERSION && prot->cipher_type != TLS_CIPHER_CHACHA20_POLY1305) { pkt_len += iv_size; memcpy(buf + TLS_NONCE_OFFSET, ctx->tx.iv + prot->salt_size, iv_size); } /* we cover nonce explicit here as well, so buf should be of * size KTLS_DTLS_HEADER_SIZE + KTLS_DTLS_NONCE_EXPLICIT_SIZE */ buf[0] = prot->version == TLS_1_3_VERSION ? TLS_RECORD_TYPE_DATA : record_type; /* Note that VERSION must be TLS_1_2 for both TLS1.2 and TLS1.3 */ buf[1] = TLS_1_2_VERSION_MINOR; buf[2] = TLS_1_2_VERSION_MAJOR; /* we can use IV for nonce explicit according to spec */ buf[3] = pkt_len >> 8; buf[4] = pkt_len & 0xFF; } static inline void tls_make_aad(char *buf, size_t size, char *record_sequence, unsigned char record_type, struct tls_prot_info *prot) { if (prot->version != TLS_1_3_VERSION) { memcpy(buf, record_sequence, prot->rec_seq_size); buf += 8; } else { size += prot->tag_size; } buf[0] = prot->version == TLS_1_3_VERSION ? TLS_RECORD_TYPE_DATA : record_type; buf[1] = TLS_1_2_VERSION_MAJOR; buf[2] = TLS_1_2_VERSION_MINOR; buf[3] = size >> 8; buf[4] = size & 0xFF; } static inline void xor_iv_with_seq(struct tls_prot_info *prot, char *iv, char *seq) { int i; if (prot->version == TLS_1_3_VERSION || prot->cipher_type == TLS_CIPHER_CHACHA20_POLY1305) { for (i = 0; i < 8; i++) iv[i + 4] ^= seq[i]; } } static inline struct tls_sw_context_rx *tls_sw_ctx_rx( const struct tls_context *tls_ctx) { return (struct tls_sw_context_rx *)tls_ctx->priv_ctx_rx; } static inline struct tls_sw_context_tx *tls_sw_ctx_tx( const struct tls_context *tls_ctx) { return (struct tls_sw_context_tx *)tls_ctx->priv_ctx_tx; } static inline struct tls_offload_context_tx * tls_offload_ctx_tx(const struct tls_context *tls_ctx) { return (struct tls_offload_context_tx *)tls_ctx->priv_ctx_tx; } static inline bool tls_sw_has_ctx_tx(const struct sock *sk) { struct tls_context *ctx = tls_get_ctx(sk); if (!ctx) return false; return !!tls_sw_ctx_tx(ctx); } static inline bool tls_sw_has_ctx_rx(const struct sock *sk) { struct tls_context *ctx = tls_get_ctx(sk); if (!ctx) return false; return !!tls_sw_ctx_rx(ctx); } void tls_sw_write_space(struct sock *sk, struct tls_context *ctx); void tls_device_write_space(struct sock *sk, struct tls_context *ctx); static inline struct tls_offload_context_rx * tls_offload_ctx_rx(const struct tls_context *tls_ctx) { return (struct tls_offload_context_rx *)tls_ctx->priv_ctx_rx; } #if IS_ENABLED(CONFIG_TLS_DEVICE) static inline void *__tls_driver_ctx(struct tls_context *tls_ctx, enum tls_offload_ctx_dir direction) { if (direction == TLS_OFFLOAD_CTX_DIR_TX) return tls_offload_ctx_tx(tls_ctx)->driver_state; else return tls_offload_ctx_rx(tls_ctx)->driver_state; } static inline void * tls_driver_ctx(const struct sock *sk, enum tls_offload_ctx_dir direction) { return __tls_driver_ctx(tls_get_ctx(sk), direction); } #endif #define RESYNC_REQ BIT(0) #define RESYNC_REQ_ASYNC BIT(1) /* The TLS context is valid until sk_destruct is called */ static inline void tls_offload_rx_resync_request(struct sock *sk, __be32 seq) { struct tls_context *tls_ctx = tls_get_ctx(sk); struct tls_offload_context_rx *rx_ctx = tls_offload_ctx_rx(tls_ctx); atomic64_set(&rx_ctx->resync_req, ((u64)ntohl(seq) << 32) | RESYNC_REQ); } /* Log all TLS record header TCP sequences in [seq, seq+len] */ static inline void tls_offload_rx_resync_async_request_start(struct sock *sk, __be32 seq, u16 len) { struct tls_context *tls_ctx = tls_get_ctx(sk); struct tls_offload_context_rx *rx_ctx = tls_offload_ctx_rx(tls_ctx); atomic64_set(&rx_ctx->resync_async->req, ((u64)ntohl(seq) << 32) | ((u64)len << 16) | RESYNC_REQ | RESYNC_REQ_ASYNC); rx_ctx->resync_async->loglen = 0; rx_ctx->resync_async->rcd_delta = 0; } static inline void tls_offload_rx_resync_async_request_end(struct sock *sk, __be32 seq) { struct tls_context *tls_ctx = tls_get_ctx(sk); struct tls_offload_context_rx *rx_ctx = tls_offload_ctx_rx(tls_ctx); atomic64_set(&rx_ctx->resync_async->req, ((u64)ntohl(seq) << 32) | RESYNC_REQ); } static inline void tls_offload_rx_resync_async_request_cancel(struct tls_offload_resync_async *resync_async) { atomic64_set(&resync_async->req, 0); } static inline void tls_offload_rx_resync_set_type(struct sock *sk, enum tls_offload_sync_type type) { struct tls_context *tls_ctx = tls_get_ctx(sk); tls_offload_ctx_rx(tls_ctx)->resync_type = type; } /* Driver's seq tracking has to be disabled until resync succeeded */ static inline bool tls_offload_tx_resync_pending(struct sock *sk) { struct tls_context *tls_ctx = tls_get_ctx(sk); bool ret; ret = test_bit(TLS_TX_SYNC_SCHED, &tls_ctx->flags); smp_mb__after_atomic(); return ret; } int __net_init tls_proc_init(struct net *net); void __net_exit tls_proc_fini(struct net *net); int tls_proccess_cmsg(struct sock *sk, struct msghdr *msg, unsigned char *record_type); int decrypt_skb(struct sock *sk, struct sk_buff *skb, struct scatterlist *sgout); struct sk_buff *tls_encrypt_skb(struct sk_buff *skb); int tls_sw_fallback_init(struct sock *sk, struct tls_offload_context_tx *offload_ctx, struct tls_crypto_info *crypto_info); #ifdef CONFIG_TLS_DEVICE int tls_device_init(void); void tls_device_cleanup(void); void tls_device_sk_destruct(struct sock *sk); int tls_set_device_offload(struct sock *sk, struct tls_context *ctx); void tls_device_free_resources_tx(struct sock *sk); int tls_set_device_offload_rx(struct sock *sk, struct tls_context *ctx); void tls_device_offload_cleanup_rx(struct sock *sk); void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq); void tls_offload_tx_resync_request(struct sock *sk, u32 got_seq, u32 exp_seq); int tls_device_decrypted(struct sock *sk, struct tls_context *tls_ctx, struct sk_buff *skb, struct strp_msg *rxm); static inline bool tls_is_sk_rx_device_offloaded(struct sock *sk) { if (!sk_fullsock(sk) || smp_load_acquire(&sk->sk_destruct) != tls_device_sk_destruct) return false; return tls_get_ctx(sk)->rx_conf == TLS_HW; } #else static inline int tls_device_init(void) { return 0; } static inline void tls_device_cleanup(void) {} static inline int tls_set_device_offload(struct sock *sk, struct tls_context *ctx) { return -EOPNOTSUPP; } static inline void tls_device_free_resources_tx(struct sock *sk) {} static inline int tls_set_device_offload_rx(struct sock *sk, struct tls_context *ctx) { return -EOPNOTSUPP; } static inline void tls_device_offload_cleanup_rx(struct sock *sk) {} static inline void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq) {} static inline int tls_device_decrypted(struct sock *sk, struct tls_context *tls_ctx, struct sk_buff *skb, struct strp_msg *rxm) { return 0; } #endif #endif /* _TLS_OFFLOAD_H */
Save
cmd:
run