ospfhello.c,v
来自「TCP-IP红宝书源代码」· C,V 代码 · 共 175 行
C,V
175 行
head 1.3;
access;
symbols;
locks
dls:1.3; strict;
comment @ * @;
1.3
date 97.09.21.19.28.38; author dls; state Dist;
branches;
next 1.2;
1.2
date 94.02.06.18.20.59; author dls; state Works;
branches;
next 1.1;
1.1
date 94.01.18.20.50.51; author dls; state Old;
branches;
next ;
desc
@@
1.3
log
@pre-3e code
@
text
@/* ospfhello.c - ospfhello */
#include <conf.h>
#include <kernel.h>
#include <network.h>
#include <ospf.h>
#define OSPFDELTA 10 /* OSPF "stagger" bounds (1/10 secs) */
/*------------------------------------------------------------------------
* ospfhello - send OSPF hello packets
*------------------------------------------------------------------------
*/
PROCESS ospfhello()
{
struct ospf_if *pif;
int ifn, rnd;
/* select initial "random" offset to stagger hello's */
rnd = nif[NI_PRIMARY].ni_ip % OSPFDELTA;
/* do state changes first so we can receive while waiting */
for (ifn=0; ifn<Net.nif; ++ifn) {
if (ifn == NI_LOCAL)
continue;
if (nif[ifn].ni_state != NIS_UP)
continue;
pif = &ospf_if[ifn];
switch (pif->if_type) {
case IFT_MULTI:
case IFT_BROADCAST:
if (pif->if_prio > 0) {
pif->if_twait = pif->if_rdintv;
pif->if_state = IFS_WAITING;
} else
pif->if_state = IFS_DROTHER;
break;
case IFT_PT2PT:
case IFT_VIRTUAL:
pif->if_state = IFS_PT2PT;
break;
default:
break;
}
}
while (1) {
sleep10(HELLOINTV*10 + rnd);
if (++rnd == OSPFDELTA)
rnd = -OSPFDELTA;
for (ifn=0; ifn<Net.nif; ++ifn) {
if (ifn == NI_LOCAL)
continue;
if (nif[ifn].ni_state != NIS_UP)
continue;
ospf_hsend(ifn);
}
}
}
@
1.2
log
@*** empty log message ***
@
text
@d20 1
a20 1
rnd = nif[NI_PRIMARY].ni_ip[IP_ALEN-1] % OSPFDELTA;
@
1.1
log
@Initial revision
@
text
@a9 8
struct neighbor nbtab[MAXNBR];
int ospf_nlock; /* neighbor table lock */
unsigned long ospf_rid;
/* these should be per area or per interface */
unsigned long ospf_aid, ospf_drouter, ospf_brouter;
unsigned char ospf_rprio;
d16 5
a20 5
struct ep *pep, *pepbase;
struct ip *pip;
struct ospf *po;
struct ospf_hello *poh;
int rnd;
d22 23
a44 6
ospf_nlock = screate(1);
blkcopy(&ospf_rid, nif[NI_PRIMARY].ni_ip, sizeof(po->ospf_rid));
pep = (struct ep *)getbuf(Net.netpool);
if ((int)pep == SYSERR) {
kprintf("ospfhello: getbuf failed (exiting)\n");
return;
a45 1
ospfhtmpl(pep);
a46 2
/* select initial "random" offset to stagger hello's */
rnd = nif[NI_PRIMARY].ni_ip[IP_ALEN-1] % OSPFDELTA;
a47 2
int i, nn, ifn;
a51 12
po->ospf_len = MINHELLOLEN;
po->ospf_cksum = 0;
poh->oh_drouter = ospf_drouter;
poh->oh_brouter = ospf_brouter;
wait(ospf_nlock);
for (i=0, nn=0; i<MAXNBR; ++i)
if (nbtab[i].nb_state >= NBS_INIT) {
poh->oh_neighbor[nn++] = nbtab[i].nb_rid;
po->ospf_len += sizeof(poh->oh_neighbor[0]);
}
signal(ospf_nlock);
a52 4
struct ep *peptmp;
struct ip *piptmp;
struct ospf *potmp;
d57 1
a57 9
blkcopy(&poh->oh_netmask, nif[ifn].ni_mask, IP_ALEN);
peptmp = (struct ep *)getbuf(Net.netpool);
if ((int)peptmp == SYSERR)
continue;
piptmp = (struct ip *)peptmp->ep_data;
blkcopy(piptmp, pip, IPMHLEN+po->ospf_len);
blkcopy(piptmp->ip_src, nif[ifn].ni_ip, IP_ALEN);
ipsend(nif[ifn].ni_brc, peptmp, po->ospf_len,
IPT_OSPF, IPP_INCTL, IP_TTL);
@
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?