libnl  3.2.7
bridge.c
1 /*
2  * lib/route/link/bridge.c AF_BRIDGE link oeprations
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation version 2.1
7  * of the License.
8  *
9  * Copyright (c) 2010 Thomas Graf <tgraf@suug.ch>
10  */
11 
12 #include <netlink-local.h>
13 #include <netlink/netlink.h>
14 #include <netlink/attr.h>
15 #include <netlink/route/rtnl.h>
16 #include <netlink/route/link/api.h>
17 
19 {
20  uint8_t b_port_state;
21 };
22 
23 static void *bridge_alloc(struct rtnl_link *link)
24 {
25  return calloc(1, sizeof(struct bridge_data));
26 }
27 
28 static void *bridge_clone(struct rtnl_link *link, void *data)
29 {
30  struct bridge_data *bd;
31 
32  if ((bd = bridge_alloc(link)))
33  memcpy(bd, data, sizeof(*bd));
34 
35  return bd;
36 }
37 
38 static void bridge_free(struct rtnl_link *link, void *data)
39 {
40  free(data);
41 }
42 
43 static int bridge_parse_protinfo(struct rtnl_link *link, struct nlattr *attr,
44  void *data)
45 {
46  struct bridge_data *bd = data;
47 
48  bd->b_port_state = nla_get_u8(attr);
49 
50  return 0;
51 }
52 
53 static void bridge_dump_details(struct rtnl_link *link,
54  struct nl_dump_params *p, void *data)
55 {
56  struct bridge_data *bd = data;
57 
58  nl_dump(p, "port-state %u ", bd->b_port_state);
59 }
60 
61 static const struct nla_policy protinfo_policy = {
62  .type = NLA_U8,
63 };
64 
65 static struct rtnl_link_af_ops bridge_ops = {
66  .ao_family = AF_BRIDGE,
67  .ao_alloc = &bridge_alloc,
68  .ao_clone = &bridge_clone,
69  .ao_free = &bridge_free,
70  .ao_parse_protinfo = &bridge_parse_protinfo,
71  .ao_dump[NL_DUMP_DETAILS] = &bridge_dump_details,
72  .ao_protinfo_policy = &protinfo_policy,
73 };
74 
75 static void __init bridge_init(void)
76 {
77  rtnl_link_af_register(&bridge_ops);
78 }
79 
80 static void __exit bridge_exit(void)
81 {
82  rtnl_link_af_unregister(&bridge_ops);
83 }