bridge.c

00001 /*
00002  * lib/route/link/bridge.c      AF_BRIDGE link oeprations
00003  *
00004  *      This library is free software; you can redistribute it and/or
00005  *      modify it under the terms of the GNU Lesser General Public
00006  *      License as published by the Free Software Foundation version 2.1
00007  *      of the License.
00008  *
00009  * Copyright (c) 2010 Thomas Graf <tgraf@suug.ch>
00010  */
00011 
00012 #include <netlink-local.h>
00013 #include <netlink/netlink.h>
00014 #include <netlink/attr.h>
00015 #include <netlink/route/rtnl.h>
00016 #include <netlink/route/link/api.h>
00017 
00018 struct bridge_data
00019 {
00020         uint8_t                 b_port_state;
00021 };
00022 
00023 static void *bridge_alloc(struct rtnl_link *link)
00024 {
00025         return calloc(1, sizeof(struct bridge_data));
00026 }
00027 
00028 static void *bridge_clone(struct rtnl_link *link, void *data)
00029 {
00030         struct bridge_data *bd;
00031 
00032         if ((bd = bridge_alloc(link)))
00033                 memcpy(bd, data, sizeof(*bd));
00034 
00035         return bd;
00036 }
00037 
00038 static void bridge_free(struct rtnl_link *link, void *data)
00039 {
00040         free(data);
00041 }
00042 
00043 static int bridge_parse_protinfo(struct rtnl_link *link, struct nlattr *attr,
00044                                  void *data)
00045 {
00046         struct bridge_data *bd = data;
00047 
00048         bd->b_port_state = nla_get_u8(attr);
00049 
00050         return 0;
00051 }
00052 
00053 static void bridge_dump_details(struct rtnl_link *link,
00054                                 struct nl_dump_params *p, void *data)
00055 {
00056         struct bridge_data *bd = data;
00057 
00058         nl_dump(p, "port-state %u ", bd->b_port_state);
00059 }
00060 
00061 static const struct nla_policy protinfo_policy = {
00062         .type                   = NLA_U8,
00063 };
00064 
00065 static struct rtnl_link_af_ops bridge_ops = {
00066         .ao_family                      = AF_BRIDGE,
00067         .ao_alloc                       = &bridge_alloc,
00068         .ao_clone                       = &bridge_clone,
00069         .ao_free                        = &bridge_free,
00070         .ao_parse_protinfo              = &bridge_parse_protinfo,
00071         .ao_dump[NL_DUMP_DETAILS]       = &bridge_dump_details,
00072         .ao_protinfo_policy             = &protinfo_policy,
00073 };
00074 
00075 static void __init bridge_init(void)
00076 {
00077         rtnl_link_af_register(&bridge_ops);
00078 }
00079 
00080 static void __exit bridge_exit(void)
00081 {
00082         rtnl_link_af_unregister(&bridge_ops);
00083 }