1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-02 10:51:20 +03:00

sd-rtnl: add sd_rtnl_message_{new_neigh,neigh_get_{family,ifindex}}

This commit is contained in:
Tom Gundersen 2014-12-02 01:35:11 +01:00
parent e559b38493
commit 20dff6c4ff
4 changed files with 73 additions and 3 deletions

View File

@ -171,6 +171,59 @@ int sd_rtnl_message_new_route(sd_rtnl *rtnl, sd_rtnl_message **ret,
return 0;
}
int sd_rtnl_message_neigh_get_family(sd_rtnl_message *m, int *family) {
struct ndmsg *ndm;
assert_return(m, -EINVAL);
assert_return(m->hdr, -EINVAL);
assert_return(rtnl_message_type_is_neigh(m->hdr->nlmsg_type), -EINVAL);
assert_return(family, -EINVAL);
ndm = NLMSG_DATA(m->hdr);
*family = ndm->ndm_family;
return 0;
}
int sd_rtnl_message_neigh_get_ifindex(sd_rtnl_message *m, int *index) {
struct ndmsg *ndm;
assert_return(m, -EINVAL);
assert_return(m->hdr, -EINVAL);
assert_return(rtnl_message_type_is_neigh(m->hdr->nlmsg_type), -EINVAL);
assert_return(index, -EINVAL);
ndm = NLMSG_DATA(m->hdr);
*index = ndm->ndm_ifindex;
return 0;
}
int sd_rtnl_message_new_neigh(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t nlmsg_type, int index, int ndm_family) {
struct ndmsg *ndm;
int r;
assert_return(rtnl_message_type_is_neigh(nlmsg_type), -EINVAL);
assert_return(ndm_family == AF_INET || ndm_family == AF_INET6, -EINVAL);
assert_return(ret, -EINVAL);
r = message_new(rtnl, ret, nlmsg_type);
if (r < 0)
return r;
if (nlmsg_type == RTM_NEWNEIGH)
(*ret)->hdr->nlmsg_flags |= NLM_F_CREATE | NLM_F_APPEND;
ndm = NLMSG_DATA((*ret)->hdr);
ndm->ndm_family = ndm_family;
ndm->ndm_ifindex = index;
return 0;
}
int sd_rtnl_message_link_set_flags(sd_rtnl_message *m, unsigned flags, unsigned change) {
struct ifinfomsg *ifi;
@ -244,7 +297,8 @@ int sd_rtnl_message_request_dump(sd_rtnl_message *m, int dump) {
assert_return(m->hdr, -EINVAL);
assert_return(m->hdr->nlmsg_type == RTM_GETLINK ||
m->hdr->nlmsg_type == RTM_GETADDR ||
m->hdr->nlmsg_type == RTM_GETROUTE,
m->hdr->nlmsg_type == RTM_GETROUTE ||
m->hdr->nlmsg_type == RTM_GETNEIGH,
-EINVAL);
if (dump)

View File

@ -122,6 +122,17 @@ int rtnl_message_new_synthetic_error(int error, uint32_t serial, sd_rtnl_message
return 0;
}
bool rtnl_message_type_is_neigh(uint16_t type) {
switch (type) {
case RTM_NEWNEIGH:
case RTM_GETNEIGH:
case RTM_DELNEIGH:
return true;
default:
return false;
}
}
bool rtnl_message_type_is_route(uint16_t type) {
switch (type) {
case RTM_NEWROUTE:

View File

@ -33,6 +33,7 @@ void rtnl_message_seal(sd_rtnl_message *m);
bool rtnl_message_type_is_link(uint16_t type);
bool rtnl_message_type_is_addr(uint16_t type);
bool rtnl_message_type_is_route(uint16_t type);
bool rtnl_message_type_is_neigh(uint16_t type);
int rtnl_set_link_name(sd_rtnl **rtnl, int ifindex, const char *name);
int rtnl_set_link_properties(sd_rtnl **rtnl, int ifindex, const char *alias, const struct ether_addr *mac, unsigned mtu);

View File

@ -75,6 +75,7 @@ int sd_rtnl_message_new_addr(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t msg_
int family);
int sd_rtnl_message_new_route(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t nlmsg_type,
int rtm_family, unsigned char rtm_protocol);
int sd_rtnl_message_new_neigh(sd_rtnl *rtnl, sd_rtnl_message **ret, uint16_t msg_type, int index, int nda_family);
sd_rtnl_message *sd_rtnl_message_ref(sd_rtnl_message *m);
sd_rtnl_message *sd_rtnl_message_unref(sd_rtnl_message *m);
@ -104,6 +105,9 @@ int sd_rtnl_message_route_set_dst_prefixlen(sd_rtnl_message *m, unsigned char pr
int sd_rtnl_message_route_set_scope(sd_rtnl_message *m, unsigned char scope);
int sd_rtnl_message_route_get_family(sd_rtnl_message *m, int *family);
int sd_rtnl_message_neigh_get_family(sd_rtnl_message *m, int *family);
int sd_rtnl_message_neigh_get_ifindex(sd_rtnl_message *m, int *family);
int sd_rtnl_message_append_string(sd_rtnl_message *m, unsigned short type, const char *data);
int sd_rtnl_message_append_u8(sd_rtnl_message *m, unsigned short type, uint8_t data);
int sd_rtnl_message_append_u16(sd_rtnl_message *m, unsigned short type, uint16_t data);