Revision 48e5f32d proto/ospf/packet.c

View differences:

proto/ospf/packet.c
39 39
unsigned
40 40
ospf_pkt_maxsize(struct ospf_iface *ifa)
41 41
{
42
  unsigned mtu = (ifa->type == OSPF_IT_VLINK) ? OSPF_VLINK_MTU : ifa->iface->mtu;
43 42
  unsigned headers = SIZE_OF_IP_HEADER;
44 43

  
45 44
#ifdef OSPFv2
......
47 46
    headers += OSPF_AUTH_CRYPT_SIZE;
48 47
#endif
49 48

  
50
  return mtu - headers;
49
  return ifa->tx_length - headers;
51 50
}
52 51

  
53 52
#ifdef OSPFv2
......
263 262
    return 1;
264 263

  
265 264
  DBG("OSPF: RX hook called (iface %s, src %I, dst %I)\n",
266
      sk->iface->name, sk->faddr, sk->laddr);
265
      sk->ifname, sk->faddr, sk->laddr);
267 266

  
268 267
  /* Initially, the packet is associated with the 'master' iface */
269 268
  struct ospf_iface *ifa = sk->data;
......
321 320
    return 1;
322 321
  }
323 322

  
324
  int osize = ntohs(ps->length);
325
  if ((unsigned) osize < sizeof(struct ospf_packet))
323
  uint plen = ntohs(ps->length);
324
  if ((plen < sizeof(struct ospf_packet)) || ((plen % 4) != 0))
326 325
  {
327
    log(L_ERR "%s%I - too low value in size field (%u bytes)", mesg, sk->faddr, osize);
326
    log(L_ERR "%s%I - invalid length (%u)", mesg, sk->faddr, plen);
328 327
    return 1;
329 328
  }
330 329

  
331
  if ((osize > size) || ((osize % 4) != 0))
330
  if (sk->flags & SKF_TRUNCATED)
332 331
  {
333
    log(L_ERR "%s%I - size field does not match (%d/%d)", mesg, sk->faddr, osize, size);
332
    log(L_WARN "%s%I - too large (%d/%d)", mesg, sk->faddr, plen, size);
333

  
334
    /* If we have dynamic buffers and received truncated message, we expand RX buffer */
335

  
336
    uint bs = plen + 256;
337
    bs = BIRD_ALIGN(bs, 1024);
338

  
339
    if (!ifa->cf->rx_buffer && (bs > sk->rbsize))
340
      sk_set_rbsize(sk, bs);
341

  
334 342
    return 1;
335 343
  }
336 344

  
337
  if ((unsigned) size > sk->rbsize)
345
  if (plen > size)
338 346
  {
339
    log(L_ERR "%s%I - too large (%d vs %d)", mesg, sk->faddr, size, sk->rbsize);
347
    log(L_ERR "%s%I - size field does not match (%d/%d)", mesg, sk->faddr, plen, size);
340 348
    return 1;
341 349
  }
342 350

  
......
349 357
#ifdef OSPFv2
350 358
  if ((ps->autype != htons(OSPF_AUTH_CRYPT)) &&
351 359
      (!ipsum_verify(ps, 16, (void *) ps + sizeof(struct ospf_packet),
352
		     osize - sizeof(struct ospf_packet), NULL)))
360
		     plen - sizeof(struct ospf_packet), NULL)))
353 361
  {
354 362
    log(L_ERR "%s%I - bad checksum", mesg, sk->faddr);
355 363
    return 1;
......
448 456
  if(!n && (ps->type != HELLO_P))
449 457
  {
450 458
    log(L_WARN "OSPF: Received non-hello packet from unknown neighbor (src %I, iface %s)",
451
	sk->faddr, ifa->iface->name);
459
	sk->faddr, ifa->ifname);
452 460
    return 1;
453 461
  }
454 462

  
......
495 503
  return 1;
496 504
}
497 505

  
506
/*
498 507
void
499 508
ospf_tx_hook(sock * sk)
500 509
{
501 510
  struct ospf_iface *ifa= (struct ospf_iface *) (sk->data);
502 511
//  struct proto *p = (struct proto *) (ifa->oa->po);
503
  log(L_ERR "OSPF: TX hook called on %s", ifa->iface->name);
512
  log(L_ERR "OSPF: TX hook called on %s", ifa->ifname);
504 513
}
514
*/
505 515

  
506 516
void
507 517
ospf_err_hook(sock * sk, int err)
508 518
{
509 519
  struct ospf_iface *ifa= (struct ospf_iface *) (sk->data);
510
//  struct proto *p = (struct proto *) (ifa->oa->po);
511
  log(L_ERR "OSPF: Socket error on %s: %M", ifa->iface->name, err);
520
  struct proto *p = &(ifa->oa->po->proto);
521
  log(L_ERR "%s: Socket error on %s: %M", p->name, ifa->ifname, err);
522
}
523

  
524
void
525
ospf_verr_hook(sock *sk, int err)
526
{
527
  struct proto_ospf *po = (struct proto_ospf *) (sk->data);
528
  struct proto *p =  &po->proto;
529
  log(L_ERR "%s: Vlink socket error: %M", p->name, err);
512 530
}
513 531

  
514 532
void
......
543 561
#endif
544 562

  
545 563
  ospf_pkt_finalize(ifa, pkt);
546
  if (sk->tbuf != sk->tpos)
547
    log(L_ERR "Aiee, old packet was overwritten in TX buffer");
548 564

  
549
  sk_send_to(sk, len, dst, 0);
565
  int done = sk_send_to(sk, len, dst, 0);
566
  if (!done)
567
    log(L_WARN "OSPF: TX queue full on %s", ifa->ifname);
550 568
}
551 569

  

Also available in: Unified diff