Commit 804aab54 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek Committed by Juliusz Chroboczek

Simplify formatting of updates.

parent 4d30fed6
...@@ -1054,27 +1054,21 @@ send_hello(struct interface *ifp) ...@@ -1054,27 +1054,21 @@ send_hello(struct interface *ifp)
static void static void
really_buffer_update(struct buffered *buf, struct interface *ifp, really_buffer_update(struct buffered *buf, struct interface *ifp,
const unsigned char *id, const unsigned char *id,
const unsigned char *prefix, unsigned char plen, const unsigned char *prefix, unsigned char plen,
const unsigned char *src_prefix, unsigned char src_plen, const unsigned char *src_prefix, unsigned char src_plen,
unsigned short seqno, unsigned short metric, unsigned short seqno, unsigned short metric,
unsigned char *channels, int channels_len) unsigned char *channels, int channels_len)
{ {
int add_metric, v4, real_plen, omit = 0; int add_metric, v4, real_plen, omit, channels_size, len;
const unsigned char *real_prefix; const unsigned char *real_prefix;
unsigned short flags = 0; unsigned short flags = 0;
int channels_size;
if(!is_default(src_prefix, src_plen)) { if(!is_default(src_prefix, src_plen)) {
debugf("Attempted to send source-specific TLV -- not implemented yet\n"); debugf("Attempted to send source-specific TLV -- not implemented yet\n");
return; return;
} }
if(diversity_kind != DIVERSITY_CHANNEL)
channels_len = -1;
channels_size = channels_len >= 0 ? channels_len + 2 : 0;
if(!if_up(ifp)) if(!if_up(ifp))
return; return;
...@@ -1092,6 +1086,7 @@ really_buffer_update(struct buffered *buf, struct interface *ifp, ...@@ -1092,6 +1086,7 @@ really_buffer_update(struct buffered *buf, struct interface *ifp,
if(v4) { if(v4) {
if(!ifp->ipv4) if(!ifp->ipv4)
return; return;
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, MESSAGE_NH, 6);
...@@ -1106,6 +1101,7 @@ really_buffer_update(struct buffered *buf, struct interface *ifp, ...@@ -1106,6 +1101,7 @@ really_buffer_update(struct buffered *buf, struct interface *ifp,
real_prefix = prefix + 12; real_prefix = prefix + 12;
real_plen = plen - 96; real_plen = plen - 96;
} else { } else {
omit = 0;
if(buf->have_prefix) { if(buf->have_prefix) {
while(omit < plen / 8 && while(omit < plen / 8 &&
buf->prefix[omit] == prefix[omit]) buf->prefix[omit] == prefix[omit])
...@@ -1130,9 +1126,11 @@ really_buffer_update(struct buffered *buf, struct interface *ifp, ...@@ -1130,9 +1126,11 @@ really_buffer_update(struct buffered *buf, struct interface *ifp,
buf->have_id = 1; buf->have_id = 1;
} }
start_message(buf, channels_size = diversity_kind == DIVERSITY_CHANNEL && channels_len >= 0 ?
MESSAGE_UPDATE, 10 + (real_plen + 7) / 8 - omit + channels_len + 2 : 0;
channels_size); len = 10 + (real_plen + 7) / 8 - omit + channels_size;
start_message(buf, 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);
...@@ -1142,13 +1140,12 @@ really_buffer_update(struct buffered *buf, struct interface *ifp, ...@@ -1142,13 +1140,12 @@ really_buffer_update(struct buffered *buf, struct interface *ifp,
accumulate_short(buf, metric); accumulate_short(buf, metric);
accumulate_bytes(buf, real_prefix + omit, (real_plen + 7) / 8 - omit); accumulate_bytes(buf, real_prefix + omit, (real_plen + 7) / 8 - omit);
/* Note that an empty channels TLV is different from no such TLV. */ /* Note that an empty channels TLV is different from no such TLV. */
if(channels_len >= 0) { if(channels_size > 0) {
accumulate_byte(buf, 2); accumulate_byte(buf, 2);
accumulate_byte(buf, channels_len); accumulate_byte(buf, channels_len);
accumulate_bytes(buf, channels, channels_len); accumulate_bytes(buf, channels, channels_len);
} }
end_message(buf, MESSAGE_UPDATE, 10 + (real_plen + 7) / 8 - omit + end_message(buf, MESSAGE_UPDATE, len);
channels_size);
if(flags & 0x80) { if(flags & 0x80) {
memcpy(buf->prefix, prefix, 16); memcpy(buf->prefix, prefix, 16);
buf->have_prefix = 1; buf->have_prefix = 1;
...@@ -1705,6 +1702,7 @@ send_request(struct buffered *buf, ...@@ -1705,6 +1702,7 @@ send_request(struct buffered *buf,
v4 = plen >= 96 && v4mapped(prefix); v4 = plen >= 96 && v4mapped(prefix);
pb = v4 ? ((plen - 96) + 7) / 8 : (plen + 7) / 8; pb = v4 ? ((plen - 96) + 7) / 8 : (plen + 7) / 8;
len = 2 + pb; len = 2 + pb;
start_message(buf, MESSAGE_REQUEST, len); start_message(buf, 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);
......
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