19 #include <netlink-private/netlink.h> 20 #include <netlink/netlink.h> 21 #include <netlink/cache.h> 22 #include <netlink/utils.h> 23 #include <netlink/data.h> 24 #include <netlink/route/rtnl.h> 25 #include <netlink/route/route.h> 26 #include <netlink/route/link.h> 28 static struct nl_cache_ops rtnl_route_ops;
30 static int route_msg_parser(
struct nl_cache_ops *ops,
struct sockaddr_nl *who,
31 struct nlmsghdr *nlh,
struct nl_parser_param *pp)
33 struct rtnl_route *route;
36 if ((err = rtnl_route_parse(nlh, &route)) < 0)
39 err = pp->pp_cb((
struct nl_object *) route, pp);
41 rtnl_route_put(route);
45 static int route_request_update(
struct nl_cache *c,
struct nl_sock *h)
48 .rtm_family = c->c_iarg1,
52 rhdr.rtm_flags |= RTM_F_CLONED;
54 return nl_send_simple(h, RTM_GETROUTE, NLM_F_DUMP, &rhdr,
sizeof(rhdr));
81 struct nl_cache **result)
83 struct nl_cache *cache;
89 cache->c_iarg1 = family;
90 cache->c_iarg2 = flags;
108 static int build_route_msg(
struct rtnl_route *tmpl,
int cmd,
int flags,
109 struct nl_msg **result)
117 if ((err = rtnl_route_build_msg(msg, tmpl)) < 0) {
126 int rtnl_route_build_add_request(
struct rtnl_route *tmpl,
int flags,
127 struct nl_msg **result)
129 return build_route_msg(tmpl, RTM_NEWROUTE, NLM_F_CREATE | flags,
133 int rtnl_route_add(
struct nl_sock *sk,
struct rtnl_route *route,
int flags)
138 if ((err = rtnl_route_build_add_request(route, flags, &msg)) < 0)
146 return wait_for_ack(sk);
149 int rtnl_route_build_del_request(
struct rtnl_route *tmpl,
int flags,
150 struct nl_msg **result)
152 return build_route_msg(tmpl, RTM_DELROUTE, flags, result);
155 int rtnl_route_delete(
struct nl_sock *sk,
struct rtnl_route *route,
int flags)
160 if ((err = rtnl_route_build_del_request(route, flags, &msg)) < 0)
168 return wait_for_ack(sk);
173 static struct nl_af_group route_groups[] = {
174 { AF_INET, RTNLGRP_IPV4_ROUTE },
175 { AF_INET6, RTNLGRP_IPV6_ROUTE },
176 { AF_DECnet, RTNLGRP_DECnet_ROUTE },
177 { END_OF_GROUP_LIST },
180 static struct nl_cache_ops rtnl_route_ops = {
181 .co_name =
"route/route",
182 .co_hdrsize =
sizeof(
struct rtmsg),
184 { RTM_NEWROUTE, NL_ACT_NEW,
"new" },
185 { RTM_DELROUTE, NL_ACT_DEL,
"del" },
186 { RTM_GETROUTE, NL_ACT_GET,
"get" },
187 END_OF_MSGTYPES_LIST,
189 .co_protocol = NETLINK_ROUTE,
190 .co_groups = route_groups,
191 .co_request_update = route_request_update,
192 .co_msg_parser = route_msg_parser,
193 .co_obj_ops = &route_obj_ops,
196 static void __init route_init(
void)
201 static void __exit route_exit(
void)
int nl_send_auto_complete(struct nl_sock *sk, struct nl_msg *msg)
void nlmsg_free(struct nl_msg *msg)
Release a reference from an netlink message.
int nl_cache_mngt_unregister(struct nl_cache_ops *ops)
Unregister a set of cache operations.
#define ROUTE_CACHE_CONTENT
When passed to rtnl_route_alloc_cache() the cache will correspond to the contents of the routing cach...
int nl_cache_mngt_register(struct nl_cache_ops *ops)
Register a set of cache operations.
int nl_send_simple(struct nl_sock *sk, int type, int flags, void *buf, size_t size)
Construct and transmit a Netlink message.
int nl_cache_refill(struct nl_sock *sk, struct nl_cache *cache)
(Re)fill a cache with the contents in the kernel.
struct nl_msg * nlmsg_alloc_simple(int nlmsgtype, int flags)
Allocate a new netlink message.
int rtnl_route_alloc_cache(struct nl_sock *sk, int family, int flags, struct nl_cache **result)
Build a route cache holding all routes currently configured in the kernel.
struct nl_cache * nl_cache_alloc(struct nl_cache_ops *ops)
Allocate new cache.