libnl  3.6.0
container.c
1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3  * Copyright (c) 2008-2013 Thomas Graf <tgraf@suug.ch>
4  */
5 
6 #include <netlink-private/netlink.h>
7 #include <netlink-private/tc.h>
8 #include <netlink/netlink.h>
9 #include <netlink/route/cls/ematch.h>
10 
11 static int container_parse(struct rtnl_ematch *e, void *data, size_t len __attribute__((unused)))
12 {
13  /*
14  The kernel may provide more than 4 bytes of data in the future and we want
15  older libnl versions to be ok with that. We want interfaces to be growable
16  so we only ever enforce a minimum data length and copy as much as we are
17  aware of. Thomas Graf.
18  */
19  memcpy(e->e_data, data, sizeof(uint32_t));
20 
21  return 0;
22 }
23 
24 static int container_fill(struct rtnl_ematch *e, struct nl_msg *msg)
25 {
26  return nlmsg_append(msg, e->e_data, sizeof(uint32_t), 0);
27 }
28 
29 static struct rtnl_ematch_ops container_ops = {
30  .eo_kind = TCF_EM_CONTAINER,
31  .eo_name = "container",
32  .eo_minlen = sizeof(uint32_t),
33  .eo_datalen = sizeof(uint32_t),
34  .eo_parse = container_parse,
35  .eo_fill = container_fill,
36 };
37 
38 static void __init container_init(void)
39 {
40  rtnl_ematch_register(&container_ops);
41 }
int rtnl_ematch_register(struct rtnl_ematch_ops *ops)
Register ematch module.
Definition: ematch.c:40
int nlmsg_append(struct nl_msg *n, void *data, size_t len, int pad)
Append data to tail of a netlink message.
Definition: msg.c:442
Extended Match Operations.
Definition: ematch.h:28