Revision 5e8df049 proto/babel/packets.c

View differences:

proto/babel/packets.c
146 146
#define TLV_HDR(tlv,t,l) ({ tlv->type = t; tlv->length = l - sizeof(struct babel_tlv); })
147 147
#define TLV_HDR0(tlv,t) TLV_HDR(tlv, t, tlv_data[t].min_length)
148 148

  
149
#define BYTES(n) ((((uint) n) + 7) / 8)
149
#define NET_SIZE(n) BYTES(net_pxlen(n))
150

  
150 151

  
151 152
static inline u16
152 153
get_time16(const void *p)
......
161 162
  put_u16(p, v * BABEL_TIME_UNITS);
162 163
}
163 164

  
164
static inline ip6_addr
165
get_ip6_px(const void *p, uint plen)
165
static inline void
166
read_ip6_px(net_addr *n, const void *p, uint plen)
166 167
{
167 168
  ip6_addr addr = IPA_NONE;
168 169
  memcpy(&addr, p, BYTES(plen));
169
  return ip6_ntoh(addr);
170
  net_fill_ip6(n, ip6_ntoh(addr), plen);
170 171
}
171 172

  
172 173
static inline void
173
put_ip6_px(void *p, ip6_addr addr, uint plen)
174
put_ip6_px(void *p, net_addr *n)
174 175
{
175
  addr = ip6_hton(addr);
176
  memcpy(p, &addr, BYTES(plen));
176
  ip6_addr addr = ip6_hton(net6_prefix(n));
177
  memcpy(p, &addr, NET_SIZE(n));
177 178
}
178 179

  
179 180
static inline ip6_addr
......
480 481
    if (tlv->plen > 0)
481 482
      return PARSE_ERROR;
482 483

  
484
    if (msg->metric != 65535)
485
      return PARSE_ERROR;
486

  
483 487
    msg->wildcard = 1;
484 488
    break;
485 489

  
......
488 492
    return PARSE_IGNORE;
489 493

  
490 494
  case BABEL_AE_IP6:
491
    if (tlv->plen > MAX_PREFIX_LENGTH)
495
    if (tlv->plen > IP6_MAX_PREFIX_LENGTH)
492 496
      return PARSE_ERROR;
493 497

  
494 498
    /* Cannot omit data if there is no saved prefix */
......
499 503
    memcpy(buf, state->def_ip6_prefix, tlv->omitted);
500 504
    memcpy(buf + tlv->omitted, tlv->addr, len);
501 505

  
502
    msg->plen = tlv->plen;
503
    msg->prefix = ipa_from_ip6(get_ip6(buf));
506
    ip6_addr prefix = get_ip6(buf);
507
    net_fill_ip6(&msg->net, prefix, tlv->plen);
504 508

  
505 509
    if (tlv->flags & BABEL_FLAG_DEF_PREFIX)
506 510
    {
507
      put_ip6(state->def_ip6_prefix, msg->prefix);
511
      put_ip6(state->def_ip6_prefix, prefix);
508 512
      state->def_ip6_prefix_seen = 1;
509 513
    }
510 514

  
511 515
    if (tlv->flags & BABEL_FLAG_ROUTER_ID)
512 516
    {
513
      state->router_id = ((u64) _I2(msg->prefix)) << 32 | _I3(msg->prefix);
517
      state->router_id = ((u64) _I2(prefix)) << 32 | _I3(prefix);
514 518
      state->router_id_seen = 1;
515 519
    }
516 520
    break;
......
559 563
    tlv = (struct babel_tlv_update *) NEXT_TLV(tlv);
560 564
  }
561 565

  
562
  uint len = sizeof(struct babel_tlv_update) + BYTES(msg->plen);
566
  uint len = sizeof(struct babel_tlv_update) + NET_SIZE(&msg->net);
563 567

  
564 568
  if (len0 + len > max_len)
565 569
    return 0;
......
575 579
  else
