From bdbec30a849807fb5e6841a38cfe0d168e5962b9 Mon Sep 17 00:00:00 2001 From: Stefano Brivio 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 --- cooker/match.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) (limited to 'cooker/match.c') diff --git a/cooker/match.c b/cooker/match.c index 36ac9df..c56d9e5 100644 --- a/cooker/match.c +++ b/cooker/match.c @@ -19,6 +19,40 @@ #include "calls/net.h" #include "seccomp_profile.h" + +#include +#include + +static struct num netlink_types[] = { + { "newroute", RTM_NEWROUTE }, + { 0 }, +}; + +static struct num netlink_flags[] = { + { "request", NLM_F_REQUEST }, + { "create", NLM_F_CREATE }, + { 0 }, +}; + +static struct field netlink_header_fields[] = { + { + "type", USHORT, 0, + offsetof(struct nlmsghdr, nlmsg_type), + 0, { .d_num = netlink_types } + }, + { + "flags", USHORT, FLAGS, + offsetof(struct nlmsghdr, nlmsg_flags), + 0, { .d_num = netlink_flags } + }, + { 0 }, +}; + +static struct field netlink_header = { + "netlink", STRUCT, 0, 0, 0, + { .d_struct = netlink_header_fields } +}; + /** * arg_load() - Allocate and build bytecode for one syscall argument * @g: gluten context @@ -117,6 +151,15 @@ xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx break; } + offset.offset += f->offset; + + if (f->flags & IOV) { + struct gluten_offset iovlen = offset; + + iovlen.offset += f->desc.d_iovlen; + offset = emit_iovload(g, offset, iovlen, f->size); + } + if (json_value_get_type(jvalue) == JSONObject && (tmp = json_value_get_object(jvalue)) && (tag_name = json_object_get_string(tmp, "set"))) { @@ -155,8 +198,6 @@ xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx if (!jvalue || (f->flags & RBUF)) return v; - offset.offset += f->offset; - switch (f->type) { case USHORT: case INT: @@ -258,6 +299,17 @@ xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx parse_field(g, offset, cmp, jump, index, f, jvalue); break; case STRING: + if (json_value_get_type(jvalue) == JSONObject && + (tmp = json_value_get_object(jvalue))) { + if ((jvalue = json_object_get_value(tmp, "netlink"))) { + parse_field(g, offset, cmp, jump, index, + &netlink_header, jvalue); + } else { + die(" unrecognised blob type"); + } + break; + } + if ((v.v_str = json_value_get_string(jvalue)) == NULL) die(" failed parsing field for value:%s", json_serialize_to_string_pretty(jvalue)); -- cgit v1.2.3