mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
netem: refactor mark -> fwmark
This commit is contained in:
parent
8da43f7070
commit
4660f97834
3 changed files with 13 additions and 11 deletions
|
@ -85,7 +85,7 @@ struct node {
|
|||
struct node_direction in, out;
|
||||
|
||||
#ifdef WITH_NETEM
|
||||
int mark; /**< Socket mark for netem, routing and filtering */
|
||||
int fwmark; /**< Socket mark for netem, routing and filtering */
|
||||
|
||||
struct rtnl_qdisc *tc_qdisc; /**< libnl3: Network emulator queuing discipline */
|
||||
struct rtnl_cls *tc_classifier; /**< libnl3: Firewall mark classifier */
|
||||
|
|
|
@ -73,12 +73,12 @@ int if_start(struct interface *i)
|
|||
//if_set_affinity(i, i->affinity);
|
||||
|
||||
/* Assign fwmark's to nodes which have netem options */
|
||||
int ret, mark = 0;
|
||||
int ret, fwmark = 0;
|
||||
for (size_t j = 0; j < vlist_length(&i->nodes); j++) {
|
||||
struct node *n = (struct node *) vlist_at(&i->nodes, j);
|
||||
|
||||
if (n->tc_qdisc)
|
||||
n->mark = 1 + mark++;
|
||||
if (n->tc_qdisc && n->fwmark < 0)
|
||||
n->fwmark = 1 + fwmark++;
|
||||
}
|
||||
|
||||
/* Abort if no node is using netem */
|
||||
|
@ -98,16 +98,16 @@ int if_start(struct interface *i)
|
|||
struct node *n = (struct node *) vlist_at(&i->nodes, j);
|
||||
|
||||
if (n->tc_qdisc) {
|
||||
ret = tc_mark(i, &n->tc_classifier, TC_HANDLE(1, n->mark), n->mark);
|
||||
ret = tc_mark(i, &n->tc_classifier, TC_HANDLE(1, n->fwmark), n->fwmark);
|
||||
if (ret)
|
||||
error("Failed to setup FW mark classifier: %s", nl_geterror(ret));
|
||||
|
||||
char *buf = tc_netem_print(n->tc_qdisc);
|
||||
debug(LOG_IF | 5, "Starting network emulation on interface '%s' for FW mark %u: %s",
|
||||
if_name(i), n->mark, buf);
|
||||
if_name(i), n->fwmark, buf);
|
||||
free(buf);
|
||||
|
||||
ret = tc_netem(i, &n->tc_qdisc, TC_HANDLE(0x1000+n->mark, 0), TC_HANDLE(1, n->mark));
|
||||
ret = tc_netem(i, &n->tc_qdisc, TC_HANDLE(0x1000+n->fwmark, 0), TC_HANDLE(1, n->fwmark));
|
||||
if (ret)
|
||||
error("Failed to setup netem qdisc: %s", nl_geterror(ret));
|
||||
}
|
||||
|
|
10
lib/node.c
10
lib/node.c
|
@ -225,6 +225,8 @@ int node_init(struct node *n, struct node_type *vt)
|
|||
n->_name = NULL;
|
||||
n->_name_long = NULL;
|
||||
|
||||
n->fwmark = -1;
|
||||
|
||||
#ifdef WITH_NETEM
|
||||
n->tc_qdisc = NULL;
|
||||
n->tc_classifier = NULL;
|
||||
|
@ -396,18 +398,18 @@ int node_start(struct node *n)
|
|||
|
||||
#ifdef __linux__
|
||||
/* Set fwmark for outgoing packets if netem is enabled for this node */
|
||||
if (n->mark) {
|
||||
if (n->fwmark) {
|
||||
int fds[16];
|
||||
int num_sds = node_netem_fds(n, fds);
|
||||
|
||||
for (int i = 0; i < num_sds; i++) {
|
||||
int fd = fds[i];
|
||||
|
||||
ret = setsockopt(fd, SOL_SOCKET, SO_MARK, &n->mark, sizeof(n->mark));
|
||||
ret = setsockopt(fd, SOL_SOCKET, SO_MARK, &n->fwmark, sizeof(n->fwmark));
|
||||
if (ret)
|
||||
serror("Failed to set FW mark for outgoing packets");
|
||||
else
|
||||
debug(LOG_SOCKET | 4, "Set FW mark for socket (sd=%u) to %u", fd, n->mark);
|
||||
debug(LOG_SOCKET | 4, "Set FW mark for socket (sd=%u) to %u", fd, n->fwmark);
|
||||
}
|
||||
}
|
||||
#endif /* __linux__ */
|
||||
|
@ -657,7 +659,7 @@ char * node_name_long(struct node *n)
|
|||
strcatf(&n->_name_long, ", out.netem=%s", n->tc_qdisc ? "yes" : "no");
|
||||
|
||||
if (n->tc_qdisc)
|
||||
strcatf(&n->_name_long, ", mark=%d", n->mark);
|
||||
strcatf(&n->_name_long, ", fwmark=%d", n->fwmark);
|
||||
#endif /* WITH_NETEM */
|
||||
|
||||
/* Append node-type specific details */
|
||||
|
|
Loading…
Add table
Reference in a new issue