Commit 38561437d056b11f679f9735d68ad597ba67dc84

Authored by Simon Horman
1 parent 4bfbfbf91f

ipvs: Use network byte order for sync message size

struct ip_vs_sync_mesg and ip_vs_sync_mesg_v0 are both sent across the wire
and used internally to store IPVS synchronisation messages.

Up until now the scheme used has been to convert the size field
to network byte order before sending a message on the wire and
convert it to host byte order when sending a message.

This patch changes that scheme to always treat the field
as being network byte order. This seems appropriate as
the structure is sent across the wire. And by consistently
treating the field has network byte order it is now possible
to take advantage of sparse to flag any future miss-use.

Acked-by: Julian Anastasov <ja@ssi.bg>
Acked-by: Hans Schillstrom <hans@schillstrom.com>
Signed-off-by: Simon Horman <horms@verge.net.au>

Showing 1 changed file with 8 additions and 13 deletions Side-by-side Diff

net/netfilter/ipvs/ip_vs_sync.c
... ... @@ -246,7 +246,7 @@
246 246 struct ip_vs_sync_mesg_v0 {
247 247 __u8 nr_conns;
248 248 __u8 syncid;
249   - __u16 size;
  249 + __be16 size;
250 250  
251 251 /* ip_vs_sync_conn entries start here */
252 252 };
... ... @@ -255,7 +255,7 @@
255 255 struct ip_vs_sync_mesg {
256 256 __u8 reserved; /* must be zero */
257 257 __u8 syncid;
258   - __u16 size;
  258 + __be16 size;
259 259 __u8 nr_conns;
260 260 __s8 version; /* SYNC_PROTO_VER */
261 261 __u16 spare;
... ... @@ -335,7 +335,7 @@
335 335 sb->mesg->reserved = 0; /* old nr_conns i.e. must be zero now */
336 336 sb->mesg->version = SYNC_PROTO_VER;
337 337 sb->mesg->syncid = ipvs->master_syncid;
338   - sb->mesg->size = sizeof(struct ip_vs_sync_mesg);
  338 + sb->mesg->size = htons(sizeof(struct ip_vs_sync_mesg));
339 339 sb->mesg->nr_conns = 0;
340 340 sb->mesg->spare = 0;
341 341 sb->head = (unsigned char *)sb->mesg + sizeof(struct ip_vs_sync_mesg);
... ... @@ -418,7 +418,7 @@
418 418 mesg = (struct ip_vs_sync_mesg_v0 *)sb->mesg;
419 419 mesg->nr_conns = 0;
420 420 mesg->syncid = ipvs->master_syncid;
421   - mesg->size = sizeof(struct ip_vs_sync_mesg_v0);
  421 + mesg->size = htons(sizeof(struct ip_vs_sync_mesg_v0));
422 422 sb->head = (unsigned char *)mesg + sizeof(struct ip_vs_sync_mesg_v0);
423 423 sb->end = (unsigned char *)mesg + ipvs->send_mesg_maxlen;
424 424 sb->firstuse = jiffies;
... ... @@ -582,7 +582,7 @@
582 582 }
583 583  
584 584 m->nr_conns++;
585   - m->size += len;
  585 + m->size = htons(ntohs(m->size) + len);
586 586 buff->head += len;
587 587  
588 588 /* check if there is a space for next one */
... ... @@ -693,7 +693,7 @@
693 693  
694 694 p = buff->head;
695 695 buff->head += pad + len;
696   - m->size += pad + len;
  696 + m->size = htons(ntohs(m->size) + pad + len);
697 697 /* Add ev. padding from prev. sync_conn */
698 698 while (pad--)
699 699 *(p++) = 0;
700 700  
... ... @@ -1175,10 +1175,8 @@
1175 1175 IP_VS_DBG(2, "BACKUP, message header too short\n");
1176 1176 return;
1177 1177 }
1178   - /* Convert size back to host byte order */
1179   - m2->size = ntohs(m2->size);
1180 1178  
1181   - if (buflen != m2->size) {
  1179 + if (buflen != ntohs(m2->size)) {
1182 1180 IP_VS_DBG(2, "BACKUP, bogus message size\n");
1183 1181 return;
1184 1182 }
... ... @@ -1544,10 +1542,7 @@
1544 1542 int msize;
1545 1543 int ret;
1546 1544  
1547   - msize = msg->size;
1548   -
1549   - /* Put size in network byte order */
1550   - msg->size = htons(msg->size);
  1545 + msize = ntohs(msg->size);
1551 1546  
1552 1547 ret = ip_vs_send_async(sock, (char *)msg, msize);
1553 1548 if (ret >= 0 || ret == -EAGAIN)