576 580
  {
577 581
    tlv->ae = BABEL_AE_IP6;
578
    tlv->plen = msg->plen;
579
    put_ip6_px(tlv->addr, msg->prefix, msg->plen);
582
    tlv->plen = net6_pxlen(&msg->net);
583
    put_ip6_px(tlv->addr, &msg->net);
580 584
  }
581 585

  
582 586
  put_time16(&tlv->interval, msg->interval);
......
610 614
    return PARSE_IGNORE;
611 615

  
612 616
  case BABEL_AE_IP6:
613
    if (tlv->plen > MAX_PREFIX_LENGTH)
617
    if (tlv->plen > IP6_MAX_PREFIX_LENGTH)
614 618
      return PARSE_ERROR;
615 619

  
616 620
    if (TLV_OPT_LENGTH(tlv) < BYTES(tlv->plen))
617 621
      return PARSE_ERROR;
618 622

  
619
    msg->plen = tlv->plen;
620
    msg->prefix = get_ip6_px(tlv->addr, tlv->plen);
623
    read_ip6_px(&msg->net, tlv->addr, tlv->plen);
621 624
    return PARSE_SUCCESS;
622 625

  
623 626
  case BABEL_AE_IP6_LL:
......
637 640
  struct babel_tlv_route_request *tlv = (void *) hdr;
638 641
  struct babel_msg_route_request *msg = &m->route_request;
639 642

  
640
  uint len = sizeof(struct babel_tlv_route_request) + BYTES(msg->plen);
643
  uint len = sizeof(struct babel_tlv_route_request) + NET_SIZE(&msg->net);
641 644

  
642 645
  if (len > max_len)
643 646
    return 0;
......
652 655
  else
653 656
  {
654 657
    tlv->ae = BABEL_AE_IP6;
655
    tlv->plen = msg->plen;
656
    put_ip6_px(tlv->addr, msg->prefix, msg->plen);
658
    tlv->plen = net6_pxlen(&msg->net);
659
    put_ip6_px(tlv->addr, &msg->net);
657 660
  }
658 661

  
659 662
  return len;
......
685 688
    return PARSE_IGNORE;
686 689

  
687 690
  case BABEL_AE_IP6:
688
    if (tlv->plen > MAX_PREFIX_LENGTH)
691
    if (tlv->plen > IP6_MAX_PREFIX_LENGTH)
689 692
      return PARSE_ERROR;
690 693

  
691 694
    if (TLV_OPT_LENGTH(tlv) < BYTES(tlv->plen))
692 695
      return PARSE_ERROR;
693 696

  
694
    msg->plen = tlv->plen;
695
    msg->prefix = get_ip6_px(tlv->addr, tlv->plen);
697
    read_ip6_px(&msg->net, tlv->addr, tlv->plen);
696 698
    return PARSE_SUCCESS;
697 699

  
698 700
  case BABEL_AE_IP6_LL:
......
712 714
  struct babel_tlv_seqno_request *tlv = (void *) hdr;
713 715
  struct babel_msg_seqno_request *msg = &m->seqno_request;
714 716

  
715
  uint len = sizeof(struct babel_tlv_seqno_request) + BYTES(msg->plen);
717
  uint len = sizeof(struct babel_tlv_seqno_request) + NET_SIZE(&msg->net);
716 718

  
717 719
  if (len > max_len)
718 720
    return 0;
719 721

  
720 722
  TLV_HDR(tlv, BABEL_TLV_SEQNO_REQUEST, len);
721 723
  tlv->ae = BABEL_AE_IP6;
722
  tlv->plen = msg->plen;
724
  tlv->plen = net6_pxlen(&msg->net);
723 725
  put_u16(&tlv->seqno, msg->seqno);
724 726
  tlv->hop_count = msg->hop_count;
725 727
  put_u64(&tlv->router_id, msg->router_id);
726
  put_ip6_px(tlv->addr, msg->prefix, msg->plen);
728
  put_ip6_px(tlv->addr, &msg->net);
727 729

  
728 730
  return len;
729 731
}

Also available in: Unified diff