|
| 1 | +/* |
| 2 | + * Kernel Connection Multiplexor |
| 3 | + * |
| 4 | + * Copyright (c) 2016 Tom Herbert <[email protected]> |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License version 2 |
| 8 | + * as published by the Free Software Foundation. |
| 9 | + */ |
| 10 | + |
| 11 | +#ifndef __NET_KCM_H_ |
| 12 | +#define __NET_KCM_H_ |
| 13 | + |
| 14 | +#include <linux/skbuff.h> |
| 15 | +#include <net/sock.h> |
| 16 | +#include <uapi/linux/kcm.h> |
| 17 | + |
| 18 | +extern unsigned int kcm_net_id; |
| 19 | + |
| 20 | +struct kcm_tx_msg { |
| 21 | + unsigned int sent; |
| 22 | + unsigned int fragidx; |
| 23 | + unsigned int frag_offset; |
| 24 | + unsigned int msg_flags; |
| 25 | + struct sk_buff *frag_skb; |
| 26 | + struct sk_buff *last_skb; |
| 27 | +}; |
| 28 | + |
| 29 | +struct kcm_rx_msg { |
| 30 | + int full_len; |
| 31 | + int accum_len; |
| 32 | + int offset; |
| 33 | +}; |
| 34 | + |
| 35 | +/* Socket structure for KCM client sockets */ |
| 36 | +struct kcm_sock { |
| 37 | + struct sock sk; |
| 38 | + struct kcm_mux *mux; |
| 39 | + struct list_head kcm_sock_list; |
| 40 | + int index; |
| 41 | + u32 done : 1; |
| 42 | + struct work_struct done_work; |
| 43 | + |
| 44 | + /* Transmit */ |
| 45 | + struct kcm_psock *tx_psock; |
| 46 | + struct work_struct tx_work; |
| 47 | + struct list_head wait_psock_list; |
| 48 | + struct sk_buff *seq_skb; |
| 49 | + |
| 50 | + /* Don't use bit fields here, these are set under different locks */ |
| 51 | + bool tx_wait; |
| 52 | + bool tx_wait_more; |
| 53 | + |
| 54 | + /* Receive */ |
| 55 | + struct kcm_psock *rx_psock; |
| 56 | + struct list_head wait_rx_list; /* KCMs waiting for receiving */ |
| 57 | + bool rx_wait; |
| 58 | + u32 rx_disabled : 1; |
| 59 | +}; |
| 60 | + |
| 61 | +struct bpf_prog; |
| 62 | + |
| 63 | +/* Structure for an attached lower socket */ |
| 64 | +struct kcm_psock { |
| 65 | + struct sock *sk; |
| 66 | + struct kcm_mux *mux; |
| 67 | + int index; |
| 68 | + |
| 69 | + u32 tx_stopped : 1; |
| 70 | + u32 rx_stopped : 1; |
| 71 | + u32 done : 1; |
| 72 | + u32 unattaching : 1; |
| 73 | + |
| 74 | + void (*save_state_change)(struct sock *sk); |
| 75 | + void (*save_data_ready)(struct sock *sk); |
| 76 | + void (*save_write_space)(struct sock *sk); |
| 77 | + |
| 78 | + struct list_head psock_list; |
| 79 | + |
| 80 | + /* Receive */ |
| 81 | + struct sk_buff *rx_skb_head; |
| 82 | + struct sk_buff **rx_skb_nextp; |
| 83 | + struct sk_buff *ready_rx_msg; |
| 84 | + struct list_head psock_ready_list; |
| 85 | + struct work_struct rx_work; |
| 86 | + struct delayed_work rx_delayed_work; |
| 87 | + struct bpf_prog *bpf_prog; |
| 88 | + struct kcm_sock *rx_kcm; |
| 89 | + |
| 90 | + /* Transmit */ |
| 91 | + struct kcm_sock *tx_kcm; |
| 92 | + struct list_head psock_avail_list; |
| 93 | +}; |
| 94 | + |
| 95 | +/* Per net MUX list */ |
| 96 | +struct kcm_net { |
| 97 | + struct mutex mutex; |
| 98 | + struct list_head mux_list; |
| 99 | + int count; |
| 100 | +}; |
| 101 | + |
| 102 | +/* Structure for a MUX */ |
| 103 | +struct kcm_mux { |
| 104 | + struct list_head kcm_mux_list; |
| 105 | + struct rcu_head rcu; |
| 106 | + struct kcm_net *knet; |
| 107 | + |
| 108 | + struct list_head kcm_socks; /* All KCM sockets on MUX */ |
| 109 | + int kcm_socks_cnt; /* Total KCM socket count for MUX */ |
| 110 | + struct list_head psocks; /* List of all psocks on MUX */ |
| 111 | + int psocks_cnt; /* Total attached sockets */ |
| 112 | + |
| 113 | + /* Receive */ |
| 114 | + spinlock_t rx_lock ____cacheline_aligned_in_smp; |
| 115 | + struct list_head kcm_rx_waiters; /* KCMs waiting for receiving */ |
| 116 | + struct list_head psocks_ready; /* List of psocks with a msg ready */ |
| 117 | + struct sk_buff_head rx_hold_queue; |
| 118 | + |
| 119 | + /* Transmit */ |
| 120 | + spinlock_t lock ____cacheline_aligned_in_smp; /* TX and mux locking */ |
| 121 | + struct list_head psocks_avail; /* List of available psocks */ |
| 122 | + struct list_head kcm_tx_waiters; /* KCMs waiting for a TX psock */ |
| 123 | +}; |
| 124 | + |
| 125 | +#endif /* __NET_KCM_H_ */ |
0 commit comments