From bdbec30a849807fb5e6841a38cfe0d168e5962b9 Mon Sep 17 00:00:00 2001
From: Stefano Brivio <sbrivio@redhat.com>
Date: Thu, 21 Dec 2023 12:06:05 +0100
Subject: seitan: Add netlink, sendto()/sendmsg(), iovec handling, demo with
 routes

A bit rough at the moment, but it does the trick. Bonus: setsockopt()
(with magic values only, not used in any demo yet).

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 demo/routes.hjson | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 demo/routes.hjson

(limited to 'demo')

diff --git a/demo/routes.hjson b/demo/routes.hjson
new file mode 100644
index 0000000..5534001
--- /dev/null
+++ b/demo/routes.hjson
@@ -0,0 +1,34 @@
+[
+  {
+    "match": [
+      /* Is somebody trying to create a route? Hang on... */
+      { "sendmsg": { "fd": { "set": "fd" },
+                     "msg": { "iov": { "set": "buf", "value": { "netlink": { "type": "newroute", "flags": { "all": [ "create", "request" ] } } } } } }
+      }
+    ],
+    "call": [
+      /* Create a new socket, owned by us */
+      { "socket": { "family": "netlink", "type": "raw", "flags": "nonblock", "protocol": "nl_route" }, "ret": "new_fd" },
+
+      /* Bind it for netlink usage */
+      { "bind": { "fd": { "get": "new_fd" }, "addr": { "family": "netlink", "pid": 0, "groups": 0 } }, "ret": "y" },
+
+      /* And re-send the original message */
+      { "sendmsg": { "fd": { "get": "new_fd" }, "msg": { "name": { "family": "netlink", "pid": 0, "groups": 0 }, "iovlen": 1, "iov": { "get": "buf" } }, "flags": 0 }, "ret": "n" }
+    ],
+    /* Then, sneak our socket back into the calling process */
+    "fd": { "src": { "get": "fd" }, "new": { "set": "new_fd" }, "close_on_exec": false },
+
+    /* And report success, or failure */
+    "return": { "value": "n", "error": "n" }
+  },
+  {
+    /* FIXME: Unblock subsequent recvmsg(). To keep this clean, we should proxy
+     * it ourselves.
+     */
+    "match": [
+      { "recvmsg": { "fd": 4 /* TODO: get *our* new number */ } }
+    ],
+    "return": { "value": 0, "error": 0 }
+  }
+]
-- 
cgit v1.2.3