Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / lsupd.c @ 394acced

History | View | Annotate | Download (3 KB)

1
/*
2
 *        BIRD -- OSPF
3
 *
4
 *        (c) 2000 Ondrej Filip <feela@network.cz>
5
 *
6
 *        Can be freely distributed and used under the terms of the GNU GPL.
7
 */
8

    
9
#include "ospf.h"
10

    
11
void
12
ospf_lsupd_tx(struct ospf_neighbor *n)
13
{
14
  /* FIXME Go on! */
15
}
16

    
17
void                /* I send all I received in LSREQ */
18
ospf_lsupd_tx_list(struct ospf_neighbor *n, list *l)
19
{
20
  struct l_lsr_head *llsh;
21
  u16 len;
22
  u32 lsano;
23
  struct top_hash_entry *en;
24
  struct ospf_lsupd_packet *pk;
25
  struct ospf_packet *op;
26
  void *pktpos;
27
  u8 ii;
28
  u8 *jj=n->ifa->ip_sk->tbuf;
29

    
30
  if(HEAD(*l)==NULL) return;
31

    
32
  pk=(struct ospf_lsupd_packet *)n->ifa->ip_sk->tbuf;
33
  op=(struct ospf_packet *)n->ifa->ip_sk->tbuf;
34

    
35
  DBG("LSupd: 1st packet\n");
36
       
37
  fill_ospf_pkt_hdr(n->ifa, pk, LSUPD);
38
  len=SIPH+sizeof(struct ospf_lsupd_packet);
39
  lsano=0;
40
  pktpos=(pk+1);
41

    
42
  WALK_LIST(llsh, *l)
43
  {
44
    en=ospf_hash_find(n->ifa->oa->gr,llsh->lsh.id,llsh->lsh.rt,llsh->lsh.type);
45
    DBG("Sending ID=%u, Type=%u, RT=%u\n", llsh->lsh.id, llsh->lsh.type,
46
      llsh->lsh.rt);
47
    if((len+sizeof(struct ospf_lsa_header)+en->lsa.length)>n->ifa->iface->mtu)
48
    {
49
      pk->lsano=htonl(lsano);
50
      op->length=htons(len);
51
      ospf_pkt_finalize(n->ifa, op);
52
                       
53
      for(ii=0;ii<(len-SIPH);ii+=4)
54
        DBG("Out dump: %d,%d,%d,%d\n", *(jj+ii), *(jj+ii+1), *(jj+ii+2), *(jj+ii+3));
55

    
56
      sk_send_to(n->ifa->ip_sk,len, n->ip, OSPF_PROTO);
57

    
58
      DBG("LSupd: next packet\n");
59
      fill_ospf_pkt_hdr(n->ifa, pk, LSUPD);
60
      len=SIPH+sizeof(struct ospf_lsupd_packet);
61
      lsano=0;
62
      pktpos=(pk+1);
63
    }
64
    htonlsah(&(en->lsa), pktpos);
65
    pktpos=pktpos+sizeof(struct ospf_lsa_header);
66
    htonlsab(en->lsa_body, pktpos, en->lsa.type, en->lsa.length);
67
    pktpos=pktpos+en->lsa.length-sizeof(struct ospf_lsa_header);
68
    len=len+en->lsa.length;
69
    lsano++;
70
  }
71
  pk->lsano=htonl(lsano);
72
  op->length=htons(len-SIPH);
73
  ospf_pkt_finalize(n->ifa, op);
74

    
75
  for(ii=0;ii<(len-SIPH);ii+=4)
76
    DBG("Out dump: %d,%d,%d,%d\n", *(jj+ii), *(jj+ii+1), *(jj+ii+2), *(jj+ii+3));
77

    
78
  sk_send_to(n->ifa->ip_sk,len, n->ip, OSPF_PROTO);
79
  DBG("LSupd: sent\n");
80
}
81

    
82
void
83
ospf_lsupd_rx(struct ospf_lsupd_packet *ps, struct proto *p,
84
  struct ospf_iface *ifa, u16 size)
85
{
86
  u32 area,nrid,myrid;
87
  struct ospf_neighbor *n;
88
  struct ospf_lsa_header *lsa;
89
  u16 length;
90
  u8 i;
91

    
92
  nrid=ntohl(ps->ospf_packet.routerid);
93

    
94
  myrid=p->cf->global->router_id;
95

    
96
  if((n=find_neigh(ifa, nrid))==NULL)
97
  {
98
    debug("%s: Received lsupd from unknown neigbor! (%u)\n", p->name,
99
      nrid);
100
    return ;
101
  }
102
  if(n->state<NEIGHBOR_EXCHANGE)
103
  {
104
    debug("%s: Received lsupd in lesser state than EXCHANGE from (%u)\n",
105
      p->name);
106
    return;
107
  }
108

    
109
  lsa=(struct ospf_lsa_header *)(ps+1);
110
  area=htonl(ps->ospf_packet.areaid);
111
  for(i=0;i<ntohl(ps->lsano);i++)
112
  {
113
    if(lsa->checksum==lsasum_check(lsa,NULL,(struct proto_ospf *)p))
114
    {
115
      DBG("Processing update Type: %u ID: %u RT: %u\n",lsa->type,
116
        ntohl(lsa->id), ntohl(lsa->rt));
117
      /* FIXME Go on */
118
    }
119
    lsa=(struct ospf_lsa_header *)(((u8 *)lsa)+ntohs(lsa->length));
120
  }
121
}
122