Skip to content

Commit ab7ac4e

Browse files
tomratbertdavem330
authored andcommitted
kcm: Kernel Connection Multiplexor module
This module implements the Kernel Connection Multiplexor. Kernel Connection Multiplexor (KCM) is a facility that provides a message based interface over TCP for generic application protocols. With KCM an application can efficiently send and receive application protocol messages over TCP using datagram sockets. For more information see the included Documentation/networking/kcm.txt Signed-off-by: Tom Herbert <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 473bd23 commit ab7ac4e

File tree

8 files changed

+2201
-1
lines changed

8 files changed

+2201
-1
lines changed

include/linux/socket.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ struct ucred {
200200
#define AF_ALG 38 /* Algorithm sockets */
201201
#define AF_NFC 39 /* NFC sockets */
202202
#define AF_VSOCK 40 /* vSockets */
203-
#define AF_MAX 41 /* For now.. */
203+
#define AF_KCM 41 /* Kernel Connection Multiplexor*/
204+
205+
#define AF_MAX 42 /* For now.. */
204206

205207
/* Protocol families, same as address families. */
206208
#define PF_UNSPEC AF_UNSPEC
@@ -246,6 +248,7 @@ struct ucred {
246248
#define PF_ALG AF_ALG
247249
#define PF_NFC AF_NFC
248250
#define PF_VSOCK AF_VSOCK
251+
#define PF_KCM AF_KCM
249252
#define PF_MAX AF_MAX
250253

251254
/* Maximum queue length specifiable by listen. */
@@ -323,6 +326,7 @@ struct ucred {
323326
#define SOL_CAIF 278
324327
#define SOL_ALG 279
325328
#define SOL_NFC 280
329+
#define SOL_KCM 281
326330

327331
/* IPX options */
328332
#define IPX_TYPE 1

include/net/kcm.h

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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_ */

include/uapi/linux/kcm.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
* User API to clone KCM sockets and attach transport socket to a KCM
11+
* multiplexor.
12+
*/
13+
14+
#ifndef KCM_KERNEL_H
15+
#define KCM_KERNEL_H
16+
17+
struct kcm_attach {
18+
int fd;
19+
int bpf_fd;
20+
};
21+
22+
struct kcm_unattach {
23+
int fd;
24+
};
25+
26+
struct kcm_clone {
27+
int fd;
28+
};
29+
30+
#define SIOCKCMATTACH (SIOCPROTOPRIVATE + 0)
31+
#define SIOCKCMUNATTACH (SIOCPROTOPRIVATE + 1)
32+
#define SIOCKCMCLONE (SIOCPROTOPRIVATE + 2)
33+
34+
#define KCMPROTO_CONNECTED 0
35+
36+
/* Socket options */
37+
#define KCM_RECV_DISABLE 1
38+
39+
#endif
40+

net/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ source "net/can/Kconfig"
360360
source "net/irda/Kconfig"
361361
source "net/bluetooth/Kconfig"
362362
source "net/rxrpc/Kconfig"
363+
source "net/kcm/Kconfig"
363364

364365
config FIB_RULES
365366
bool

net/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ obj-$(CONFIG_IRDA) += irda/
3434
obj-$(CONFIG_BT) += bluetooth/
3535
obj-$(CONFIG_SUNRPC) += sunrpc/
3636
obj-$(CONFIG_AF_RXRPC) += rxrpc/
37+
obj-$(CONFIG_AF_KCM) += kcm/
3738
obj-$(CONFIG_ATM) += atm/
3839
obj-$(CONFIG_L2TP) += l2tp/
3940
obj-$(CONFIG_DECNET) += decnet/

net/kcm/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
config AF_KCM
3+
tristate "KCM sockets"
4+
depends on INET
5+
select BPF_SYSCALL
6+
---help---
7+
KCM (Kernel Connection Multiplexor) sockets provide a method
8+
for multiplexing messages of a message based application
9+
protocol over kernel connectons (e.g. TCP connections).
10+

net/kcm/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
obj-$(CONFIG_AF_KCM) += kcm.o
2+
3+
kcm-y := kcmsock.o

0 commit comments

Comments
 (0)