Commit 04047250 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Move enable_timestamps back into struct interface.

Since this causes flushbuf to take a struct interface, we're basically
carrying a struct interface all over the place.  Good.
parent 360f9e19
...@@ -573,7 +573,7 @@ main(int argc, char **argv) ...@@ -573,7 +573,7 @@ main(int argc, char **argv)
send_hello(ifp); send_hello(ifp);
send_wildcard_retraction(ifp); send_wildcard_retraction(ifp);
flushupdates(ifp); flushupdates(ifp);
flushbuf(&ifp->buf); flushbuf(&ifp->buf, ifp);
} }
FOR_ALL_INTERFACES(ifp) { FOR_ALL_INTERFACES(ifp) {
...@@ -586,7 +586,7 @@ main(int argc, char **argv) ...@@ -586,7 +586,7 @@ main(int argc, char **argv)
send_self_update(ifp); send_self_update(ifp);
send_multicast_request(ifp, NULL, 0, NULL, 0); send_multicast_request(ifp, NULL, 0, NULL, 0);
flushupdates(ifp); flushupdates(ifp);
flushbuf(&ifp->buf); flushbuf(&ifp->buf, ifp);
} }
debugf("Entering main loop.\n"); debugf("Entering main loop.\n");
...@@ -782,7 +782,7 @@ main(int argc, char **argv) ...@@ -782,7 +782,7 @@ main(int argc, char **argv)
if(ifp->buf.timeout.tv_sec != 0) { if(ifp->buf.timeout.tv_sec != 0) {
if(timeval_compare(&now, &ifp->buf.timeout) >= 0) { if(timeval_compare(&now, &ifp->buf.timeout) >= 0) {
flushupdates(ifp); flushupdates(ifp);
flushbuf(&ifp->buf); flushbuf(&ifp->buf, ifp);
} }
} }
} }
...@@ -790,7 +790,7 @@ main(int argc, char **argv) ...@@ -790,7 +790,7 @@ main(int argc, char **argv)
FOR_ALL_NEIGHBOURS(neigh) { FOR_ALL_NEIGHBOURS(neigh) {
if(neigh->buf.timeout.tv_sec != 0) { if(neigh->buf.timeout.tv_sec != 0) {
if(timeval_compare(&now, &neigh->buf.timeout) >= 0) { if(timeval_compare(&now, &neigh->buf.timeout) >= 0) {
flushbuf(&neigh->buf); flushbuf(&neigh->buf, neigh->ifp);
} }
} }
} }
...@@ -815,7 +815,7 @@ main(int argc, char **argv) ...@@ -815,7 +815,7 @@ main(int argc, char **argv)
/* Make sure that we expire quickly from our neighbours' /* Make sure that we expire quickly from our neighbours'
association caches. */ association caches. */
send_hello_noihu(ifp, 10); send_hello_noihu(ifp, 10);
flushbuf(&ifp->buf); flushbuf(&ifp->buf, ifp);
usleep(roughly(1000)); usleep(roughly(1000));
gettime(&now); gettime(&now);
} }
...@@ -825,7 +825,7 @@ main(int argc, char **argv) ...@@ -825,7 +825,7 @@ main(int argc, char **argv)
/* Make sure they got it. */ /* Make sure they got it. */
send_wildcard_retraction(ifp); send_wildcard_retraction(ifp);
send_hello_noihu(ifp, 1); send_hello_noihu(ifp, 1);
flushbuf(&ifp->buf); flushbuf(&ifp->buf, ifp);
usleep(roughly(10000)); usleep(roughly(10000));
gettime(&now); gettime(&now);
interface_up(ifp, 0); interface_up(ifp, 0);
......
...@@ -430,14 +430,14 @@ interface_up(struct interface *ifp, int up) ...@@ -430,14 +430,14 @@ interface_up(struct interface *ifp, int up)
ifp->max_rtt_penalty = 96; ifp->max_rtt_penalty = 96;
if(IF_CONF(ifp, enable_timestamps) == CONFIG_YES) if(IF_CONF(ifp, enable_timestamps) == CONFIG_YES)
ifp->buf.enable_timestamps = 1; ifp->flags |= IF_TIMESTAMPS;
else if(IF_CONF(ifp, enable_timestamps) == CONFIG_NO) else if(IF_CONF(ifp, enable_timestamps) == CONFIG_NO)
ifp->buf.enable_timestamps = 0; ifp->flags &= ~IF_TIMESTAMPS;
else if(type == IF_TYPE_TUNNEL) else if(type == IF_TYPE_TUNNEL)
ifp->buf.enable_timestamps = 1; ifp->flags |= IF_TIMESTAMPS;
else else
ifp->buf.enable_timestamps = 0; ifp->flags &= ~IF_TIMESTAMPS;
if(ifp->max_rtt_penalty > 0 && !ifp->buf.enable_timestamps) if(ifp->max_rtt_penalty > 0 && !(ifp->flags & IF_TIMESTAMPS))
fprintf(stderr, fprintf(stderr,
"Warning: max_rtt_penalty is set " "Warning: max_rtt_penalty is set "
"but timestamps are disabled on interface %s.\n", "but timestamps are disabled on interface %s.\n",
......
...@@ -72,8 +72,10 @@ struct interface_conf { ...@@ -72,8 +72,10 @@ struct interface_conf {
#define IF_FARAWAY (1 << 4) #define IF_FARAWAY (1 << 4)
/* Send most TLVs over unicast. */ /* Send most TLVs over unicast. */
#define IF_UNICAST (1 << 5) #define IF_UNICAST (1 << 5)
/* Send timestamps in Hello and IHU. */
#define IF_TIMESTAMPS (1 << 6)
/* Remain compatible with RFC 6126. */ /* Remain compatible with RFC 6126. */
#define IF_RFC6126 (1 << 6) #define IF_RFC6126 (1 << 7)
/* Only INTERFERING can appear on the wire. */ /* Only INTERFERING can appear on the wire. */
#define IF_CHANNEL_UNKNOWN 0 #define IF_CHANNEL_UNKNOWN 0
...@@ -87,7 +89,6 @@ struct buffered { ...@@ -87,7 +89,6 @@ struct buffered {
int size; int size;
int flush_interval; int flush_interval;
struct timeval timeout; struct timeval timeout;
char enable_timestamps;
char have_id; char have_id;
char have_nh; char have_nh;
char have_prefix; char have_prefix;
......
...@@ -444,7 +444,7 @@ parse_packet(const unsigned char *from, struct interface *ifp, ...@@ -444,7 +444,7 @@ parse_packet(const unsigned char *from, struct interface *ifp,
/* Content of the RTT sub-TLV on IHU messages. */ /* Content of the RTT sub-TLV on IHU messages. */
unsigned int hello_send_us = 0, hello_rtt_receive_time = 0; unsigned int hello_send_us = 0, hello_rtt_receive_time = 0;
if(ifp->buf.enable_timestamps) { if((ifp->flags & IF_TIMESTAMPS) != 0) {
/* We want to track exactly when we received this packet. */ /* We want to track exactly when we received this packet. */
gettime(&now); gettime(&now);
} }
...@@ -870,9 +870,9 @@ parse_packet(const unsigned char *from, struct interface *ifp, ...@@ -870,9 +870,9 @@ parse_packet(const unsigned char *from, struct interface *ifp,
} }
static int static int
fill_rtt_message(struct buffered *buf) fill_rtt_message(struct buffered *buf, struct interface *ifp)
{ {
if(buf->enable_timestamps && (buf->hello >= 0)) { if((ifp->flags & IF_TIMESTAMPS) != 0 && (buf->hello >= 0)) {
if(buf->buf[buf->hello + 8] == SUBTLV_PADN && if(buf->buf[buf->hello + 8] == SUBTLV_PADN &&
buf->buf[buf->hello + 9] == 4) { buf->buf[buf->hello + 9] == 4) {
unsigned int time; unsigned int time;
...@@ -893,7 +893,7 @@ fill_rtt_message(struct buffered *buf) ...@@ -893,7 +893,7 @@ fill_rtt_message(struct buffered *buf)
} }
void void
flushbuf(struct buffered *buf) flushbuf(struct buffered *buf, struct interface *ifp)
{ {
int rc; int rc;
...@@ -902,7 +902,7 @@ flushbuf(struct buffered *buf) ...@@ -902,7 +902,7 @@ flushbuf(struct buffered *buf)
if(buf->len > 0) { if(buf->len > 0) {
debugf(" (flushing %d buffered bytes)\n", buf->len); debugf(" (flushing %d buffered bytes)\n", buf->len);
DO_HTONS(packet_header + 2, buf->len); DO_HTONS(packet_header + 2, buf->len);
fill_rtt_message(buf); fill_rtt_message(buf, ifp);
rc = babel_send(protocol_socket, rc = babel_send(protocol_socket,
packet_header, sizeof(packet_header), packet_header, sizeof(packet_header),
buf->buf, buf->len, buf->buf, buf->len,
...@@ -943,17 +943,17 @@ schedule_flush_now(struct buffered *buf) ...@@ -943,17 +943,17 @@ schedule_flush_now(struct buffered *buf)
} }
static void static void
ensure_space(struct buffered *buf, int space) ensure_space(struct buffered *buf, struct interface *ifp, int space)
{ {
if(buf->size - buf->len < space) if(buf->size - buf->len < space)
flushbuf(buf); flushbuf(buf, ifp);
} }
static void static void
start_message(struct buffered *buf, int type, int len) start_message(struct buffered *buf, struct interface *ifp, int type, int len)
{ {
if(buf->size - buf->len < len + 2) if(buf->size - buf->len < len + 2)
flushbuf(buf); flushbuf(buf, ifp);
buf->buf[buf->len++] = type; buf->buf[buf->len++] = type;
buf->buf[buf->len++] = len; buf->buf[buf->len++] = len;
} }
...@@ -1000,7 +1000,7 @@ send_ack(struct neighbour *neigh, unsigned short nonce, unsigned short interval) ...@@ -1000,7 +1000,7 @@ send_ack(struct neighbour *neigh, unsigned short nonce, unsigned short interval)
{ {
debugf("Sending ack (%04x) to %s on %s.\n", debugf("Sending ack (%04x) to %s on %s.\n",
nonce, format_address(neigh->address), neigh->ifp->name); nonce, format_address(neigh->address), neigh->ifp->name);
start_message(&neigh->buf, MESSAGE_ACK, 2); start_message(&neigh->buf, neigh->ifp, MESSAGE_ACK, 2);
accumulate_short(&neigh->buf, nonce); accumulate_short(&neigh->buf, nonce);
end_message(&neigh->buf, MESSAGE_ACK, 2); end_message(&neigh->buf, MESSAGE_ACK, 2);
/* Roughly yields a value no larger than 3/2, so this meets the deadline */ /* Roughly yields a value no larger than 3/2, so this meets the deadline */
...@@ -1014,7 +1014,7 @@ send_hello_noihu(struct interface *ifp, unsigned interval) ...@@ -1014,7 +1014,7 @@ send_hello_noihu(struct interface *ifp, unsigned interval)
link quality estimation. */ link quality estimation. */
if(ifp->buf.hello >= 0) { if(ifp->buf.hello >= 0) {
flushupdates(ifp); flushupdates(ifp);
flushbuf(&ifp->buf); flushbuf(&ifp->buf, ifp);
} }
ifp->hello_seqno = seqno_plus(ifp->hello_seqno, 1); ifp->hello_seqno = seqno_plus(ifp->hello_seqno, 1);
...@@ -1026,19 +1026,20 @@ send_hello_noihu(struct interface *ifp, unsigned interval) ...@@ -1026,19 +1026,20 @@ send_hello_noihu(struct interface *ifp, unsigned interval)
debugf("Sending hello %d (%d) to %s.\n", debugf("Sending hello %d (%d) to %s.\n",
ifp->hello_seqno, interval, ifp->name); ifp->hello_seqno, interval, ifp->name);
start_message(&ifp->buf, MESSAGE_HELLO, ifp->buf.enable_timestamps ? 12 : 6); start_message(&ifp->buf, ifp, MESSAGE_HELLO,
(ifp->flags & IF_TIMESTAMPS) ? 12 : 6);
ifp->buf.hello = ifp->buf.len - 2; ifp->buf.hello = ifp->buf.len - 2;
accumulate_short(&ifp->buf, 0); accumulate_short(&ifp->buf, 0);
accumulate_short(&ifp->buf, ifp->hello_seqno); accumulate_short(&ifp->buf, ifp->hello_seqno);
accumulate_short(&ifp->buf, interval > 0xFFFF ? 0xFFFF : interval); accumulate_short(&ifp->buf, interval > 0xFFFF ? 0xFFFF : interval);
if(ifp->buf.enable_timestamps) { if((ifp->flags & IF_TIMESTAMPS) != 0) {
/* Sub-TLV containing the local time of emission. We use a /* Sub-TLV containing the local time of emission. We use a
Pad4 sub-TLV, which we'll fill just before sending. */ Pad4 sub-TLV, which we'll fill just before sending. */
accumulate_byte(&ifp->buf, SUBTLV_PADN); accumulate_byte(&ifp->buf, SUBTLV_PADN);
accumulate_byte(&ifp->buf, 4); accumulate_byte(&ifp->buf, 4);
accumulate_int(&ifp->buf, 0); accumulate_int(&ifp->buf, 0);
} }
end_message(&ifp->buf, MESSAGE_HELLO, ifp->buf.enable_timestamps ? 12 : 6); end_message(&ifp->buf, MESSAGE_HELLO, (ifp->flags & IF_TIMESTAMPS) ? 12 : 6);
} }
void void
...@@ -1080,7 +1081,7 @@ really_buffer_update(struct buffered *buf, struct interface *ifp, ...@@ -1080,7 +1081,7 @@ really_buffer_update(struct buffered *buf, struct interface *ifp,
metric = MIN(metric + add_metric, INFINITY); metric = MIN(metric + add_metric, INFINITY);
/* Worst case */ /* Worst case */
ensure_space(buf, 20 + 12 + 28 + 18); ensure_space(buf, ifp, 20 + 12 + 28 + 18);
v4 = plen >= 96 && v4mapped(prefix); v4 = plen >= 96 && v4mapped(prefix);
...@@ -1090,7 +1091,7 @@ really_buffer_update(struct buffered *buf, struct interface *ifp, ...@@ -1090,7 +1091,7 @@ really_buffer_update(struct buffered *buf, struct interface *ifp,
omit = 0; omit = 0;
if(!buf->have_nh || if(!buf->have_nh ||
memcmp(buf->nh, ifp->ipv4, 4) != 0) { memcmp(buf->nh, ifp->ipv4, 4) != 0) {
start_message(buf, MESSAGE_NH, 6); start_message(buf, ifp, MESSAGE_NH, 6);
accumulate_byte(buf, 1); accumulate_byte(buf, 1);
accumulate_byte(buf, 0); accumulate_byte(buf, 0);
accumulate_bytes(buf, ifp->ipv4, 4); accumulate_bytes(buf, ifp->ipv4, 4);
...@@ -1121,7 +1122,7 @@ really_buffer_update(struct buffered *buf, struct interface *ifp, ...@@ -1121,7 +1122,7 @@ really_buffer_update(struct buffered *buf, struct interface *ifp,
if(real_plen == 128 && memcmp(real_prefix + 8, id, 8) == 0) { if(real_plen == 128 && memcmp(real_prefix + 8, id, 8) == 0) {
flags |= 0x40; flags |= 0x40;
} else { } else {
start_message(buf, MESSAGE_ROUTER_ID, 10); start_message(buf, ifp, MESSAGE_ROUTER_ID, 10);
accumulate_short(buf, 0); accumulate_short(buf, 0);
accumulate_bytes(buf, id, 8); accumulate_bytes(buf, id, 8);
end_message(buf, MESSAGE_ROUTER_ID, 10); end_message(buf, MESSAGE_ROUTER_ID, 10);
...@@ -1137,7 +1138,7 @@ really_buffer_update(struct buffered *buf, struct interface *ifp, ...@@ -1137,7 +1138,7 @@ really_buffer_update(struct buffered *buf, struct interface *ifp,
if(is_ss) if(is_ss)
len += 3 + spb; len += 3 + spb;
start_message(buf, MESSAGE_UPDATE, len); start_message(buf, ifp, MESSAGE_UPDATE, len);
accumulate_byte(buf, v4 ? 1 : 2); accumulate_byte(buf, v4 ? 1 : 2);
accumulate_byte(buf, flags); accumulate_byte(buf, flags);
accumulate_byte(buf, real_plen); accumulate_byte(buf, real_plen);
...@@ -1513,9 +1514,9 @@ send_update_resend(struct interface *ifp, ...@@ -1513,9 +1514,9 @@ send_update_resend(struct interface *ifp,
} }
void void
buffer_wildcard_retraction(struct buffered *buf) buffer_wildcard_retraction(struct buffered *buf, struct interface *ifp)
{ {
start_message(buf, MESSAGE_UPDATE, 10); start_message(buf, ifp, MESSAGE_UPDATE, 10);
accumulate_byte(buf, 0); accumulate_byte(buf, 0);
accumulate_byte(buf, 0); accumulate_byte(buf, 0);
accumulate_byte(buf, 0); accumulate_byte(buf, 0);
...@@ -1546,11 +1547,11 @@ send_wildcard_retraction(struct interface *ifp) ...@@ -1546,11 +1547,11 @@ send_wildcard_retraction(struct interface *ifp)
struct neighbour *neigh; struct neighbour *neigh;
FOR_ALL_NEIGHBOURS(neigh) { FOR_ALL_NEIGHBOURS(neigh) {
if(neigh->ifp == ifp) { if(neigh->ifp == ifp) {
buffer_wildcard_retraction(&neigh->buf); buffer_wildcard_retraction(&neigh->buf, neigh->ifp);
} }
} }
} else { } else {
buffer_wildcard_retraction(&ifp->buf); buffer_wildcard_retraction(&ifp->buf, ifp);
} }
} }
...@@ -1591,7 +1592,7 @@ send_self_update(struct interface *ifp) ...@@ -1591,7 +1592,7 @@ send_self_update(struct interface *ifp)
} }
void void
buffer_ihu(struct buffered *buf, unsigned short rxcost, buffer_ihu(struct buffered *buf, struct interface *ifp, unsigned short rxcost,
unsigned short interval, const unsigned char *address, unsigned short interval, const unsigned char *address,
int rtt_data, unsigned int t1, unsigned int t2) int rtt_data, unsigned int t1, unsigned int t2)
{ {
...@@ -1600,7 +1601,7 @@ buffer_ihu(struct buffered *buf, unsigned short rxcost, ...@@ -1600,7 +1601,7 @@ buffer_ihu(struct buffered *buf, unsigned short rxcost,
ll = linklocal(address); ll = linklocal(address);
msglen = (ll ? 14 : 200) + (rtt_data ? 10 : 0); msglen = (ll ? 14 : 200) + (rtt_data ? 10 : 0);
start_message(buf, MESSAGE_IHU, msglen); start_message(buf, ifp, MESSAGE_IHU, msglen);
accumulate_byte(buf, ll ? 3 : 2); accumulate_byte(buf, ll ? 3 : 2);
accumulate_byte(buf, 0); accumulate_byte(buf, 0);
accumulate_short(buf, rxcost); accumulate_short(buf, rxcost);
...@@ -1659,7 +1660,7 @@ send_ihu(struct neighbour *neigh, struct interface *ifp) ...@@ -1659,7 +1660,7 @@ send_ihu(struct neighbour *neigh, struct interface *ifp)
neigh->ifp->name, neigh->ifp->name,
format_address(neigh->address)); format_address(neigh->address));
if(ifp->buf.enable_timestamps && neigh->hello_send_us && if((ifp->flags & IF_TIMESTAMPS) != 0 && neigh->hello_send_us &&
/* Checks whether the RTT data is not too old to be sent. */ /* Checks whether the RTT data is not too old to be sent. */
timeval_minus_msec(&now, &neigh->hello_rtt_receive_time) < 1000000) { timeval_minus_msec(&now, &neigh->hello_rtt_receive_time) < 1000000) {
send_rtt_data = 1; send_rtt_data = 1;
...@@ -1668,7 +1669,7 @@ send_ihu(struct neighbour *neigh, struct interface *ifp) ...@@ -1668,7 +1669,7 @@ send_ihu(struct neighbour *neigh, struct interface *ifp)
send_rtt_data = 0; send_rtt_data = 0;
} }
buffer_ihu(&ifp->buf, rxcost, interval, neigh->address, buffer_ihu(&ifp->buf, ifp, rxcost, interval, neigh->address,
send_rtt_data, neigh->hello_send_us, send_rtt_data, neigh->hello_send_us,
time_us(neigh->hello_rtt_receive_time)); time_us(neigh->hello_rtt_receive_time));
...@@ -1703,7 +1704,7 @@ send_request(struct buffered *buf, struct interface *ifp, ...@@ -1703,7 +1704,7 @@ send_request(struct buffered *buf, struct interface *ifp,
if(!prefix) { if(!prefix) {
assert(!src_prefix); assert(!src_prefix);
debugf("sending request for any.\n"); debugf("sending request for any.\n");
start_message(buf, MESSAGE_REQUEST, 2); start_message(buf, ifp, MESSAGE_REQUEST, 2);
accumulate_byte(buf, 0); accumulate_byte(buf, 0);
accumulate_byte(buf, 0); accumulate_byte(buf, 0);
end_message(buf, MESSAGE_REQUEST, 2); end_message(buf, MESSAGE_REQUEST, 2);
...@@ -1719,7 +1720,7 @@ send_request(struct buffered *buf, struct interface *ifp, ...@@ -1719,7 +1720,7 @@ send_request(struct buffered *buf, struct interface *ifp,
spb = v4 ? ((src_plen - 96) + 7) / 8 : (src_plen + 7) / 8; spb = v4 ? ((src_plen - 96) + 7) / 8 : (src_plen + 7) / 8;
len = 2 + pb + (is_ss ? 3 + spb : 0); len = 2 + pb + (is_ss ? 3 + spb : 0);
start_message(buf, MESSAGE_REQUEST, len); start_message(buf, ifp, MESSAGE_REQUEST, len);
accumulate_byte(buf, v4 ? 1 : 2); accumulate_byte(buf, v4 ? 1 : 2);
accumulate_byte(buf, v4 ? plen - 96 : plen); accumulate_byte(buf, v4 ? plen - 96 : plen);
if(v4) if(v4)
...@@ -1806,7 +1807,7 @@ send_multihop_request(struct buffered *buf, struct interface *ifp, ...@@ -1806,7 +1807,7 @@ send_multihop_request(struct buffered *buf, struct interface *ifp,
spb = v4 ? ((src_plen - 96) + 7) / 8 : (src_plen + 7) / 8; spb = v4 ? ((src_plen - 96) + 7) / 8 : (src_plen + 7) / 8;
len = 6 + 8 + pb + (is_ss ? 3 + spb : 0); len = 6 + 8 + pb + (is_ss ? 3 + spb : 0);
start_message(buf, MESSAGE_MH_REQUEST, len); start_message(buf, ifp, MESSAGE_MH_REQUEST, len);
accumulate_byte(buf, v4 ? 1 : 2); accumulate_byte(buf, v4 ? 1 : 2);
accumulate_byte(buf, v4 ? plen - 96 : plen); accumulate_byte(buf, v4 ? plen - 96 : plen);
accumulate_short(buf, seqno); accumulate_short(buf, seqno);
......
...@@ -52,7 +52,7 @@ extern unsigned char packet_header[4]; ...@@ -52,7 +52,7 @@ extern unsigned char packet_header[4];
void parse_packet(const unsigned char *from, struct interface *ifp, void parse_packet(const unsigned char *from, struct interface *ifp,
const unsigned char *packet, int packetlen); const unsigned char *packet, int packetlen);
void flushbuf(struct buffered *buf); void flushbuf(struct buffered *buf, struct interface *ifp);
void flushupdates(struct interface *ifp); void flushupdates(struct interface *ifp);
void send_ack(struct neighbour *neigh, unsigned short nonce, void send_ack(struct neighbour *neigh, unsigned short nonce,
unsigned short interval); unsigned short interval);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment