Revision a92847e7 proto/ospf/rt.c

View differences:

proto/ospf/rt.c
9 9
#include "ospf.h"
10 10

  
11 11
void
12
init_stub_fib(struct fib_node *fn)
13
{
14
  struct stub_fib *sf=(struct stub_fib *)fn;
15

  
16
  sf->metric=LSINFINITY;
17
  sf->nhi=NULL;
18
}
19

  
20
void
12 21
ospf_rt_spfa(struct ospf_area *oa, struct proto *p)
13 22
{
14 23
  struct top_hash_entry *en, *nx;
15 24
  u32 i,*rts;
16 25
  struct ospf_lsa_rt *rt;
17 26
  struct ospf_lsa_rt_link *rtl,*rr;
27
  struct fib fib;
28
  struct stub_fib *sf;
18 29

  
19 30
  /*
20 31
   * First of all, mark all vertices as they are not in SPF
......
147 158
  DBG("Now calculating routes for stub networks.\n");
148 159

  
149 160
  /* Now calculate routes to stub networks */
161
  fib_init(&fib,p->pool,sizeof(struct stub_fib),16,init_stub_fib);
162
    /*FIXME 16? */
150 163

  
151 164
  WALK_SLIST_DELSAFE(SNODE en, SNODE nx, oa->lsal)
152 165
  {
......
162 175
      }
163 176
      if(en->lsa.type==LSA_T_RT)
164 177
      {
178
        ip_addr ip;
179

  
165 180
        DBG("Working on LSA: rt: %I, id: %I, type: %u\n",en->lsa.rt,en->lsa.id,en->lsa.type);
166 181
        rt=(struct ospf_lsa_rt *)en->lsa_body;
167 182
	if((rt->VEB)&(1>>LSA_RT_V)) oa->trcap=1;
......
172 187
	  if(rtl->type==LSART_STUB)
173 188
	  {
174 189
	    DBG("       Working on stub network: %I\n",rtl->id);
190
	    ip=ipa_from_u32(rtl->id);
175 191
	    /* Check destination and so on (pg 166) */
192
	    sf=fib_get(&fib,&ip,
193
	      ipa_mklen(ipa_from_u32(rtl->data)));
194

  
195
	    if(sf->metric>(en->dist+rtl->metric))
196
	    {
197
	      sf->metric=en->dist+rtl->metric;
198
	      calc_next_hop_fib(en,sf,p,oa);
199
	      if(sf->nhi!=NULL)
200
	      {
201
                net *ne;
202
                rta a0;
203
                rte *e;
204

  
205
                bzero(&a0, sizeof(a0));
206
           
207
                a0.proto=p;
208
                a0.source=RTS_OSPF;
209
                a0.scope=SCOPE_UNIVERSE;	/* What's this good for? */
210
                a0.cast=RTC_UNICAST;
211
                a0.dest=RTD_ROUTER;
212
                a0.flags=0;
213
                a0.aflags=0;
214
                a0.iface=sf->nhi;
215
                a0.gw=sf->nh;
216
                a0.from=sf->nh;		/* FIXME Just a test */
217
                ip=ipa_from_u32(rtl->id);
218
                ne=net_get(p->table, ip, ipa_mklen(ipa_from_u32(rtl->data)));
219
                e=rte_get_temp(&a0);
220
                e->u.ospf.metric1=sf->metric;
221
                e->u.ospf.metric2=0;
222
                e->u.ospf.tag=0;			/* FIXME Some config? */
223
                e->pflags = 0;
224
                e->net=ne;
225
                DBG("Modifying stub rt entry %I mask %I\n     (GW: %I, Iface: %s)\n",
226
                  ip,rtl->data,sf->nh,sf->nhi->name);
227
                rte_update(p->table, ne, p, e);
228
	      }
229
	    }
176 230
	  }
177 231
	}
178 232
      }
......
266 320
  en->nhi=par->nhi;
267 321
  DBG("     Next hop calculated: %I\n", en->nh);
268 322
}
323

  
324
void
325
calc_next_hop_fib(struct top_hash_entry *par, struct stub_fib *en,
326
  struct proto *p, struct ospf_area *oa)
327
{
328
  struct ospf_neighbor *neigh;
329
  struct proto_ospf *po=(struct proto_ospf *)p;
330
  DBG("     Next hop called\n");
331
  if(par==oa->rt) return;
332
  if(par->nhi==NULL)
333
  {
334
    neighbor *nn;
335
    DBG("     Next hop calculating for Fib\n");
336
    if(par->lsa.type!=LSA_T_RT) return;
337
    if((neigh=find_neigh_noifa(po,par->lsa.rt))==NULL) return;
338
    nn=neigh_find(p,&neigh->ip,0);
339
    DBG("     Next hop calculated: %I\n", nn->addr);
340
    en->nh=nn->addr;
341
    en->nhi=nn->iface;
342
    return;
343
  }
344
  en->nh=par->nh;
345
  en->nhi=par->nhi;
346
  DBG("     Next hop calculated: %I\n", en->nh);
347
}

Also available in: Unified diff