Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
4bf0ec2
Update ksocket.c
mephistolist Aug 3, 2025
7514522
Update ksocket.h
mephistolist Aug 3, 2025
7d69cef
Update Makefile
mephistolist Aug 3, 2025
9c2b4cc
Update README.md
mephistolist Aug 3, 2025
287692c
Update README.md
mephistolist Aug 3, 2025
8afbded
Update README.md
mephistolist Aug 3, 2025
161400a
Update Makefile
mephistolist Aug 7, 2025
b53df7a
Update Makefile
mephistolist Aug 7, 2025
f77b13e
Update ksocket.h
mephistolist Aug 7, 2025
50230fc
Update ksocket.h
mephistolist Aug 7, 2025
9e59499
Create tcp_server.c
mephistolist Aug 7, 2025
ed955d8
Update tcp_server.c
mephistolist Aug 7, 2025
638bd23
Delete sample/tcp/ksocket_tcp_cli_demo.c
mephistolist Aug 7, 2025
92b333e
Delete sample/tcp/ksocket_tcp_srv_demo.c
mephistolist Aug 7, 2025
84aaa39
Create tcp_client.c
mephistolist Aug 7, 2025
b0469f4
Update tcp_client.c
mephistolist Aug 7, 2025
37ea871
Create udp_server.c
mephistolist Aug 10, 2025
536953e
Delete sample/udp/ksocket_udp_srv_demo.c
mephistolist Aug 10, 2025
18d6eb7
Delete sample/udp/ksocket_udp_cli_demo.c
mephistolist Aug 10, 2025
1cdef9e
Create udp_client.c
mephistolist Aug 10, 2025
7a01695
Update Makefile
mephistolist Aug 10, 2025
1bb06e4
Create Makefile
mephistolist Aug 10, 2025
1ec8c3f
Create ksocket.h
mephistolist Aug 10, 2025
85c2488
Create tcp_server.c
mephistolist Aug 10, 2025
2d52844
Create Makefile
mephistolist Aug 10, 2025
e6cd4d5
Create ksocket.h
mephistolist Aug 10, 2025
8ba16f6
Create tcp_client.c
mephistolist Aug 10, 2025
24d4ba9
Create Makefile
mephistolist Aug 10, 2025
6844e76
Create ksocket.h
mephistolist Aug 10, 2025
f296f1d
Create udp_server.c
mephistolist Aug 10, 2025
7b0737c
Create Makefile
mephistolist Aug 10, 2025
edf7f5e
Create ksocket.h
mephistolist Aug 10, 2025
ba17592
Create udp_client.c
mephistolist Aug 10, 2025
8011e00
Delete sample/tcp directory
mephistolist Aug 10, 2025
7a56b0b
Delete sample/udp directory
mephistolist Aug 10, 2025
4ed2a90
Update tcp_server.c
mephistolist Aug 10, 2025
2567f73
Update tcp_server.c
mephistolist Aug 10, 2025
ce0bad7
Update ksocket.h
mephistolist Aug 11, 2025
750f294
Update ksocket.h
mephistolist Aug 11, 2025
0872014
Update ksocket.h
mephistolist Aug 11, 2025
ce58935
Update README.md
mephistolist Aug 11, 2025
e643f64
Update README.md
mephistolist Aug 11, 2025
e811af4
Update AUTHOR
mephistolist Aug 11, 2025
a5be4c1
Update README.md
mephistolist Aug 11, 2025
274b6ef
Update ksocket.c
mephistolist Aug 11, 2025
b706296
Update tcp_server.c
mephistolist Aug 11, 2025
fda2d48
Update README.md
mephistolist Aug 11, 2025
a6fa750
Update README.md
mephistolist Aug 14, 2025
4e4bac3
Update README.md
mephistolist Aug 15, 2025
0fcffd2
Create Kconfig
mephistolist Aug 16, 2025
fce2fc1
Update README.md
mephistolist Aug 16, 2025
0c1e1f0
Update README.md
mephistolist Aug 16, 2025
229fb42
Update AUTHOR
mephistolist Aug 16, 2025
6b1f60a
Update README.md
mephistolist Aug 16, 2025
1b414be
Update README.md
mephistolist Aug 16, 2025
f61ac7f
Update README.md
mephistolist Aug 17, 2025
a0b9fff
Update README.md
mephistolist Aug 19, 2025
716dab7
Update README.md
mephistolist Aug 19, 2025
fbdb304
Update tcp_server.c
mephistolist Aug 20, 2025
631467d
Update udp_server.c
mephistolist Aug 20, 2025
e0b1f60
Update udp_client.c
mephistolist Aug 20, 2025
8e0ff79
Update udp_client.c
mephistolist Aug 20, 2025
b5c4d1b
Update tcp_server.c
mephistolist Aug 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions AUTHOR
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
Author
Authors

[email protected]

(C)2007-2008, China

2017 Hardik Bagdi([email protected])
Changes for Compatibility with Linux 4.9 to use iov_iter

2025 Mephistolist([email protected])
Complete rewrite for kernels 5.11-6.16.
69 changes: 43 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
# ksocket API

