Statistics
| Branch: | Revision:

iof-bird-daemon / proto / ospf / lsreq.c @ 58313b24

History | View | Annotate | Download (2.95 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_lsreq_tx(struct ospf_neighbor *n)
13
{
14
  snode *sn;
15
  struct top_hash_entry *en;
16
  struct ospf_lsreq_packet *pk;
17
  struct ospf_packet *op;
18
  struct ospf_lsreq_header *lsh;
19
  u16 length;
20
  int i,j;
21

    
22
  pk=(struct ospf_lsreq_packet *)n->ifa->ip_sk->tbuf;
23
  op=(struct ospf_packet *)n->ifa->ip_sk->tbuf;
24

    
25
  fill_ospf_pkt_hdr(n->ifa, pk, LSREQ);
26

    
27
  sn=SHEAD(n->lsrql);
28
  if(EMPTY_SLIST(n->lsrql))
29
  {
30
    if(n->state==NEIGHBOR_LOADING) ospf_neigh_sm(n, INM_LOADDONE);
31
    return;
32
  }
33
 
34
  i=j=(n->ifa->iface->mtu-SIPH-sizeof(struct ospf_lsreq_packet))/
35
    sizeof(struct ospf_lsreq_header);
36
  lsh=(struct ospf_lsreq_header *)(pk+1);
37
  
38
  for(;i>0;i--)
39
  {
40
    en=(struct top_hash_entry *)sn;
41
    lsh->padd1=0; lsh->padd2=0;
42
    lsh->type=en->lsa.type;
43
    lsh->rt=htonl(en->lsa.rt);
44
    lsh->id=htonl(en->lsa.id);
45
    DBG("Requesting %uth LSA: Type: %u, Id: %u, RT: %u\n",i, en->lsa.type,
46
                    en->lsa.id, en->lsa.rt);
47
    lsh++;
48
    if(sn==STAIL(n->lsrql)) break;
49
    sn=sn->next;
50
  }
51
  if(i!=0) i--;
52

    
53
  length=sizeof(struct ospf_lsreq_packet)+(j-i)*sizeof(struct ospf_lsreq_header);
54
  op->length=htons(length);
55
  ospf_pkt_finalize(n->ifa, op);
56
  sk_send_to(n->ifa->ip_sk,length, n->ip, OSPF_PROTO);
57
  DBG("Lsreq send to: %u\n", n->rid);
58
}
59

    
60
void
61
lsrr_timer_hook(timer *timer)
62
{
63
  struct ospf_iface *ifa;
64
  struct proto *p;
65
  struct ospf_neighbor *n;
66

    
67
  n=(struct ospf_neighbor *)timer->data;
68
  ifa=n->ifa;
69
  p=(struct proto *)(ifa->proto);
70
  debug("%s: LSRR timer fired on interface %s for neigh: %u.\n",
71
    p->name, ifa->iface->name, n->rid);
72
  ospf_lsreq_tx(n);
73
}
74

    
75
void
76
ospf_lsreq_rx(struct ospf_lsreq_packet *ps, struct proto *p,
77
  struct ospf_iface *ifa, u16 size)
78
{
79
  u32 nrid, myrid;
80
  struct ospf_neighbor *n;
81
  struct ospf_lsreq_header *lsh;
82
  struct l_lsr_head *llsh;
83
  list uplist;
84
  slab *upslab;
85
  int length;
86
  u8 i;
87

    
88
  nrid=ntohl(ps->ospf_packet.routerid);
89

    
90
  myrid=p->cf->global->router_id;
91

    
92
  if((n=find_neigh(ifa, nrid))==NULL)
93
  {
94
    debug("%s: Received lsreq from unknown neigbor! (%u)\n", p->name,
95
      nrid);
96
    return ;
97
  }
98
  if(n->state<NEIGHBOR_EXCHANGE) debug("%s: Ignoring it.\n", p->name);
99

    
100
  length=htons(ps->ospf_packet.length);
101
  lsh=(void *)(ps+1);
102
  init_list(&uplist);
103
  upslab=sl_new(p->pool,sizeof(struct l_lsr_head));
104

    
105
  for(i=0;i<(length-sizeof(struct ospf_lsreq_packet))/
106
    sizeof(struct ospf_lsreq_header);i++);
107
  {
108
    DBG("Processing LSA: ID=%u, Type=%u, Router=%u\n", ntohl(lsh->id),
109
    lsh->type, ntohl(lsh->rt));
110
    llsh=sl_alloc(upslab);
111
    llsh->lsh.id=ntohl(lsh->id);
112
    llsh->lsh.rt=ntohl(lsh->rt);
113
    llsh->lsh.type=lsh->type;
114
    add_tail(&uplist, NODE llsh);
115
    if(ospf_hash_find(n->ifa->oa->gr, llsh->lsh.id, llsh->lsh.rt,
116
      llsh->lsh.type)==NULL)
117
    {
118
      ospf_neigh_sm(n,INM_BADLSREQ);
119
      rfree(upslab);
120
      return;
121
    }
122
  }
123
  ospf_lsupd_tx_list(n, &uplist);
124
  rfree(upslab);
125
}
126