+int odhcpd_setup_route(const struct in6_addr *addr, const int prefixlen,
+ const struct interface *iface, const struct in6_addr *gw,
+ const uint32_t metric, const bool add)
+{
+ struct nl_msg *msg;
+ struct rtmsg rtm = {
+ .rtm_family = AF_INET6,
+ .rtm_dst_len = prefixlen,
+ .rtm_src_len = 0,
+ .rtm_table = RT_TABLE_MAIN,
+ .rtm_protocol = (add ? RTPROT_STATIC : RTPROT_UNSPEC),
+ .rtm_scope = (add ? (gw ? RT_SCOPE_UNIVERSE : RT_SCOPE_LINK) : RT_SCOPE_NOWHERE),
+ .rtm_type = (add ? RTN_UNICAST : RTN_UNSPEC),
+ };
+ int ret = 0;
+
+ msg = nlmsg_alloc_simple(add ? RTM_NEWROUTE : RTM_DELROUTE,
+ add ? NLM_F_CREATE | NLM_F_REPLACE : 0);
+ if (!msg)
+ return -1;
+
+ nlmsg_append(msg, &rtm, sizeof(rtm), 0);
+
+ nla_put(msg, RTA_DST, sizeof(*addr), addr);
+ nla_put_u32(msg, RTA_OIF, iface->ifindex);
+ nla_put_u32(msg, RTA_PRIORITY, metric);
+
+ if (gw)
+ nla_put(msg, RTA_GATEWAY, sizeof(*gw), gw);
+
+ ret = nl_send_auto_complete(rtnl_socket, msg);
+ nlmsg_free(msg);
+
+ if (ret < 0)
+ return ret;
+
+ return nl_wait_for_ack(rtnl_socket);
+}
+
+int odhcpd_setup_proxy_neigh(const struct in6_addr *addr,
+ const struct interface *iface, const bool add)
+{
+ struct nl_msg *msg;
+ struct ndmsg ndm = {
+ .ndm_family = AF_INET6,
+ .ndm_flags = NTF_PROXY,
+ .ndm_ifindex = iface->ifindex,
+ };
+ int ret = 0, flags = NLM_F_REQUEST;
+
+ if (add)
+ flags |= NLM_F_REPLACE | NLM_F_CREATE;
+
+ msg = nlmsg_alloc_simple(add ? RTM_NEWNEIGH : RTM_DELNEIGH, flags);
+ if (!msg)
+ return -1;
+
+ nlmsg_append(msg, &ndm, sizeof(ndm), 0);
+
+ nla_put(msg, NDA_DST, sizeof(*addr), addr);
+
+ ret = nl_send_auto_complete(rtnl_socket, msg);
+ nlmsg_free(msg);
+
+ if (ret < 0)
+ return ret;
+
+ return nl_wait_for_ack(rtnl_socket);
+}