BSD-style socket API in kernel space for TCP/IP networking.
Original ksocket for v2.6 was published at [http://ksocket.sourceforge.net/](http://ksocket.sourceforge.net/).
This repository contains changes to make it compatible with new kernel versions.
The ksocket API has been updated to incorporate the changes related to the [iov_iter](https://lwn.net/Articles/625077/) interface introduced in kernel v3.19+.
A BSD-style socket API in kernel space for TCP/IP networking on Linux kernels 5.11-6.16. This is not backwards compatible with older kernels, but links will be provided to those later in this documentation.

### Getting started
```
$ git clone https://github.com/hbagdi/ksocket.git
$ git clone https://github.com/mephistolist/ksocket.git
$ cd ksocket/src
$ make # make sure you have the kernel headers/tree installed
$ make # make sure you have the kernel headers/tree installed first
$ sudo insmod ksocket.ko
#now you can use the exported symbols from this kernel module
```

### Sample
Look at `sample` sub-directory for code-samples.
You can then go to the samples directory in the root of this project. Inside it are TCP and UDP of servers and client examples you may build and insert into the kernel. After inserting the server and client for TCP, you should see something like the following with dmesg:
```
$ cd ksocket/sample/tcp/
$ make
# two kernel modules are ksocket_tcp_cli_demo.ko(TCP client) and ksocket_tcp_srv_demo.ko(TCP server)
$ sudo ksocket_tcp_srv_demo.ko
$ sudo ksocket_tcp_cli_demo.ko
$ dmesg
# dmesg
[ 137.259240] tcp_server: Loading (starting thread)
[ 137.260232] tcp_server: thread starting
[ 137.260634] tcp_server: listening on port 12345
[ 151.256262] [tcp_client] Initializing
[ 151.257245] sock_create sk= 0x00000000db4a0058
[ 151.264826] [tcp_client] Connected to 127.0.0.1:12345
[ 151.264886] tcp_server: accepted newsock=000000000aae9c53 newsock->sk=00000000844b247d
[ 151.265311] tcp_server: received (29 bytes): Hello from kernel TCP client!
[ 151.265396] [tcp_client] Sent: Hello from kernel TCP client!
```
Or with the UDP modules, the dmesg should resemble this:
```
# dmesg
[ 501.520772] sock_create sk= 0x00000000295150e8
[ 501.522605] kbind ret = 0
[ 501.523914] UDP Server: Listening on port 4444
[ 590.998621] [udp_client] Initializing
[ 591.001210] sock_create sk= 0x000000006da0c70b
[ 591.003466] [udp_client] Sent: Hello UDP Server
[ 591.003636] UDP Server: Received 'Hello UDP Server'
[ 591.062269] [udp_client] Received: ACK from UDP Server
```

### Support across kernel versions
The original ksocket work was to support Linux 2.6, however support for v5.4.0 has been
included.

v5.4.0 support is a work on Linux ubuntu 5.4.0-66 x86-64, therefore there is no guarantee it works
well on versions > 2.6 && < 5.3.x

In order to keep the 2.6 version stable it was left without the 5.4.0 work,
instead we now have two branches: v2.6 (master) and v5.4.0
The original ksocket work was to support Linux 2.6, and later versions came for later kernels. This version of ksocket was designed for kernels 5.11-6.16. It may work in verions beyond 6.16, but we do not know what future kernel versions will entail. If you need this for an older kernel, see the links below:

#### v2.6 original development
https://github.com/hbagdi/ksocket
Expand All @@ -43,7 +46,21 @@ https://github.com/hbagdi/ksocket/tree/linux-5.4.0

### Contributing/Reporting Bugs
- Feel free to open Pull-Requests here for any enhancements/fixes.
- Open an issue in the repository for any help or bugs. Make sure to mention Kernel version.
- Open an issue in the repository for any help or bugs. Make sure to mention Kernel version.

### Stream-lining
If you wish to not have to load the ksocket module, or link its symbols in Makefiles you can statically link ksocket when building a kernel from source. Considering we have kernel 6.16 inside /usr/src and this ksocket project in /home/user/ksocket, we can do something like the following:

```
# export VERSION=6.16
# mkdir /usr/src/linux-$VERSION/drivers/ksocket
# rsync -avP /home/user/ksocket/ /usr/src/linux-$VERSION/drivers/ksocket/
# sed -i '$ s|^endmenu$|source "drivers/ksocket/Kconfig"\nendmenu|' /usr/src/linux-$VERSION/drivers/Kconfig
# echo "obj-$(CONFIG_KSOCKET) += ksocket/" >> /usr/src/linux-$VERSION/drivers/Makefile
```
If you proceed with then building and loading your kernel, you will not have to build or insert the ksocket module as it will already be in the kernel. You will also no longer need this line in your Makefiles to use or call kscoket's API:
```
KBUILD_EXTRA_SYMBOLS := ../../../src/Module.symvers
```
### Contact
Email at [email protected] for any further help.
For this version of kscoket you may reach out to [email protected].
33 changes: 0 additions & 33 deletions sample/tcp/Makefile

This file was deleted.

92 changes: 0 additions & 92 deletions sample/tcp/ksocket_tcp_cli_demo.c

This file was deleted.

128 changes: 0 additions & 128 deletions sample/tcp/ksocket_tcp_srv_demo.c

This file was deleted.

33 changes: 0 additions & 33 deletions sample/udp/Makefile

This file was deleted.

Loading