diff --git a/include/node.h b/include/node.h index f9520d611..d03fd8bda 100644 --- a/include/node.h +++ b/include/node.h @@ -48,6 +48,12 @@ struct node /// Remote address of the socket struct sockaddr_in remote; + /// Name of the local interface + const char *ifname; + /// Index of the local interface + int ifindex; + /// Socket Mark + int mark; /// A short identifier of the node const char *name; diff --git a/src/node.c b/src/node.c index 90528eb8e..360f5a3f8 100644 --- a/src/node.c +++ b/src/node.c @@ -19,6 +19,7 @@ #include "utils.h" #include "msg.h" #include "node.h" +#include "if.h" int node_create(struct node *n, const char *name, enum node_type type, struct sockaddr_in local, struct sockaddr_in remote) @@ -29,6 +30,10 @@ int node_create(struct node *n, const char *name, enum node_type type, n->local = local; n->remote = remote; + /* We use to local address to determine the outgoing interface */ + //n->ifname = if_addrtoname((struct sockaddr*) &local); + //n->ifindex = if_nametoindex(n->ifname); + return 0; } @@ -41,8 +46,16 @@ int node_connect(struct node *n) /* Set socket options */ int prio = SOCKET_PRIO; - if (setsockopt(n->sd, SOL_SOCKET, SOCKET_PRIO, &prio, sizeof(prio))) - perror("Failed to set socket options"); + if (setsockopt(n->sd, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio))) + perror("Failed to set socket priority"); + else + debug(4, "Set socket priority of node '%s' to %u", n->name, prio); + + /* Set mark for outgoing packets */ + if (setsockopt(n->sd, SOL_SOCKET, SO_MARK, &n->mark, sizeof(n->mark))) + perror("Failed to set mark for outgoing packets"); + else + debug(4, "Set mark of outgoing packets of node '%s' to %u", n->name, n->mark); /* Bind socket for receiving */ if (bind(n->sd, (struct sockaddr *) &n->local, sizeof(struct sockaddr_in)))