#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
+#include <time.h>
#include <linux/fib_rules.h>
#include "relayd.h"
+#define NLMSG_ALIGNTO 4U
+#define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) )
+
static struct uloop_fd rtnl_sock;
static unsigned int rtnl_seq, rtnl_dump_seq;
int route_table = 16800;
static void
rtnl_rule_request(struct relayd_interface *rif, int flags)
{
- static struct {
+ struct {
struct nlmsghdr nl;
struct rtmsg rt;
struct {
} __packed table;
struct {
struct rtattr rta;
+ int prio;
+ } __packed prio;
+ struct {
+ struct rtattr rta;
char ifname[IFNAMSIZ + 1];
} __packed dev;
} __packed req = {
.rtm_scope = RT_SCOPE_UNIVERSE,
.rtm_protocol = RTPROT_BOOT,
},
+ .prio = {
+ .rta.rta_type = FRA_PRIORITY,
+ .rta.rta_len = sizeof(req.prio),
+ .prio = 2,
+ },
.table.rta = {
.rta_type = FRA_TABLE,
.rta_len = sizeof(req.table),
ifname = rif->ifname;
if (!(flags & RULE_F_DEFGW_WORKAROUND)) {
+ int len = strlen(ifname) + 1;
req.dev.rta.rta_type = FRA_IFNAME;
- padding -= strlen(ifname) + 1;
+ padding -= NLMSG_ALIGN(len);
strcpy(req.dev.ifname, ifname);
- req.dev.rta.rta_len = sizeof(req.dev.rta) + strlen(ifname) + 1;
+ req.dev.rta.rta_len = sizeof(req.dev.rta) + len;
} else {
- req.dev.rta.rta_type = FRA_PRIORITY;
- req.dev.rta.rta_len = sizeof(req.dev.rta) + sizeof(uint32_t);
- padding -= sizeof(uint32_t);
- *((uint32_t *) &req.dev.ifname) = 1;
+ padding = sizeof(req.dev);
+ req.prio.prio--;
}
req.table.table = get_route_table(rif);
req.nl.nlmsg_len = sizeof(req) - padding;
int relayd_rtnl_init(void)
{
- struct sockaddr_nl snl_local;
+ struct sockaddr_nl snl_local = {};
rtnl_sock.fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (rtnl_sock.fd < 0) {