2 * OSPF Sending and Receiving OSPF Packets.
3 * Copyright (C) 1999, 2000 Toshiaki Takada
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
31 #include "sockunion.h"
37 #include "ospfd/ospfd.h"
38 #include "ospfd/ospf_network.h"
39 #include "ospfd/ospf_interface.h"
40 #include "ospfd/ospf_ism.h"
41 #include "ospfd/ospf_asbr.h"
42 #include "ospfd/ospf_lsa.h"
43 #include "ospfd/ospf_lsdb.h"
44 #include "ospfd/ospf_neighbor.h"
45 #include "ospfd/ospf_nsm.h"
46 #include "ospfd/ospf_packet.h"
47 #include "ospfd/ospf_spf.h"
48 #include "ospfd/ospf_flood.h"
49 #include "ospfd/ospf_dump.h"
51 static void ospf_ls_ack_send_list (struct ospf_interface
*, struct list
*,
54 /* Packet Type String. */
55 const char *ospf_packet_type_str
[] =
59 "Database Description",
62 "Link State Acknowledgment",
65 extern int in_cksum (void *ptr
, int nbytes
);
67 /* OSPF authentication checking function */
69 ospf_auth_type (struct ospf_interface
*oi
)
73 if (OSPF_IF_PARAM (oi
, auth_type
) == OSPF_AUTH_NOTSET
)
74 auth_type
= oi
->area
->auth_type
;
76 auth_type
= OSPF_IF_PARAM (oi
, auth_type
);
78 /* Handle case where MD5 key list is not configured aka Cisco */
79 if (auth_type
== OSPF_AUTH_CRYPTOGRAPHIC
&&
80 list_isempty (OSPF_IF_PARAM (oi
, auth_crypt
)))
81 return OSPF_AUTH_NULL
;
87 /* forward output pointer. */
89 ospf_output_forward (struct stream
*s
, int size
)
95 ospf_packet_new (size_t size
)
97 struct ospf_packet
*new;
99 new = XCALLOC (MTYPE_OSPF_PACKET
, sizeof (struct ospf_packet
));
100 new->s
= stream_new (size
);
106 ospf_packet_free (struct ospf_packet
*op
)
111 XFREE (MTYPE_OSPF_PACKET
, op
);
119 struct ospf_fifo
*new;
121 new = XCALLOC (MTYPE_OSPF_FIFO
, sizeof (struct ospf_fifo
));
125 /* Add new packet to fifo. */
127 ospf_fifo_push (struct ospf_fifo
*fifo
, struct ospf_packet
*op
)
130 fifo
->tail
->next
= op
;
139 /* Delete first packet from fifo. */
141 ospf_fifo_pop (struct ospf_fifo
*fifo
)
143 struct ospf_packet
*op
;
149 fifo
->head
= op
->next
;
151 if (fifo
->head
== NULL
)
160 /* Return first fifo entry. */
162 ospf_fifo_head (struct ospf_fifo
*fifo
)
167 /* Flush ospf packet fifo. */
169 ospf_fifo_flush (struct ospf_fifo
*fifo
)
171 struct ospf_packet
*op
;
172 struct ospf_packet
*next
;
174 for (op
= fifo
->head
; op
; op
= next
)
177 ospf_packet_free (op
);
179 fifo
->head
= fifo
->tail
= NULL
;
183 /* Free ospf packet fifo. */
185 ospf_fifo_free (struct ospf_fifo
*fifo
)
187 ospf_fifo_flush (fifo
);
189 XFREE (MTYPE_OSPF_FIFO
, fifo
);
193 ospf_packet_add (struct ospf_interface
*oi
, struct ospf_packet
*op
)
195 /* Add packet to end of queue. */
196 ospf_fifo_push (oi
->obuf
, op
);
198 /* Debug of packet fifo*/
199 /* ospf_fifo_debug (oi->obuf); */
203 ospf_packet_delete (struct ospf_interface
*oi
)
205 struct ospf_packet
*op
;
207 op
= ospf_fifo_pop (oi
->obuf
);
210 ospf_packet_free (op
);
214 ospf_stream_copy (struct stream
*new, struct stream
*s
)
220 memcpy (new->data
, s
->data
, stream_get_endp (s
));
226 ospf_packet_dup (struct ospf_packet
*op
)
228 struct ospf_packet
*new;
230 if (stream_get_endp(op
->s
) != op
->length
)
231 zlog_warn ("ospf_packet_dup stream %ld ospf_packet %d size mismatch",
232 STREAM_SIZE(op
->s
), op
->length
);
234 /* Reserve space for MD5 authentication that may be added later. */
235 new = ospf_packet_new (stream_get_endp(op
->s
) + OSPF_AUTH_MD5_SIZE
);
236 ospf_stream_copy (new->s
, op
->s
);
239 new->length
= op
->length
;
246 ospf_packet_authspace (struct ospf_interface
*oi
)
250 if ( ospf_auth_type (oi
) == OSPF_AUTH_CRYPTOGRAPHIC
)
251 auth
= OSPF_AUTH_MD5_SIZE
;
257 ospf_packet_max (struct ospf_interface
*oi
)
261 max
= oi
->ifp
->mtu
- ospf_packet_authspace(oi
);
263 max
-= (OSPF_HEADER_SIZE
+ sizeof (struct ip
));
270 ospf_check_md5_digest (struct ospf_interface
*oi
, struct stream
*s
,
275 unsigned char digest
[OSPF_AUTH_MD5_SIZE
];
276 unsigned char *pdigest
;
277 struct crypt_key
*ck
;
278 struct ospf_header
*ospfh
;
279 struct ospf_neighbor
*nbr
;
282 ibuf
= STREAM_PNT (s
);
283 ospfh
= (struct ospf_header
*) ibuf
;
285 /* Get pointer to the end of the packet. */
286 pdigest
= ibuf
+ length
;
288 /* Get secret key. */
289 ck
= ospf_crypt_key_lookup (OSPF_IF_PARAM (oi
, auth_crypt
),
290 ospfh
->u
.crypt
.key_id
);
293 zlog_warn ("interface %s: ospf_check_md5 no key %d",
294 IF_NAME (oi
), ospfh
->u
.crypt
.key_id
);
298 /* check crypto seqnum. */
299 nbr
= ospf_nbr_lookup_by_routerid (oi
->nbrs
, &ospfh
->router_id
);
301 if (nbr
&& ntohl(nbr
->crypt_seqnum
) > ntohl(ospfh
->u
.crypt
.crypt_seqnum
))
303 zlog_warn ("interface %s: ospf_check_md5 bad sequence %d (expect %d)",
305 ntohl(ospfh
->u
.crypt
.crypt_seqnum
),
306 ntohl(nbr
->crypt_seqnum
));
310 /* Generate a digest for the ospf packet - their digest + our digest. */
312 md5_process_bytes (ibuf
, length
, &ctx
);
313 md5_process_bytes (ck
->auth_key
, OSPF_AUTH_MD5_SIZE
, &ctx
);
314 md5_finish_ctx (&ctx
, digest
);
316 /* compare the two */
317 if (memcmp (pdigest
, digest
, OSPF_AUTH_MD5_SIZE
))
319 zlog_warn ("interface %s: ospf_check_md5 checksum mismatch",
324 /* save neighbor's crypt_seqnum */
326 nbr
->crypt_seqnum
= ospfh
->u
.crypt
.crypt_seqnum
;
330 /* This function is called from ospf_write(), it will detect the
331 authentication scheme and if it is MD5, it will change the sequence
332 and update the MD5 digest. */
334 ospf_make_md5_digest (struct ospf_interface
*oi
, struct ospf_packet
*op
)
336 struct ospf_header
*ospfh
;
337 unsigned char digest
[OSPF_AUTH_MD5_SIZE
];
340 unsigned long oldputp
;
342 struct crypt_key
*ck
;
345 ibuf
= STREAM_DATA (op
->s
);
346 ospfh
= (struct ospf_header
*) ibuf
;
348 if (ntohs (ospfh
->auth_type
) != OSPF_AUTH_CRYPTOGRAPHIC
)
351 /* We do this here so when we dup a packet, we don't have to
352 waste CPU rewriting other headers. */
353 t
= (time(NULL
) & 0xFFFFFFFF);
354 oi
->crypt_seqnum
= ( t
> oi
->crypt_seqnum
? t
: oi
->crypt_seqnum
++);
355 ospfh
->u
.crypt
.crypt_seqnum
= htonl (oi
->crypt_seqnum
);
357 /* Get MD5 Authentication key from auth_key list. */
358 if (list_isempty (OSPF_IF_PARAM (oi
, auth_crypt
)))
359 auth_key
= (char *) "";
362 ck
= getdata (OSPF_IF_PARAM (oi
, auth_crypt
)->tail
);
363 auth_key
= (char *) ck
->auth_key
;
366 /* Generate a digest for the entire packet + our secret key. */
368 md5_process_bytes (ibuf
, ntohs (ospfh
->length
), &ctx
);
369 md5_process_bytes (auth_key
, OSPF_AUTH_MD5_SIZE
, &ctx
);
370 md5_finish_ctx (&ctx
, digest
);
372 /* Append md5 digest to the end of the stream. */
373 oldputp
= stream_get_putp (op
->s
);
374 stream_set_putp (op
->s
, ntohs (ospfh
->length
));
375 stream_put (op
->s
, digest
, OSPF_AUTH_MD5_SIZE
);
376 stream_set_putp (op
->s
, oldputp
);
378 /* We do *NOT* increment the OSPF header length. */
379 op
->length
= ntohs (ospfh
->length
) + OSPF_AUTH_MD5_SIZE
;
381 if (stream_get_endp(op
->s
) != op
->length
)
382 zlog_warn("ospf_make_md5_digest: length mismatch stream %ld ospf_packet %d", stream_get_endp(op
->s
), op
->length
);
384 return OSPF_AUTH_MD5_SIZE
;
389 ospf_ls_req_timer (struct thread
*thread
)
391 struct ospf_neighbor
*nbr
;
393 nbr
= THREAD_ARG (thread
);
394 nbr
->t_ls_req
= NULL
;
396 /* Send Link State Request. */
397 if (ospf_ls_request_count (nbr
))
398 ospf_ls_req_send (nbr
);
400 /* Set Link State Request retransmission timer. */
401 OSPF_NSM_TIMER_ON (nbr
->t_ls_req
, ospf_ls_req_timer
, nbr
->v_ls_req
);
407 ospf_ls_req_event (struct ospf_neighbor
*nbr
)
411 thread_cancel (nbr
->t_ls_req
);
412 nbr
->t_ls_req
= NULL
;
414 nbr
->t_ls_req
= thread_add_event (master
, ospf_ls_req_timer
, nbr
, 0);
417 /* Cyclic timer function. Fist registered in ospf_nbr_new () in
420 ospf_ls_upd_timer (struct thread
*thread
)
422 struct ospf_neighbor
*nbr
;
424 nbr
= THREAD_ARG (thread
);
425 nbr
->t_ls_upd
= NULL
;
427 /* Send Link State Update. */
428 if (ospf_ls_retransmit_count (nbr
) > 0)
431 struct ospf_lsdb
*lsdb
;
434 int retransmit_interval
;
436 gettimeofday (&now
, NULL
);
437 retransmit_interval
= OSPF_IF_PARAM (nbr
->oi
, retransmit_interval
);
439 lsdb
= &nbr
->ls_rxmt
;
440 update
= list_new ();
442 for (i
= OSPF_MIN_LSA
; i
< OSPF_MAX_LSA
; i
++)
444 struct route_table
*table
= lsdb
->type
[i
].db
;
445 struct route_node
*rn
;
447 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
449 struct ospf_lsa
*lsa
;
451 if ((lsa
= rn
->info
) != NULL
)
452 /* Don't retransmit an LSA if we received it within
453 the last RxmtInterval seconds - this is to allow the
454 neighbour a chance to acknowledge the LSA as it may
455 have ben just received before the retransmit timer
456 fired. This is a small tweak to what is in the RFC,
457 but it will cut out out a lot of retransmit traffic
459 if (tv_cmp (tv_sub (now
, lsa
->tv_recv
),
460 int2tv (retransmit_interval
)) >= 0)
461 listnode_add (update
, rn
->info
);
465 if (listcount (update
) > 0)
466 ospf_ls_upd_send (nbr
, update
, OSPF_SEND_PACKET_DIRECT
);
467 list_delete (update
);
470 /* Set LS Update retransmission timer. */
471 OSPF_NSM_TIMER_ON (nbr
->t_ls_upd
, ospf_ls_upd_timer
, nbr
->v_ls_upd
);
477 ospf_ls_ack_timer (struct thread
*thread
)
479 struct ospf_interface
*oi
;
481 oi
= THREAD_ARG (thread
);
484 /* Send Link State Acknowledgment. */
485 if (listcount (oi
->ls_ack
) > 0)
486 ospf_ls_ack_send_delayed (oi
);
488 /* Set LS Ack timer. */
489 OSPF_ISM_TIMER_ON (oi
->t_ls_ack
, ospf_ls_ack_timer
, oi
->v_ls_ack
);
494 #ifdef WANT_OSPF_WRITE_FRAGMENT
496 ospf_write_frags (int fd
, struct ospf_packet
*op
, struct ip
*iph
,
497 struct msghdr
*msg
, unsigned int maxdatasize
,
498 unsigned int mtu
, int flags
, u_char type
)
500 #define OSPF_WRITE_FRAG_SHIFT 3
505 assert ( op
->length
== stream_get_endp(op
->s
) );
506 assert (msg
->msg_iovlen
== 2);
510 * SunOS, BSD and BSD derived kernels likely will clear ip_id, as
511 * well as the IP_MF flag, making this all quite pointless.
513 * However, for a system on which IP_MF is left alone, and ip_id left
514 * alone or else which sets same ip_id for each fragment this might
517 * XXX-TODO: It would be much nicer to have the kernel's use their
518 * existing fragmentation support to do this for us. Bugs/RFEs need to
519 * be raised against the various kernels.
523 iph
->ip_off
|= IP_MF
;
525 /* ip frag offset is expressed in units of 8byte words */
526 offset
= maxdatasize
>> OSPF_WRITE_FRAG_SHIFT
;
528 iovp
= &msg
->msg_iov
[1];
530 while ( (stream_get_endp(op
->s
) - stream_get_getp (op
->s
))
533 /* data length of this frag is to next offset value */
534 iovp
->iov_len
= offset
<< OSPF_WRITE_FRAG_SHIFT
;
535 iph
->ip_len
= iovp
->iov_len
+ sizeof (struct ip
);
536 assert (iph
->ip_len
<= mtu
);
538 sockopt_iphdrincl_swab_htosys (iph
);
540 ret
= sendmsg (fd
, msg
, flags
);
542 sockopt_iphdrincl_swab_systoh (iph
);
545 zlog_warn ("*** ospf_write_frags: sendmsg failed to %s,"
546 " id %d, off %d, len %d failed with %s",
547 inet_ntoa (iph
->ip_dst
),
551 safe_strerror (errno
));
553 if (IS_DEBUG_OSPF_PACKET (type
- 1, SEND
))
555 zlog_debug ("ospf_write_frags: sent id %d, off %d, len %d to %s\n",
556 iph
->ip_id
, iph
->ip_off
, iph
->ip_len
,
557 inet_ntoa (iph
->ip_dst
));
558 if (IS_DEBUG_OSPF_PACKET (type
- 1, DETAIL
))
560 zlog_debug ("-----------------IP Header Dump----------------------");
561 ospf_ip_header_dump (iph
);
562 zlog_debug ("-----------------------------------------------------");
566 iph
->ip_off
+= offset
;
567 stream_forward (op
->s
, iovp
->iov_len
);
568 iovp
->iov_base
= STREAM_PNT (op
->s
);
571 /* setup for final fragment */
572 iovp
->iov_len
= stream_get_endp(op
->s
) - stream_get_getp (op
->s
);
573 iph
->ip_len
= iovp
->iov_len
+ sizeof (struct ip
);
574 iph
->ip_off
&= (~IP_MF
);
576 #endif /* WANT_OSPF_WRITE_FRAGMENT */
579 ospf_write (struct thread
*thread
)
581 struct ospf
*ospf
= THREAD_ARG (thread
);
582 struct ospf_interface
*oi
;
583 struct ospf_packet
*op
;
584 struct sockaddr_in sa_dst
;
591 struct listnode
*node
;
592 #ifdef WANT_OSPF_WRITE_FRAGMENT
593 static u_int16_t ipid
= 0;
594 #endif /* WANT_OSPF_WRITE_FRAGMENT */
595 u_int16_t maxdatasize
;
596 #define OSPF_WRITE_IPHL_SHIFT 2
598 ospf
->t_write
= NULL
;
600 node
= listhead (ospf
->oi_write_q
);
605 #ifdef WANT_OSPF_WRITE_FRAGMENT
606 /* seed ipid static with low order bits of time */
608 ipid
= (time(NULL
) & 0xffff);
609 #endif /* WANT_OSPF_WRITE_FRAGMENT */
611 /* convenience - max OSPF data per packet */
612 maxdatasize
= oi
->ifp
->mtu
- sizeof (struct ip
);
614 /* Get one packet from queue. */
615 op
= ospf_fifo_head (oi
->obuf
);
617 assert (op
->length
>= OSPF_HEADER_SIZE
);
619 if (op
->dst
.s_addr
== htonl (OSPF_ALLSPFROUTERS
)
620 || op
->dst
.s_addr
== htonl (OSPF_ALLDROUTERS
))
621 ospf_if_ipmulticast (ospf
, oi
->address
, oi
->ifp
->ifindex
);
623 /* Rewrite the md5 signature & update the seq */
624 ospf_make_md5_digest (oi
, op
);
626 /* Retrieve OSPF packet type. */
627 stream_set_getp (op
->s
, 1);
628 type
= stream_getc (op
->s
);
630 /* reset get pointer */
631 stream_set_getp (op
->s
, 0);
633 memset (&iph
, 0, sizeof (struct ip
));
634 memset (&sa_dst
, 0, sizeof (sa_dst
));
636 sa_dst
.sin_family
= AF_INET
;
638 sa_dst
.sin_len
= sizeof(sa_dst
);
639 #endif /* HAVE_SIN_LEN */
640 sa_dst
.sin_addr
= op
->dst
;
641 sa_dst
.sin_port
= htons (0);
643 /* Set DONTROUTE flag if dst is unicast. */
644 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
645 if (!IN_MULTICAST (htonl (op
->dst
.s_addr
)))
646 flags
= MSG_DONTROUTE
;
648 iph
.ip_hl
= sizeof (struct ip
) >> OSPF_WRITE_IPHL_SHIFT
;
649 /* it'd be very strange for header to not be 4byte-word aligned but.. */
650 if ( sizeof (struct ip
)
651 > (unsigned int)(iph
.ip_hl
<< OSPF_WRITE_IPHL_SHIFT
) )
652 iph
.ip_hl
++; /* we presume sizeof struct ip cant overflow ip_hl.. */
654 iph
.ip_v
= IPVERSION
;
655 iph
.ip_tos
= IPTOS_PREC_INTERNETCONTROL
;
656 iph
.ip_len
= (iph
.ip_hl
<< OSPF_WRITE_IPHL_SHIFT
) + op
->length
;
658 #ifdef WANT_OSPF_WRITE_FRAGMENT
659 /* XXX-MT: not thread-safe at all..
660 * XXX: this presumes this is only programme sending OSPF packets
661 * otherwise, no guarantee ipid will be unique
664 #endif /* WANT_OSPF_WRITE_FRAGMENT */
667 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
668 iph
.ip_ttl
= OSPF_VL_IP_TTL
;
670 iph
.ip_ttl
= OSPF_IP_TTL
;
671 iph
.ip_p
= IPPROTO_OSPFIGP
;
673 iph
.ip_src
.s_addr
= oi
->address
->u
.prefix4
.s_addr
;
674 iph
.ip_dst
.s_addr
= op
->dst
.s_addr
;
676 memset (&msg
, 0, sizeof (msg
));
677 msg
.msg_name
= (caddr_t
) &sa_dst
;
678 msg
.msg_namelen
= sizeof (sa_dst
);
681 iov
[0].iov_base
= (char*)&iph
;
682 iov
[0].iov_len
= iph
.ip_hl
<< OSPF_WRITE_IPHL_SHIFT
;
683 iov
[1].iov_base
= STREAM_PNT (op
->s
);
684 iov
[1].iov_len
= op
->length
;
686 /* Sadly we can not rely on kernels to fragment packets because of either
687 * IP_HDRINCL and/or multicast destination being set.
689 #ifdef WANT_OSPF_WRITE_FRAGMENT
690 if ( op
->length
> maxdatasize
)
691 ospf_write_frags (ospf
->fd
, op
, &iph
, &msg
, maxdatasize
,
692 oi
->ifp
->mtu
, flags
, type
);
693 #endif /* WANT_OSPF_WRITE_FRAGMENT */
695 /* send final fragment (could be first) */
696 sockopt_iphdrincl_swab_htosys (&iph
);
697 ret
= sendmsg (ospf
->fd
, &msg
, flags
);
698 sockopt_iphdrincl_swab_systoh (&iph
);
701 zlog_warn ("*** sendmsg in ospf_write to %s failed with %s",
702 inet_ntoa (iph
.ip_dst
), safe_strerror (errno
));
704 /* Show debug sending packet. */
705 if (IS_DEBUG_OSPF_PACKET (type
- 1, SEND
))
707 if (IS_DEBUG_OSPF_PACKET (type
- 1, DETAIL
))
709 zlog_debug ("-----------------------------------------------------");
710 ospf_ip_header_dump (&iph
);
711 stream_set_getp (op
->s
, 0);
712 ospf_packet_dump (op
->s
);
715 zlog_debug ("%s sent to [%s] via [%s].",
716 ospf_packet_type_str
[type
], inet_ntoa (op
->dst
),
719 if (IS_DEBUG_OSPF_PACKET (type
- 1, DETAIL
))
720 zlog_debug ("-----------------------------------------------------");
723 /* Now delete packet from queue. */
724 ospf_packet_delete (oi
);
726 if (ospf_fifo_head (oi
->obuf
) == NULL
)
729 list_delete_node (ospf
->oi_write_q
, node
);
732 /* If packets still remain in queue, call write thread. */
733 if (!list_isempty (ospf
->oi_write_q
))
735 thread_add_write (master
, ospf_write
, ospf
, ospf
->fd
);
740 /* OSPF Hello message read -- RFC2328 Section 10.5. */
742 ospf_hello (struct ip
*iph
, struct ospf_header
*ospfh
,
743 struct stream
* s
, struct ospf_interface
*oi
, int size
)
745 struct ospf_hello
*hello
;
746 struct ospf_neighbor
*nbr
;
750 /* increment statistics. */
753 hello
= (struct ospf_hello
*) STREAM_PNT (s
);
755 /* If Hello is myself, silently discard. */
756 if (IPV4_ADDR_SAME (&ospfh
->router_id
, &oi
->ospf
->router_id
))
758 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, RECV
))
760 zlog_debug ("ospf_header[%s/%s]: selforiginated, "
762 ospf_packet_type_str
[ospfh
->type
],
763 inet_ntoa (iph
->ip_src
));
768 /* If incoming interface is passive one, ignore Hello. */
769 if (OSPF_IF_PARAM (oi
, passive_interface
) == OSPF_IF_PASSIVE
) {
770 zlog_info ("Packet %s [HELLO:RECV]: oi is passive",
771 inet_ntoa (ospfh
->router_id
));
775 /* get neighbor prefix. */
777 p
.prefixlen
= ip_masklen (hello
->network_mask
);
778 p
.u
.prefix4
= iph
->ip_src
;
780 /* Compare network mask. */
781 /* Checking is ignored for Point-to-Point and Virtual link. */
782 if (oi
->type
!= OSPF_IFTYPE_POINTOPOINT
783 && oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
784 if (oi
->address
->prefixlen
!= p
.prefixlen
)
786 zlog_warn ("Packet %s [Hello:RECV]: NetworkMask mismatch.",
787 inet_ntoa (ospfh
->router_id
));
791 /* Compare Hello Interval. */
792 if (OSPF_IF_PARAM (oi
, v_hello
) != ntohs (hello
->hello_interval
))
794 zlog_warn ("Packet %s [Hello:RECV]: HelloInterval mismatch.",
795 inet_ntoa (ospfh
->router_id
));
799 /* Compare Router Dead Interval. */
800 if (OSPF_IF_PARAM (oi
, v_wait
) != ntohl (hello
->dead_interval
))
802 zlog_warn ("Packet %s [Hello:RECV]: RouterDeadInterval mismatch.",
803 inet_ntoa (ospfh
->router_id
));
807 if (IS_DEBUG_OSPF_EVENT
)
808 zlog_debug ("Packet %s [Hello:RECV]: Options %s",
809 inet_ntoa (ospfh
->router_id
),
810 ospf_options_dump (hello
->options
));
812 /* Compare options. */
813 #define REJECT_IF_TBIT_ON 1 /* XXX */
814 #ifdef REJECT_IF_TBIT_ON
815 if (CHECK_FLAG (hello
->options
, OSPF_OPTION_T
))
818 * This router does not support non-zero TOS.
819 * Drop this Hello packet not to establish neighbor relationship.
821 zlog_warn ("Packet %s [Hello:RECV]: T-bit on, drop it.",
822 inet_ntoa (ospfh
->router_id
));
825 #endif /* REJECT_IF_TBIT_ON */
827 #ifdef HAVE_OPAQUE_LSA
828 if (CHECK_FLAG (oi
->ospf
->config
, OSPF_OPAQUE_CAPABLE
)
829 && CHECK_FLAG (hello
->options
, OSPF_OPTION_O
))
832 * This router does know the correct usage of O-bit
833 * the bit should be set in DD packet only.
835 zlog_warn ("Packet %s [Hello:RECV]: O-bit abuse?",
836 inet_ntoa (ospfh
->router_id
));
837 #ifdef STRICT_OBIT_USAGE_CHECK
838 return; /* Reject this packet. */
839 #else /* STRICT_OBIT_USAGE_CHECK */
840 UNSET_FLAG (hello
->options
, OSPF_OPTION_O
); /* Ignore O-bit. */
841 #endif /* STRICT_OBIT_USAGE_CHECK */
843 #endif /* HAVE_OPAQUE_LSA */
845 /* new for NSSA is to ensure that NP is on and E is off */
847 if (oi
->area
->external_routing
== OSPF_AREA_NSSA
)
849 if (! (CHECK_FLAG (OPTIONS (oi
), OSPF_OPTION_NP
)
850 && CHECK_FLAG (hello
->options
, OSPF_OPTION_NP
)
851 && ! CHECK_FLAG (OPTIONS (oi
), OSPF_OPTION_E
)
852 && ! CHECK_FLAG (hello
->options
, OSPF_OPTION_E
)))
854 zlog_warn ("NSSA-Packet-%s[Hello:RECV]: my options: %x, his options %x", inet_ntoa (ospfh
->router_id
), OPTIONS (oi
), hello
->options
);
857 if (IS_DEBUG_OSPF_NSSA
)
858 zlog_debug ("NSSA-Hello:RECV:Packet from %s:", inet_ntoa(ospfh
->router_id
));
861 /* The setting of the E-bit found in the Hello Packet's Options
862 field must match this area's ExternalRoutingCapability A
863 mismatch causes processing to stop and the packet to be
864 dropped. The setting of the rest of the bits in the Hello
865 Packet's Options field should be ignored. */
866 if (CHECK_FLAG (OPTIONS (oi
), OSPF_OPTION_E
) !=
867 CHECK_FLAG (hello
->options
, OSPF_OPTION_E
))
869 zlog_warn ("Packet %s [Hello:RECV]: my options: %x, his options %x",
870 inet_ntoa(ospfh
->router_id
), OPTIONS (oi
), hello
->options
);
874 /* get neighbour struct */
875 nbr
= ospf_nbr_get (oi
, ospfh
, iph
, &p
);
877 /* neighbour must be valid, ospf_nbr_get creates if none existed */
880 old_state
= nbr
->state
;
882 /* Add event to thread. */
883 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_HelloReceived
);
885 /* RFC2328 Section 9.5.1
886 If the router is not eligible to become Designated Router,
887 (snip) It must also send an Hello Packet in reply to an
888 Hello Packet received from any eligible neighbor (other than
889 the current Designated Router and Backup Designated Router). */
890 if (oi
->type
== OSPF_IFTYPE_NBMA
)
891 if (PRIORITY(oi
) == 0 && hello
->priority
> 0
892 && IPV4_ADDR_CMP(&DR(oi
), &iph
->ip_src
)
893 && IPV4_ADDR_CMP(&BDR(oi
), &iph
->ip_src
))
894 OSPF_NSM_TIMER_ON (nbr
->t_hello_reply
, ospf_hello_reply_timer
,
895 OSPF_HELLO_REPLY_DELAY
);
897 /* on NBMA network type, it happens to receive bidirectional Hello packet
898 without advance 1-Way Received event.
899 To avoid incorrect DR-seletion, raise 1-Way Received event.*/
900 if (oi
->type
== OSPF_IFTYPE_NBMA
&&
901 (old_state
== NSM_Down
|| old_state
== NSM_Attempt
))
903 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_OneWayReceived
);
904 nbr
->priority
= hello
->priority
;
905 nbr
->d_router
= hello
->d_router
;
906 nbr
->bd_router
= hello
->bd_router
;
910 if (ospf_nbr_bidirectional (&oi
->ospf
->router_id
, hello
->neighbors
,
911 size
- OSPF_HELLO_MIN_SIZE
))
913 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_TwoWayReceived
);
914 nbr
->options
|= hello
->options
;
918 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_OneWayReceived
);
919 /* Set neighbor information. */
920 nbr
->priority
= hello
->priority
;
921 nbr
->d_router
= hello
->d_router
;
922 nbr
->bd_router
= hello
->bd_router
;
926 /* If neighbor itself declares DR and no BDR exists,
927 cause event BackupSeen */
928 if (IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &hello
->d_router
))
929 if (hello
->bd_router
.s_addr
== 0 && oi
->state
== ISM_Waiting
)
930 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_BackupSeen
);
932 /* neighbor itself declares BDR. */
933 if (oi
->state
== ISM_Waiting
&&
934 IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &hello
->bd_router
))
935 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_BackupSeen
);
937 /* had not previously. */
938 if ((IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &hello
->d_router
) &&
939 IPV4_ADDR_CMP (&nbr
->address
.u
.prefix4
, &nbr
->d_router
)) ||
940 (IPV4_ADDR_CMP (&nbr
->address
.u
.prefix4
, &hello
->d_router
) &&
941 IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &nbr
->d_router
)))
942 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_NeighborChange
);
944 /* had not previously. */
945 if ((IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &hello
->bd_router
) &&
946 IPV4_ADDR_CMP (&nbr
->address
.u
.prefix4
, &nbr
->bd_router
)) ||
947 (IPV4_ADDR_CMP (&nbr
->address
.u
.prefix4
, &hello
->bd_router
) &&
948 IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &nbr
->bd_router
)))
949 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_NeighborChange
);
951 /* Neighbor priority check. */
952 if (nbr
->priority
>= 0 && nbr
->priority
!= hello
->priority
)
953 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_NeighborChange
);
955 /* Set neighbor information. */
956 nbr
->priority
= hello
->priority
;
957 nbr
->d_router
= hello
->d_router
;
958 nbr
->bd_router
= hello
->bd_router
;
961 /* Save DD flags/options/Seqnum received. */
963 ospf_db_desc_save_current (struct ospf_neighbor
*nbr
,
964 struct ospf_db_desc
*dd
)
966 nbr
->last_recv
.flags
= dd
->flags
;
967 nbr
->last_recv
.options
= dd
->options
;
968 nbr
->last_recv
.dd_seqnum
= ntohl (dd
->dd_seqnum
);
971 /* Process rest of DD packet. */
973 ospf_db_desc_proc (struct stream
*s
, struct ospf_interface
*oi
,
974 struct ospf_neighbor
*nbr
, struct ospf_db_desc
*dd
,
977 struct ospf_lsa
*new, *find
;
978 struct lsa_header
*lsah
;
980 stream_forward (s
, OSPF_DB_DESC_MIN_SIZE
);
981 for (size
-= OSPF_DB_DESC_MIN_SIZE
;
982 size
>= OSPF_LSA_HEADER_SIZE
; size
-= OSPF_LSA_HEADER_SIZE
)
984 lsah
= (struct lsa_header
*) STREAM_PNT (s
);
985 stream_forward (s
, OSPF_LSA_HEADER_SIZE
);
987 /* Unknown LS type. */
988 if (lsah
->type
< OSPF_MIN_LSA
|| lsah
->type
>= OSPF_MAX_LSA
)
990 zlog_warn ("Packet [DD:RECV]: Unknown LS type %d.", lsah
->type
);
991 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
995 #ifdef HAVE_OPAQUE_LSA
996 if (IS_OPAQUE_LSA (lsah
->type
)
997 && ! CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
))
999 zlog_warn ("LSA[Type%d:%s]: Opaque capability mismatch?", lsah
->type
, inet_ntoa (lsah
->id
));
1000 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1003 #endif /* HAVE_OPAQUE_LSA */
1007 case OSPF_AS_EXTERNAL_LSA
:
1008 #ifdef HAVE_OPAQUE_LSA
1009 case OSPF_OPAQUE_AS_LSA
:
1010 #endif /* HAVE_OPAQUE_LSA */
1011 /* Check for stub area. Reject if AS-External from stub but
1012 allow if from NSSA. */
1013 if (oi
->area
->external_routing
== OSPF_AREA_STUB
)
1015 zlog_warn ("Packet [DD:RECV]: LSA[Type%d:%s] from %s area.",
1016 lsah
->type
, inet_ntoa (lsah
->id
),
1017 (oi
->area
->external_routing
== OSPF_AREA_STUB
) ?\
1019 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1027 /* Create LS-request object. */
1028 new = ospf_ls_request_new (lsah
);
1030 /* Lookup received LSA, then add LS request list. */
1031 find
= ospf_lsa_lookup_by_header (oi
->area
, lsah
);
1032 if (!find
|| ospf_lsa_more_recent (find
, new) < 0)
1034 ospf_ls_request_add (nbr
, new);
1035 ospf_lsa_discard (new);
1039 /* Received LSA is not recent. */
1040 if (IS_DEBUG_OSPF_EVENT
)
1041 zlog_debug ("Packet [DD:RECV]: LSA received Type %d, "
1042 "ID %s is not recent.", lsah
->type
, inet_ntoa (lsah
->id
));
1043 ospf_lsa_discard (new);
1049 if (IS_SET_DD_MS (nbr
->dd_flags
))
1052 /* Entire DD packet sent. */
1053 if (!IS_SET_DD_M (dd
->flags
) && !IS_SET_DD_M (nbr
->dd_flags
))
1054 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_ExchangeDone
);
1056 /* Send new DD packet. */
1057 ospf_db_desc_send (nbr
);
1062 nbr
->dd_seqnum
= ntohl (dd
->dd_seqnum
);
1064 /* When master's more flags is not set. */
1065 if (!IS_SET_DD_M (dd
->flags
) && ospf_db_summary_isempty (nbr
))
1067 nbr
->dd_flags
&= ~(OSPF_DD_FLAG_M
);
1068 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_ExchangeDone
);
1071 /* Send DD packet in reply. */
1072 ospf_db_desc_send (nbr
);
1075 /* Save received neighbor values from DD. */
1076 ospf_db_desc_save_current (nbr
, dd
);
1080 ospf_db_desc_is_dup (struct ospf_db_desc
*dd
, struct ospf_neighbor
*nbr
)
1082 /* Is DD duplicated? */
1083 if (dd
->options
== nbr
->last_recv
.options
&&
1084 dd
->flags
== nbr
->last_recv
.flags
&&
1085 dd
->dd_seqnum
== htonl (nbr
->last_recv
.dd_seqnum
))
1091 /* OSPF Database Description message read -- RFC2328 Section 10.6. */
1093 ospf_db_desc (struct ip
*iph
, struct ospf_header
*ospfh
,
1094 struct stream
*s
, struct ospf_interface
*oi
, u_int16_t size
)
1096 struct ospf_db_desc
*dd
;
1097 struct ospf_neighbor
*nbr
;
1099 /* Increment statistics. */
1102 dd
= (struct ospf_db_desc
*) STREAM_PNT (s
);
1104 nbr
= ospf_nbr_lookup (oi
, iph
, ospfh
);
1107 zlog_warn ("Packet[DD]: Unknown Neighbor %s",
1108 inet_ntoa (ospfh
->router_id
));
1113 if (ntohs (dd
->mtu
) > oi
->ifp
->mtu
)
1115 zlog_warn ("Packet[DD]: Neighbor %s MTU %u is larger than [%s]'s MTU %u",
1116 inet_ntoa (nbr
->router_id
), ntohs (dd
->mtu
),
1117 IF_NAME (oi
), oi
->ifp
->mtu
);
1122 * XXX HACK by Hasso Tepper. Setting N/P bit in NSSA area DD packets is not
1123 * required. In fact at least JunOS sends DD packets with P bit clear.
1124 * Until proper solution is developped, this hack should help.
1126 * Update: According to the RFCs, N bit is specified /only/ for Hello
1127 * options, unfortunately its use in DD options is not specified. Hence some
1128 * implementations follow E-bit semantics and set it in DD options, and some
1129 * treat it as unspecified and hence follow the directive "default for
1130 * options is clear", ie unset.
1132 * Reset the flag, as ospfd follows E-bit semantics.
1134 if ( (oi
->area
->external_routing
== OSPF_AREA_NSSA
)
1135 && (CHECK_FLAG (nbr
->options
, OSPF_OPTION_NP
))
1136 && (!CHECK_FLAG (dd
->options
, OSPF_OPTION_NP
)) )
1138 if (IS_DEBUG_OSPF_EVENT
)
1139 zlog_debug ("Packet[DD]: Neighbour %s: Has NSSA capability, sends with N bit clear in DD options",
1140 inet_ntoa (nbr
->router_id
) );
1141 SET_FLAG (dd
->options
, OSPF_OPTION_NP
);
1144 #ifdef REJECT_IF_TBIT_ON
1145 if (CHECK_FLAG (dd
->options
, OSPF_OPTION_T
))
1148 * In Hello protocol, optional capability must have checked
1149 * to prevent this T-bit enabled router be my neighbor.
1151 zlog_warn ("Packet[DD]: Neighbor %s: T-bit on?", inet_ntoa (nbr
->router_id
));
1154 #endif /* REJECT_IF_TBIT_ON */
1156 #ifdef HAVE_OPAQUE_LSA
1157 if (CHECK_FLAG (dd
->options
, OSPF_OPTION_O
)
1158 && !CHECK_FLAG (oi
->ospf
->config
, OSPF_OPAQUE_CAPABLE
))
1161 * This node is not configured to handle O-bit, for now.
1162 * Clear it to ignore unsupported capability proposed by neighbor.
1164 UNSET_FLAG (dd
->options
, OSPF_OPTION_O
);
1166 #endif /* HAVE_OPAQUE_LSA */
1168 /* Process DD packet by neighbor status. */
1174 zlog_warn ("Packet[DD]: Neighbor %s state is %s, packet discarded.",
1175 inet_ntoa(nbr
->router_id
),
1176 LOOKUP (ospf_nsm_state_msg
, nbr
->state
));
1179 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_TwoWayReceived
);
1180 /* If the new state is ExStart, the processing of the current
1181 packet should then continue in this new state by falling
1182 through to case ExStart below. */
1183 if (nbr
->state
!= NSM_ExStart
)
1187 if ((IS_SET_DD_ALL (dd
->flags
) == OSPF_DD_FLAG_ALL
) &&
1188 (size
== OSPF_DB_DESC_MIN_SIZE
))
1190 if (IPV4_ADDR_CMP (&nbr
->router_id
, &oi
->ospf
->router_id
) > 0)
1192 /* We're Slave---obey */
1193 zlog_info ("Packet[DD]: Neighbor %s Negotiation done (Slave).",
1194 inet_ntoa(nbr
->router_id
));
1195 nbr
->dd_seqnum
= ntohl (dd
->dd_seqnum
);
1196 nbr
->dd_flags
&= ~(OSPF_DD_FLAG_MS
|OSPF_DD_FLAG_I
); /* Reset I/MS */
1200 /* We're Master, ignore the initial DBD from Slave */
1201 zlog_warn ("Packet[DD]: Neighbor %s: Initial DBD from Slave, "
1202 "ignoring.", inet_ntoa(nbr
->router_id
));
1206 /* Ack from the Slave */
1207 else if (!IS_SET_DD_MS (dd
->flags
) && !IS_SET_DD_I (dd
->flags
) &&
1208 ntohl (dd
->dd_seqnum
) == nbr
->dd_seqnum
&&
1209 IPV4_ADDR_CMP (&nbr
->router_id
, &oi
->ospf
->router_id
) < 0)
1211 zlog_info ("Packet[DD]: Neighbor %s Negotiation done (Master).",
1212 inet_ntoa(nbr
->router_id
));
1213 nbr
->dd_flags
&= ~OSPF_DD_FLAG_I
;
1217 zlog_warn ("Packet[DD]: Neighbor %s Negotiation fails.",
1218 inet_ntoa(nbr
->router_id
));
1222 /* This is where the real Options are saved */
1223 nbr
->options
= dd
->options
;
1225 #ifdef HAVE_OPAQUE_LSA
1226 if (CHECK_FLAG (oi
->ospf
->config
, OSPF_OPAQUE_CAPABLE
))
1228 if (IS_DEBUG_OSPF_EVENT
)
1229 zlog_debug ("Neighbor[%s] is %sOpaque-capable.",
1230 inet_ntoa (nbr
->router_id
),
1231 CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
) ? "" : "NOT ");
1233 if (! CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
)
1234 && IPV4_ADDR_SAME (&DR (oi
), &nbr
->address
.u
.prefix4
))
1236 zlog_warn ("DR-neighbor[%s] is NOT opaque-capable; Opaque-LSAs cannot be reliably advertised in this network.", inet_ntoa (nbr
->router_id
));
1237 /* This situation is undesirable, but not a real error. */
1240 #endif /* HAVE_OPAQUE_LSA */
1242 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_NegotiationDone
);
1244 /* continue processing rest of packet. */
1245 ospf_db_desc_proc (s
, oi
, nbr
, dd
, size
);
1248 if (ospf_db_desc_is_dup (dd
, nbr
))
1250 if (IS_SET_DD_MS (nbr
->dd_flags
))
1251 /* Master: discard duplicated DD packet. */
1252 zlog_warn ("Packet[DD] (Master): Neighbor %s packet duplicated.",
1253 inet_ntoa (nbr
->router_id
));
1255 /* Slave: cause to retransmit the last Database Description. */
1257 zlog_warn ("Packet[DD] [Slave]: Neighbor %s packet duplicated.",
1258 inet_ntoa (nbr
->router_id
));
1259 ospf_db_desc_resend (nbr
);
1264 /* Otherwise DD packet should be checked. */
1265 /* Check Master/Slave bit mismatch */
1266 if (IS_SET_DD_MS (dd
->flags
) != IS_SET_DD_MS (nbr
->last_recv
.flags
))
1268 zlog_warn ("Packet[DD]: Neighbor %s MS-bit mismatch.",
1269 inet_ntoa(nbr
->router_id
));
1270 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1271 if (IS_DEBUG_OSPF_EVENT
)
1272 zlog_debug ("Packet[DD]: dd->flags=%d, nbr->dd_flags=%d",
1273 dd
->flags
, nbr
->dd_flags
);
1277 /* Check initialize bit is set. */
1278 if (IS_SET_DD_I (dd
->flags
))
1280 zlog_warn ("Packet[DD]: Neighbor %s I-bit set.",
1281 inet_ntoa(nbr
->router_id
));
1282 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1286 /* Check DD Options. */
1287 if (dd
->options
!= nbr
->options
)
1289 #ifdef ORIGINAL_CODING
1290 /* Save the new options for debugging */
1291 nbr
->options
= dd
->options
;
1292 #endif /* ORIGINAL_CODING */
1293 zlog_warn ("Packet[DD]: Neighbor %s options mismatch.",
1294 inet_ntoa(nbr
->router_id
));
1295 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1299 /* Check DD sequence number. */
1300 if ((IS_SET_DD_MS (nbr
->dd_flags
) &&
1301 ntohl (dd
->dd_seqnum
) != nbr
->dd_seqnum
) ||
1302 (!IS_SET_DD_MS (nbr
->dd_flags
) &&
1303 ntohl (dd
->dd_seqnum
) != nbr
->dd_seqnum
+ 1))
1305 zlog_warn ("Packet[DD]: Neighbor %s sequence number mismatch.",
1306 inet_ntoa(nbr
->router_id
));
1307 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1311 /* Continue processing rest of packet. */
1312 ospf_db_desc_proc (s
, oi
, nbr
, dd
, size
);
1316 if (ospf_db_desc_is_dup (dd
, nbr
))
1318 if (IS_SET_DD_MS (nbr
->dd_flags
))
1320 /* Master should discard duplicate DD packet. */
1321 zlog_warn("Packet[DD]: Neighbor %s duplicated, packet discarded.",
1322 inet_ntoa(nbr
->router_id
));
1327 struct timeval t
, now
;
1328 gettimeofday (&now
, NULL
);
1329 t
= tv_sub (now
, nbr
->last_send_ts
);
1330 if (tv_cmp (t
, int2tv (nbr
->v_inactivity
)) < 0)
1332 /* In states Loading and Full the slave must resend
1333 its last Database Description packet in response to
1334 duplicate Database Description packets received
1335 from the master. For this reason the slave must
1336 wait RouterDeadInterval seconds before freeing the
1337 last Database Description packet. Reception of a
1338 Database Description packet from the master after
1339 this interval will generate a SeqNumberMismatch
1340 neighbor event. RFC2328 Section 10.8 */
1341 ospf_db_desc_resend (nbr
);
1347 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1350 zlog_warn ("Packet[DD]: Neighbor %s NSM illegal status %u.",
1351 inet_ntoa(nbr
->router_id
), nbr
->state
);
1356 #define OSPF_LSA_KEY_SIZE 12 /* type(4) + id(4) + ar(4) */
1358 /* OSPF Link State Request Read -- RFC2328 Section 10.7. */
1360 ospf_ls_req (struct ip
*iph
, struct ospf_header
*ospfh
,
1361 struct stream
*s
, struct ospf_interface
*oi
, u_int16_t size
)
1363 struct ospf_neighbor
*nbr
;
1365 struct in_addr ls_id
;
1366 struct in_addr adv_router
;
1367 struct ospf_lsa
*find
;
1368 struct list
*ls_upd
;
1369 unsigned int length
;
1371 /* Increment statistics. */
1374 nbr
= ospf_nbr_lookup (oi
, iph
, ospfh
);
1377 zlog_warn ("Link State Request: Unknown Neighbor %s.",
1378 inet_ntoa (ospfh
->router_id
));
1382 /* Neighbor State should be Exchange or later. */
1383 if (nbr
->state
!= NSM_Exchange
&&
1384 nbr
->state
!= NSM_Loading
&&
1385 nbr
->state
!= NSM_Full
)
1387 zlog_warn ("Link State Request received from %s: "
1388 "Neighbor state is %s, packet discarded.",
1389 inet_ntoa (ospfh
->router_id
),
1390 LOOKUP (ospf_nsm_state_msg
, nbr
->state
));
1394 /* Send Link State Update for ALL requested LSAs. */
1395 ls_upd
= list_new ();
1396 length
= OSPF_HEADER_SIZE
+ OSPF_LS_UPD_MIN_SIZE
;
1398 while (size
>= OSPF_LSA_KEY_SIZE
)
1400 /* Get one slice of Link State Request. */
1401 ls_type
= stream_getl (s
);
1402 ls_id
.s_addr
= stream_get_ipv4 (s
);
1403 adv_router
.s_addr
= stream_get_ipv4 (s
);
1405 /* Verify LSA type. */
1406 if (ls_type
< OSPF_MIN_LSA
|| ls_type
>= OSPF_MAX_LSA
)
1408 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_BadLSReq
);
1409 list_delete (ls_upd
);
1413 /* Search proper LSA in LSDB. */
1414 find
= ospf_lsa_lookup (oi
->area
, ls_type
, ls_id
, adv_router
);
1417 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_BadLSReq
);
1418 list_delete (ls_upd
);
1422 /* Packet overflows MTU size, send immediately. */
1423 if (length
+ ntohs (find
->data
->length
) > ospf_packet_max (oi
))
1425 if (oi
->type
== OSPF_IFTYPE_NBMA
)
1426 ospf_ls_upd_send (nbr
, ls_upd
, OSPF_SEND_PACKET_DIRECT
);
1428 ospf_ls_upd_send (nbr
, ls_upd
, OSPF_SEND_PACKET_INDIRECT
);
1430 /* Only remove list contents. Keep ls_upd. */
1431 list_delete_all_node (ls_upd
);
1433 length
= OSPF_HEADER_SIZE
+ OSPF_LS_UPD_MIN_SIZE
;
1436 /* Append LSA to update list. */
1437 listnode_add (ls_upd
, find
);
1438 length
+= ntohs (find
->data
->length
);
1440 size
-= OSPF_LSA_KEY_SIZE
;
1443 /* Send rest of Link State Update. */
1444 if (listcount (ls_upd
) > 0)
1446 if (oi
->type
== OSPF_IFTYPE_NBMA
)
1447 ospf_ls_upd_send (nbr
, ls_upd
, OSPF_SEND_PACKET_DIRECT
);
1449 ospf_ls_upd_send (nbr
, ls_upd
, OSPF_SEND_PACKET_INDIRECT
);
1451 list_delete (ls_upd
);
1457 /* Get the list of LSAs from Link State Update packet.
1458 And process some validation -- RFC2328 Section 13. (1)-(2). */
1459 static struct list
*
1460 ospf_ls_upd_list_lsa (struct ospf_neighbor
*nbr
, struct stream
*s
,
1461 struct ospf_interface
*oi
, size_t size
)
1463 u_int16_t count
, sum
;
1465 struct lsa_header
*lsah
;
1466 struct ospf_lsa
*lsa
;
1471 count
= stream_getl (s
);
1472 size
-= OSPF_LS_UPD_MIN_SIZE
; /* # LSAs */
1474 for (; size
>= OSPF_LSA_HEADER_SIZE
&& count
> 0;
1475 size
-= length
, stream_forward (s
, length
), count
--)
1477 lsah
= (struct lsa_header
*) STREAM_PNT (s
);
1478 length
= ntohs (lsah
->length
);
1482 zlog_warn ("Link State Update: LSA length exceeds packet size.");
1486 /* Validate the LSA's LS checksum. */
1487 sum
= lsah
->checksum
;
1488 if (sum
!= ospf_lsa_checksum (lsah
))
1490 zlog_warn ("Link State Update: LSA checksum error %x, %x.",
1491 sum
, lsah
->checksum
);
1495 /* Examine the LSA's LS type. */
1496 if (lsah
->type
< OSPF_MIN_LSA
|| lsah
->type
>= OSPF_MAX_LSA
)
1498 zlog_warn ("Link State Update: Unknown LS type %d", lsah
->type
);
1503 * What if the received LSA's age is greater than MaxAge?
1504 * Treat it as a MaxAge case -- endo.
1506 if (ntohs (lsah
->ls_age
) > OSPF_LSA_MAXAGE
)
1507 lsah
->ls_age
= htons (OSPF_LSA_MAXAGE
);
1509 #ifdef HAVE_OPAQUE_LSA
1510 if (CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
))
1512 #ifdef STRICT_OBIT_USAGE_CHECK
1513 if ((IS_OPAQUE_LSA(lsah
->type
) &&
1514 ! CHECK_FLAG (lsah
->options
, OSPF_OPTION_O
))
1515 || (! IS_OPAQUE_LSA(lsah
->type
) &&
1516 CHECK_FLAG (lsah
->options
, OSPF_OPTION_O
)))
1519 * This neighbor must know the exact usage of O-bit;
1520 * the bit will be set in Type-9,10,11 LSAs only.
1522 zlog_warn ("LSA[Type%d:%s]: O-bit abuse?", lsah
->type
, inet_ntoa (lsah
->id
));
1525 #endif /* STRICT_OBIT_USAGE_CHECK */
1527 /* Do not take in AS External Opaque-LSAs if we are a stub. */
1528 if (lsah
->type
== OSPF_OPAQUE_AS_LSA
1529 && nbr
->oi
->area
->external_routing
!= OSPF_AREA_DEFAULT
)
1531 if (IS_DEBUG_OSPF_EVENT
)
1532 zlog_debug ("LSA[Type%d:%s]: We are a stub, don't take this LSA.", lsah
->type
, inet_ntoa (lsah
->id
));
1536 else if (IS_OPAQUE_LSA(lsah
->type
))
1538 zlog_warn ("LSA[Type%d:%s]: Opaque capability mismatch?", lsah
->type
, inet_ntoa (lsah
->id
));
1541 #endif /* HAVE_OPAQUE_LSA */
1543 /* Create OSPF LSA instance. */
1544 lsa
= ospf_lsa_new ();
1546 /* We may wish to put some error checking if type NSSA comes in
1547 and area not in NSSA mode */
1550 case OSPF_AS_EXTERNAL_LSA
:
1551 #ifdef HAVE_OPAQUE_LSA
1552 case OSPF_OPAQUE_AS_LSA
:
1555 case OSPF_OPAQUE_LINK_LSA
:
1556 lsa
->oi
= oi
; /* Remember incoming interface for flooding control. */
1558 #endif /* HAVE_OPAQUE_LSA */
1560 lsa
->area
= oi
->area
;
1564 lsa
->data
= ospf_lsa_data_new (length
);
1565 memcpy (lsa
->data
, lsah
, length
);
1567 if (IS_DEBUG_OSPF_EVENT
)
1568 zlog_debug("LSA[Type%d:%s]: %p new LSA created with Link State Update",
1569 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
), lsa
);
1570 listnode_add (lsas
, lsa
);
1576 /* Cleanup Update list. */
1578 ospf_upd_list_clean (struct list
*lsas
)
1580 struct listnode
*node
;
1581 struct ospf_lsa
*lsa
;
1583 for (node
= listhead (lsas
); node
; nextnode (node
))
1584 if ((lsa
= getdata (node
)) != NULL
)
1585 ospf_lsa_discard (lsa
);
1590 /* OSPF Link State Update message read -- RFC2328 Section 13. */
1592 ospf_ls_upd (struct ip
*iph
, struct ospf_header
*ospfh
,
1593 struct stream
*s
, struct ospf_interface
*oi
, u_int16_t size
)
1595 struct ospf_neighbor
*nbr
;
1597 #ifdef HAVE_OPAQUE_LSA
1598 struct list
*mylsa_acks
, *mylsa_upds
;
1599 #endif /* HAVE_OPAQUE_LSA */
1600 struct listnode
*node
, *next
;
1601 struct ospf_lsa
*lsa
= NULL
;
1602 /* unsigned long ls_req_found = 0; */
1604 /* Dis-assemble the stream, update each entry, re-encapsulate for flooding */
1606 /* Increment statistics. */
1609 /* Check neighbor. */
1610 nbr
= ospf_nbr_lookup (oi
, iph
, ospfh
);
1613 zlog_warn ("Link State Update: Unknown Neighbor %s on int: %s",
1614 inet_ntoa (ospfh
->router_id
), IF_NAME (oi
));
1618 /* Check neighbor state. */
1619 if (nbr
->state
< NSM_Exchange
)
1621 zlog_warn ("Link State Update: "
1622 "Neighbor[%s] state %s is less than Exchange",
1623 inet_ntoa (ospfh
->router_id
),
1624 LOOKUP(ospf_nsm_state_msg
, nbr
->state
));
1628 /* Get list of LSAs from Link State Update packet. - Also perorms Stages
1629 * 1 (validate LSA checksum) and 2 (check for LSA consistent type)
1632 lsas
= ospf_ls_upd_list_lsa (nbr
, s
, oi
, size
);
1634 #ifdef HAVE_OPAQUE_LSA
1636 * Prepare two kinds of lists to clean up unwanted self-originated
1637 * Opaque-LSAs from the routing domain as soon as possible.
1639 mylsa_acks
= list_new (); /* Let the sender cease retransmission. */
1640 mylsa_upds
= list_new (); /* Flush target LSAs if necessary. */
1643 * If self-originated Opaque-LSAs that have flooded before restart
1644 * are contained in the received LSUpd message, corresponding LSReq
1645 * messages to be sent may have to be modified.
1646 * To eliminate possible race conditions such that flushing and normal
1647 * updating for the same LSA would take place alternately, this trick
1648 * must be done before entering to the loop below.
1650 ospf_opaque_adjust_lsreq (nbr
, lsas
);
1651 #endif /* HAVE_OPAQUE_LSA */
1653 #define DISCARD_LSA(L,N) {\
1654 if (IS_DEBUG_OSPF_EVENT) \
1655 zlog_debug ("ospf_lsa_discard() in ospf_ls_upd() point %d: lsa %p Type-%d", N, lsa, (int) lsa->data->type); \
1656 ospf_lsa_discard (L); \
1659 /* Process each LSA received in the one packet. */
1660 for (node
= listhead (lsas
); node
; node
= next
)
1662 struct ospf_lsa
*ls_ret
, *current
;
1667 lsa
= getdata (node
);
1669 if (IS_DEBUG_OSPF_NSSA
)
1671 char buf1
[INET_ADDRSTRLEN
];
1672 char buf2
[INET_ADDRSTRLEN
];
1673 char buf3
[INET_ADDRSTRLEN
];
1675 zlog_debug("LSA Type-%d from %s, ID: %s, ADV: %s",
1677 inet_ntop (AF_INET
, &ospfh
->router_id
,
1678 buf1
, INET_ADDRSTRLEN
),
1679 inet_ntop (AF_INET
, &lsa
->data
->id
,
1680 buf2
, INET_ADDRSTRLEN
),
1681 inet_ntop (AF_INET
, &lsa
->data
->adv_router
,
1682 buf3
, INET_ADDRSTRLEN
));
1685 listnode_delete (lsas
, lsa
); /* We don't need it in list anymore */
1687 /* Validate Checksum - Done above by ospf_ls_upd_list_lsa() */
1689 /* LSA Type - Done above by ospf_ls_upd_list_lsa() */
1691 /* Do not take in AS External LSAs if we are a stub or NSSA. */
1693 /* Do not take in AS NSSA if this neighbor and we are not NSSA */
1695 /* Do take in Type-7's if we are an NSSA */
1697 /* If we are also an ABR, later translate them to a Type-5 packet */
1699 /* Later, an NSSA Re-fresh can Re-fresh Type-7's and an ABR will
1700 translate them to a separate Type-5 packet. */
1702 if (lsa
->data
->type
== OSPF_AS_EXTERNAL_LSA
)
1703 /* Reject from STUB or NSSA */
1704 if (nbr
->oi
->area
->external_routing
!= OSPF_AREA_DEFAULT
)
1706 DISCARD_LSA (lsa
, 1);
1707 if (IS_DEBUG_OSPF_NSSA
)
1708 zlog_debug("Incoming External LSA Discarded: We are NSSA/STUB Area");
1711 if (lsa
->data
->type
== OSPF_AS_NSSA_LSA
)
1712 if (nbr
->oi
->area
->external_routing
!= OSPF_AREA_NSSA
)
1714 DISCARD_LSA (lsa
,2);
1715 if (IS_DEBUG_OSPF_NSSA
)
1716 zlog_debug("Incoming NSSA LSA Discarded: Not NSSA Area");
1719 /* Find the LSA in the current database. */
1721 current
= ospf_lsa_lookup_by_header (oi
->area
, lsa
->data
);
1723 /* If the LSA's LS age is equal to MaxAge, and there is currently
1724 no instance of the LSA in the router's link state database,
1725 and none of router's neighbors are in states Exchange or Loading,
1726 then take the following actions. */
1728 if (IS_LSA_MAXAGE (lsa
) && !current
&&
1729 (ospf_nbr_count (oi
, NSM_Exchange
) +
1730 ospf_nbr_count (oi
, NSM_Loading
)) == 0)
1732 /* Response Link State Acknowledgment. */
1733 ospf_ls_ack_send (nbr
, lsa
);
1736 zlog_warn("Link State Update[%s]: LS age is equal to MaxAge.",
1738 DISCARD_LSA (lsa
, 3);
1741 #ifdef HAVE_OPAQUE_LSA
1742 if (IS_OPAQUE_LSA (lsa
->data
->type
)
1743 && IPV4_ADDR_SAME (&lsa
->data
->adv_router
, &oi
->ospf
->router_id
))
1746 * Even if initial flushing seems to be completed, there might
1747 * be a case that self-originated LSA with MaxAge still remain
1748 * in the routing domain.
1749 * Just send an LSAck message to cease retransmission.
1751 if (IS_LSA_MAXAGE (lsa
))
1753 zlog_warn ("LSA[%s]: Boomerang effect?", dump_lsa_key (lsa
));
1754 ospf_ls_ack_send (nbr
, lsa
);
1755 ospf_lsa_discard (lsa
);
1757 if (current
!= NULL
&& ! IS_LSA_MAXAGE (current
))
1758 ospf_opaque_lsa_refresh_schedule (current
);
1763 * If an instance of self-originated Opaque-LSA is not found
1764 * in the LSDB, there are some possible cases here.
1766 * 1) This node lost opaque-capability after restart.
1767 * 2) Else, a part of opaque-type is no more supported.
1768 * 3) Else, a part of opaque-id is no more supported.
1770 * Anyway, it is still this node's responsibility to flush it.
1771 * Otherwise, the LSA instance remains in the routing domain
1772 * until its age reaches to MaxAge.
1774 if (current
== NULL
)
1776 if (IS_DEBUG_OSPF_EVENT
)
1777 zlog_debug ("LSA[%s]: Previously originated Opaque-LSA, not found in the LSDB.", dump_lsa_key (lsa
));
1779 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
1780 listnode_add (mylsa_upds
, ospf_lsa_dup (lsa
));
1781 listnode_add (mylsa_acks
, ospf_lsa_lock (lsa
));
1785 #endif /* HAVE_OPAQUE_LSA */
1786 /* It might be happen that received LSA is self-originated network LSA, but
1787 * router ID is cahnged. So, we should check if LSA is a network-LSA whose
1788 * Link State ID is one of the router's own IP interface addresses but whose
1789 * Advertising Router is not equal to the router's own Router ID
1790 * According to RFC 2328 12.4.2 and 13.4 this LSA should be flushed.
1793 if(lsa
->data
->type
== OSPF_NETWORK_LSA
)
1795 struct listnode
*oi_node
;
1798 for(oi_node
= listhead(oi
->ospf
->oiflist
); oi_node
; oi_node
= nextnode(oi_node
))
1800 struct ospf_interface
*out_if
= getdata(oi_node
);
1804 if((IPV4_ADDR_SAME(&out_if
->address
->u
.prefix4
, &lsa
->data
->id
)) &&
1805 (!(IPV4_ADDR_SAME(&oi
->ospf
->router_id
, &lsa
->data
->adv_router
))))
1807 if(out_if
->network_lsa_self
)
1809 ospf_lsa_flush_area(lsa
,out_if
->area
);
1810 if(IS_DEBUG_OSPF_EVENT
)
1811 zlog_debug ("ospf_lsa_discard() in ospf_ls_upd() point 9: lsa %p Type-%d",
1812 lsa
, (int) lsa
->data
->type
);
1813 ospf_lsa_discard (lsa
);
1823 /* (5) Find the instance of this LSA that is currently contained
1824 in the router's link state database. If there is no
1825 database copy, or the received LSA is more recent than
1826 the database copy the following steps must be performed. */
1828 if (current
== NULL
||
1829 (ret
= ospf_lsa_more_recent (current
, lsa
)) < 0)
1831 /* Actual flooding procedure. */
1832 if (ospf_flood (oi
->ospf
, nbr
, current
, lsa
) < 0) /* Trap NSSA later. */
1833 DISCARD_LSA (lsa
, 4);
1837 /* (6) Else, If there is an instance of the LSA on the sending
1838 neighbor's Link state request list, an error has occurred in
1839 the Database Exchange process. In this case, restart the
1840 Database Exchange process by generating the neighbor event
1841 BadLSReq for the sending neighbor and stop processing the
1842 Link State Update packet. */
1844 if (ospf_ls_request_lookup (nbr
, lsa
))
1846 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_BadLSReq
);
1847 zlog_warn("LSA[%s] instance exists on Link state request list",
1850 /* Clean list of LSAs. */
1851 ospf_upd_list_clean (lsas
);
1852 /* this lsa is not on lsas list already. */
1853 ospf_lsa_discard (lsa
);
1854 #ifdef HAVE_OPAQUE_LSA
1855 list_delete (mylsa_acks
);
1856 list_delete (mylsa_upds
);
1857 #endif /* HAVE_OPAQUE_LSA */
1861 /* If the received LSA is the same instance as the database copy
1862 (i.e., neither one is more recent) the following two steps
1863 should be performed: */
1867 /* If the LSA is listed in the Link state retransmission list
1868 for the receiving adjacency, the router itself is expecting
1869 an acknowledgment for this LSA. The router should treat the
1870 received LSA as an acknowledgment by removing the LSA from
1871 the Link state retransmission list. This is termed an
1872 "implied acknowledgment". */
1874 ls_ret
= ospf_ls_retransmit_lookup (nbr
, lsa
);
1878 ospf_ls_retransmit_delete (nbr
, ls_ret
);
1880 /* Delayed acknowledgment sent if advertisement received
1881 from Designated Router, otherwise do nothing. */
1882 if (oi
->state
== ISM_Backup
)
1883 if (NBR_IS_DR (nbr
))
1884 listnode_add (oi
->ls_ack
, ospf_lsa_lock (lsa
));
1886 DISCARD_LSA (lsa
, 5);
1889 /* Acknowledge the receipt of the LSA by sending a
1890 Link State Acknowledgment packet back out the receiving
1893 ospf_ls_ack_send (nbr
, lsa
);
1894 DISCARD_LSA (lsa
, 6);
1898 /* The database copy is more recent. If the database copy
1899 has LS age equal to MaxAge and LS sequence number equal to
1900 MaxSequenceNumber, simply discard the received LSA without
1901 acknowledging it. (In this case, the LSA's LS sequence number is
1902 wrapping, and the MaxSequenceNumber LSA must be completely
1903 flushed before any new LSA instance can be introduced). */
1905 else if (ret
> 0) /* Database copy is more recent */
1907 if (IS_LSA_MAXAGE (current
) &&
1908 current
->data
->ls_seqnum
== htonl (OSPF_MAX_SEQUENCE_NUMBER
))
1910 DISCARD_LSA (lsa
, 7);
1912 /* Otherwise, as long as the database copy has not been sent in a
1913 Link State Update within the last MinLSArrival seconds, send the
1914 database copy back to the sending neighbor, encapsulated within
1915 a Link State Update Packet. The Link State Update Packet should
1916 be sent directly to the neighbor. In so doing, do not put the
1917 database copy of the LSA on the neighbor's link state
1918 retransmission list, and do not acknowledge the received (less
1919 recent) LSA instance. */
1924 gettimeofday (&now
, NULL
);
1926 if (tv_cmp (tv_sub (now
, current
->tv_orig
),
1927 int2tv (OSPF_MIN_LS_ARRIVAL
)) > 0)
1928 /* Trap NSSA type later.*/
1929 ospf_ls_upd_send_lsa (nbr
, current
, OSPF_SEND_PACKET_DIRECT
);
1930 DISCARD_LSA (lsa
, 8);
1935 #ifdef HAVE_OPAQUE_LSA
1937 * Now that previously originated Opaque-LSAs those which not yet
1938 * installed into LSDB are captured, take several steps to clear
1939 * them completely from the routing domain, before proceeding to
1940 * origination for the current target Opaque-LSAs.
1942 while (listcount (mylsa_acks
) > 0)
1943 ospf_ls_ack_send_list (oi
, mylsa_acks
, nbr
->address
.u
.prefix4
);
1945 if (listcount (mylsa_upds
) > 0)
1946 ospf_opaque_self_originated_lsa_received (nbr
, mylsa_upds
);
1948 list_delete (mylsa_upds
);
1949 list_delete (mylsa_acks
);
1950 #endif /* HAVE_OPAQUE_LSA */
1952 assert (listcount (lsas
) == 0);
1956 /* OSPF Link State Acknowledgment message read -- RFC2328 Section 13.7. */
1958 ospf_ls_ack (struct ip
*iph
, struct ospf_header
*ospfh
,
1959 struct stream
*s
, struct ospf_interface
*oi
, u_int16_t size
)
1961 struct ospf_neighbor
*nbr
;
1962 #ifdef HAVE_OPAQUE_LSA
1963 struct list
*opaque_acks
;
1964 #endif /* HAVE_OPAQUE_LSA */
1966 /* increment statistics. */
1969 nbr
= ospf_nbr_lookup (oi
, iph
, ospfh
);
1972 zlog_warn ("Link State Acknowledgment: Unknown Neighbor %s.",
1973 inet_ntoa (ospfh
->router_id
));
1977 if (nbr
->state
< NSM_Exchange
)
1979 zlog_warn ("Link State Acknowledgment: "
1980 "Neighbor[%s] state %s is less than Exchange",
1981 inet_ntoa (ospfh
->router_id
),
1982 LOOKUP(ospf_nsm_state_msg
, nbr
->state
));
1986 #ifdef HAVE_OPAQUE_LSA
1987 opaque_acks
= list_new ();
1988 #endif /* HAVE_OPAQUE_LSA */
1990 while (size
>= OSPF_LSA_HEADER_SIZE
)
1992 struct ospf_lsa
*lsa
, *lsr
;
1994 lsa
= ospf_lsa_new ();
1995 lsa
->data
= (struct lsa_header
*) STREAM_PNT (s
);
1997 /* lsah = (struct lsa_header *) STREAM_PNT (s); */
1998 size
-= OSPF_LSA_HEADER_SIZE
;
1999 stream_forward (s
, OSPF_LSA_HEADER_SIZE
);
2001 if (lsa
->data
->type
< OSPF_MIN_LSA
|| lsa
->data
->type
>= OSPF_MAX_LSA
)
2004 ospf_lsa_discard (lsa
);
2008 lsr
= ospf_ls_retransmit_lookup (nbr
, lsa
);
2010 if (lsr
!= NULL
&& lsr
->data
->ls_seqnum
== lsa
->data
->ls_seqnum
)
2012 #ifdef HAVE_OPAQUE_LSA
2013 /* Keep this LSA entry for later reference. */
2014 if (IS_OPAQUE_LSA (lsr
->data
->type
))
2015 listnode_add (opaque_acks
, ospf_lsa_dup (lsr
));
2016 #endif /* HAVE_OPAQUE_LSA */
2018 ospf_ls_retransmit_delete (nbr
, lsr
);
2022 ospf_lsa_discard (lsa
);
2025 #ifdef HAVE_OPAQUE_LSA
2026 if (listcount (opaque_acks
) > 0)
2027 ospf_opaque_ls_ack_received (nbr
, opaque_acks
);
2029 list_delete (opaque_acks
);
2031 #endif /* HAVE_OPAQUE_LSA */
2035 ospf_recv_packet (int fd
, struct interface
**ifp
)
2040 struct stream
*ibuf
;
2041 unsigned int ifindex
= 0;
2043 /* Header and data both require alignment. */
2044 char buff
[CMSG_SPACE(SOPT_SIZE_CMSG_IFINDEX_IPV4())];
2047 memset (&msgh
, 0, sizeof (struct msghdr
));
2048 msgh
.msg_iov
= &iov
;
2049 msgh
.msg_iovlen
= 1;
2050 msgh
.msg_control
= (caddr_t
) buff
;
2051 msgh
.msg_controllen
= sizeof (buff
);
2053 ret
= recvfrom (fd
, (void *)&iph
, sizeof (iph
), MSG_PEEK
, NULL
, 0);
2055 if (ret
!= sizeof (iph
))
2057 zlog_warn ("ospf_recv_packet packet smaller than ip header");
2058 /* XXX: We peeked, and thus perhaps should discard this packet. */
2062 sockopt_iphdrincl_swab_systoh (&iph
);
2064 ip_len
= iph
.ip_len
;
2066 #if !defined(GNU_LINUX) && (OpenBSD < 200311)
2068 * Kernel network code touches incoming IP header parameters,
2069 * before protocol specific processing.
2071 * 1) Convert byteorder to host representation.
2072 * --> ip_len, ip_id, ip_off
2074 * 2) Adjust ip_len to strip IP header size!
2075 * --> If user process receives entire IP packet via RAW
2076 * socket, it must consider adding IP header size to
2077 * the "ip_len" field of "ip" structure.
2079 * For more details, see <netinet/ip_input.c>.
2081 ip_len
= ip_len
+ (iph
.ip_hl
<< 2);
2084 ibuf
= stream_new (ip_len
);
2085 iov
.iov_base
= STREAM_DATA (ibuf
);
2086 iov
.iov_len
= ip_len
;
2087 ret
= recvmsg (fd
, &msgh
, 0);
2089 ifindex
= getsockopt_ifindex (AF_INET
, &msgh
);
2091 *ifp
= if_lookup_by_index (ifindex
);
2095 zlog_warn ("ospf_recv_packet short read. "
2096 "ip_len %d bytes read %d", ip_len
, ret
);
2104 struct ospf_interface
*
2105 ospf_associate_packet_vl (struct ospf
*ospf
, struct interface
*ifp
,
2106 struct ip
*iph
, struct ospf_header
*ospfh
)
2108 struct ospf_interface
*rcv_oi
;
2109 struct ospf_vl_data
*vl_data
;
2110 struct ospf_area
*vl_area
;
2111 struct listnode
*node
;
2113 if (IN_MULTICAST (ntohl (iph
->ip_dst
.s_addr
)) ||
2114 !OSPF_IS_AREA_BACKBONE (ospfh
))
2117 /* look for local OSPF interface matching the destination
2118 * to determine Area ID. We presume therefore the destination address
2119 * is unique, or at least (for "unnumbered" links), not used in other
2122 if ((rcv_oi
= ospf_if_lookup_by_local_addr (ospf
, NULL
,
2123 iph
->ip_dst
)) == NULL
)
2126 for (node
= listhead (ospf
->vlinks
); node
; nextnode (node
))
2128 if ((vl_data
= getdata (node
)) == NULL
)
2131 vl_area
= ospf_area_lookup_by_area_id (ospf
, vl_data
->vl_area_id
);
2135 if (OSPF_AREA_SAME (&vl_area
, &rcv_oi
->area
) &&
2136 IPV4_ADDR_SAME (&vl_data
->vl_peer
, &ospfh
->router_id
))
2138 if (IS_DEBUG_OSPF_EVENT
)
2139 zlog_debug ("associating packet with %s",
2140 IF_NAME (vl_data
->vl_oi
));
2141 if (! CHECK_FLAG (vl_data
->vl_oi
->ifp
->flags
, IFF_UP
))
2143 if (IS_DEBUG_OSPF_EVENT
)
2144 zlog_debug ("This VL is not up yet, sorry");
2148 return vl_data
->vl_oi
;
2152 if (IS_DEBUG_OSPF_EVENT
)
2153 zlog_debug ("couldn't find any VL to associate the packet with");
2159 ospf_check_area_id (struct ospf_interface
*oi
, struct ospf_header
*ospfh
)
2161 /* Check match the Area ID of the receiving interface. */
2162 if (OSPF_AREA_SAME (&oi
->area
, &ospfh
))
2168 /* Unbound socket will accept any Raw IP packets if proto is matched.
2169 To prevent it, compare src IP address and i/f address with masking
2170 i/f network mask. */
2172 ospf_check_network_mask (struct ospf_interface
*oi
, struct in_addr ip_src
)
2174 struct in_addr mask
, me
, him
;
2176 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
||
2177 oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
2180 masklen2ip (oi
->address
->prefixlen
, &mask
);
2182 me
.s_addr
= oi
->address
->u
.prefix4
.s_addr
& mask
.s_addr
;
2183 him
.s_addr
= ip_src
.s_addr
& mask
.s_addr
;
2185 if (IPV4_ADDR_SAME (&me
, &him
))
2192 ospf_check_auth (struct ospf_interface
*oi
, struct stream
*ibuf
,
2193 struct ospf_header
*ospfh
)
2196 struct crypt_key
*ck
;
2198 switch (ntohs (ospfh
->auth_type
))
2200 case OSPF_AUTH_NULL
:
2203 case OSPF_AUTH_SIMPLE
:
2204 if (!memcmp (OSPF_IF_PARAM (oi
, auth_simple
), ospfh
->u
.auth_data
, OSPF_AUTH_SIMPLE_SIZE
))
2209 case OSPF_AUTH_CRYPTOGRAPHIC
:
2210 if ((ck
= getdata (OSPF_IF_PARAM (oi
,auth_crypt
)->tail
)) == NULL
)
2216 /* This is very basic, the digest processing is elsewhere */
2217 if (ospfh
->u
.crypt
.auth_data_len
== OSPF_AUTH_MD5_SIZE
&&
2218 ospfh
->u
.crypt
.key_id
== ck
->key_id
&&
2219 ntohs (ospfh
->length
) + OSPF_AUTH_SIMPLE_SIZE
<= stream_get_size (ibuf
))
2233 ospf_check_sum (struct ospf_header
*ospfh
)
2237 int in_cksum (void *ptr
, int nbytes
);
2239 /* clear auth_data for checksum. */
2240 memset (ospfh
->u
.auth_data
, 0, OSPF_AUTH_SIMPLE_SIZE
);
2242 /* keep checksum and clear. */
2243 sum
= ospfh
->checksum
;
2244 memset (&ospfh
->checksum
, 0, sizeof (u_int16_t
));
2246 /* calculate checksum. */
2247 ret
= in_cksum (ospfh
, ntohs (ospfh
->length
));
2251 zlog_info ("ospf_check_sum(): checksum mismatch, my %X, his %X",
2259 /* OSPF Header verification. */
2261 ospf_verify_header (struct stream
*ibuf
, struct ospf_interface
*oi
,
2262 struct ip
*iph
, struct ospf_header
*ospfh
)
2264 /* check version. */
2265 if (ospfh
->version
!= OSPF_VERSION
)
2267 zlog_warn ("interface %s: ospf_read version number mismatch.",
2272 /* Check Area ID. */
2273 if (!ospf_check_area_id (oi
, ospfh
))
2275 zlog_warn ("interface %s: ospf_read invalid Area ID %s.",
2276 IF_NAME (oi
), inet_ntoa (ospfh
->area_id
));
2280 /* Check network mask, Silently discarded. */
2281 if (! ospf_check_network_mask (oi
, iph
->ip_src
))
2283 zlog_warn ("interface %s: ospf_read network address is not same [%s]",
2284 IF_NAME (oi
), inet_ntoa (iph
->ip_src
));
2288 /* Check authentication. */
2289 if (ospf_auth_type (oi
) != ntohs (ospfh
->auth_type
))
2291 zlog_warn ("interface %s: ospf_read authentication type mismatch.",
2296 if (! ospf_check_auth (oi
, ibuf
, ospfh
))
2298 zlog_warn ("interface %s: ospf_read authentication failed.",
2303 /* if check sum is invalid, packet is discarded. */
2304 if (ntohs (ospfh
->auth_type
) != OSPF_AUTH_CRYPTOGRAPHIC
)
2306 if (! ospf_check_sum (ospfh
))
2308 zlog_warn ("interface %s: ospf_read packet checksum error %s",
2309 IF_NAME (oi
), inet_ntoa (ospfh
->router_id
));
2315 if (ospfh
->checksum
!= 0)
2317 if (ospf_check_md5_digest (oi
, ibuf
, ntohs (ospfh
->length
)) == 0)
2319 zlog_warn ("interface %s: ospf_read md5 authentication failed.",
2328 /* Starting point of packet process function. */
2330 ospf_read (struct thread
*thread
)
2333 struct stream
*ibuf
;
2335 struct ospf_interface
*oi
;
2337 struct ospf_header
*ospfh
;
2339 struct interface
*ifp
;
2341 /* first of all get interface pointer. */
2342 ospf
= THREAD_ARG (thread
);
2343 ospf
->t_read
= NULL
;
2345 /* read OSPF packet. */
2346 ibuf
= ospf_recv_packet (ospf
->fd
, &ifp
);
2350 iph
= (struct ip
*) STREAM_DATA (ibuf
);
2351 sockopt_iphdrincl_swab_systoh (iph
);
2354 /* Handle cases where the platform does not support retrieving the ifindex,
2355 and also platforms (such as Solaris 8) that claim to support ifindex
2356 retrieval but do not. */
2357 ifp
= if_lookup_address (iph
->ip_src
);
2365 /* prepare for next packet. */
2366 ospf
->t_read
= thread_add_read (master
, ospf_read
, ospf
, ospf
->fd
);
2368 /* IP Header dump. */
2369 if (IS_DEBUG_OSPF_PACKET(0, RECV
))
2370 ospf_ip_header_dump (iph
);
2372 /* Self-originated packet should be discarded silently. */
2373 if (ospf_if_lookup_by_local_addr (ospf
, NULL
, iph
->ip_src
))
2375 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2377 zlog_debug ("ospf_read[%s]: Dropping self-originated packet",
2378 inet_ntoa (iph
->ip_src
));
2384 /* Adjust size to message length. */
2385 stream_forward (ibuf
, iph
->ip_hl
* 4);
2387 /* Get ospf packet header. */
2388 ospfh
= (struct ospf_header
*) STREAM_PNT (ibuf
);
2390 /* associate packet with ospf interface */
2391 oi
= ospf_if_lookup_recv_if (ospf
, iph
->ip_src
);
2393 /* if no local ospf_interface,
2394 * or header area is backbone but ospf_interface is not
2395 * check for VLINK interface
2397 if ( (oi
== NULL
) ||
2398 (OSPF_IS_AREA_ID_BACKBONE(ospfh
->area_id
)
2399 && !OSPF_IS_AREA_ID_BACKBONE(oi
->area
->area_id
))
2402 if ((oi
= ospf_associate_packet_vl (ospf
, ifp
, iph
, ospfh
)) == NULL
)
2404 zlog_warn ("Packet from [%s] received on link %s"
2405 " but no ospf_interface",
2406 inet_ntoa (iph
->ip_src
), ifp
->name
);
2412 /* else it must be a local ospf interface, check it was received on
2415 else if (oi
->ifp
!= ifp
)
2417 zlog_warn ("Packet from [%s] received on wrong link %s",
2418 inet_ntoa (iph
->ip_src
), ifp
->name
);
2424 * If the received packet is destined for AllDRouters, the packet
2425 * should be accepted only if the received ospf interface state is
2426 * either DR or Backup -- endo.
2428 if (iph
->ip_dst
.s_addr
== htonl (OSPF_ALLDROUTERS
)
2429 && (oi
->state
!= ISM_DR
&& oi
->state
!= ISM_Backup
))
2431 zlog_info ("Packet for AllDRouters from [%s] via [%s] (ISM: %s)",
2432 inet_ntoa (iph
->ip_src
), IF_NAME (oi
),
2433 LOOKUP (ospf_ism_state_msg
, oi
->state
));
2438 /* Show debug receiving packet. */
2439 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, RECV
))
2441 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, DETAIL
))
2443 zlog_debug ("-----------------------------------------------------");
2444 ospf_packet_dump (ibuf
);
2447 zlog_debug ("%s received from [%s] via [%s]",
2448 ospf_packet_type_str
[ospfh
->type
],
2449 inet_ntoa (ospfh
->router_id
), IF_NAME (oi
));
2450 zlog_debug (" src [%s],", inet_ntoa (iph
->ip_src
));
2451 zlog_debug (" dst [%s]", inet_ntoa (iph
->ip_dst
));
2453 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, DETAIL
))
2454 zlog_debug ("-----------------------------------------------------");
2457 /* Some header verification. */
2458 ret
= ospf_verify_header (ibuf
, oi
, iph
, ospfh
);
2461 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, RECV
))
2463 zlog_debug ("ospf_read[%s/%s]: Header check failed, "
2465 ospf_packet_type_str
[ospfh
->type
],
2466 inet_ntoa (iph
->ip_src
));
2472 stream_forward (ibuf
, OSPF_HEADER_SIZE
);
2474 /* Adjust size to message length. */
2475 length
= ntohs (ospfh
->length
) - OSPF_HEADER_SIZE
;
2477 /* Read rest of the packet and call each sort of packet routine. */
2478 switch (ospfh
->type
)
2480 case OSPF_MSG_HELLO
:
2481 ospf_hello (iph
, ospfh
, ibuf
, oi
, length
);
2483 case OSPF_MSG_DB_DESC
:
2484 ospf_db_desc (iph
, ospfh
, ibuf
, oi
, length
);
2486 case OSPF_MSG_LS_REQ
:
2487 ospf_ls_req (iph
, ospfh
, ibuf
, oi
, length
);
2489 case OSPF_MSG_LS_UPD
:
2490 ospf_ls_upd (iph
, ospfh
, ibuf
, oi
, length
);
2492 case OSPF_MSG_LS_ACK
:
2493 ospf_ls_ack (iph
, ospfh
, ibuf
, oi
, length
);
2496 zlog (NULL
, LOG_WARNING
,
2497 "interface %s: OSPF packet header type %d is illegal",
2498 IF_NAME (oi
), ospfh
->type
);
2506 /* Make OSPF header. */
2508 ospf_make_header (int type
, struct ospf_interface
*oi
, struct stream
*s
)
2510 struct ospf_header
*ospfh
;
2512 ospfh
= (struct ospf_header
*) STREAM_DATA (s
);
2514 ospfh
->version
= (u_char
) OSPF_VERSION
;
2515 ospfh
->type
= (u_char
) type
;
2517 ospfh
->router_id
= oi
->ospf
->router_id
;
2519 ospfh
->checksum
= 0;
2520 ospfh
->area_id
= oi
->area
->area_id
;
2521 ospfh
->auth_type
= htons (ospf_auth_type (oi
));
2523 memset (ospfh
->u
.auth_data
, 0, OSPF_AUTH_SIMPLE_SIZE
);
2525 ospf_output_forward (s
, OSPF_HEADER_SIZE
);
2528 /* Make Authentication Data. */
2530 ospf_make_auth (struct ospf_interface
*oi
, struct ospf_header
*ospfh
)
2532 struct crypt_key
*ck
;
2534 switch (ospf_auth_type (oi
))
2536 case OSPF_AUTH_NULL
:
2537 /* memset (ospfh->u.auth_data, 0, sizeof (ospfh->u.auth_data)); */
2539 case OSPF_AUTH_SIMPLE
:
2540 memcpy (ospfh
->u
.auth_data
, OSPF_IF_PARAM (oi
, auth_simple
),
2541 OSPF_AUTH_SIMPLE_SIZE
);
2543 case OSPF_AUTH_CRYPTOGRAPHIC
:
2544 /* If key is not set, then set 0. */
2545 if (list_isempty (OSPF_IF_PARAM (oi
, auth_crypt
)))
2547 ospfh
->u
.crypt
.zero
= 0;
2548 ospfh
->u
.crypt
.key_id
= 0;
2549 ospfh
->u
.crypt
.auth_data_len
= OSPF_AUTH_MD5_SIZE
;
2553 ck
= getdata (OSPF_IF_PARAM (oi
, auth_crypt
)->tail
);
2554 ospfh
->u
.crypt
.zero
= 0;
2555 ospfh
->u
.crypt
.key_id
= ck
->key_id
;
2556 ospfh
->u
.crypt
.auth_data_len
= OSPF_AUTH_MD5_SIZE
;
2558 /* note: the seq is done in ospf_make_md5_digest() */
2561 /* memset (ospfh->u.auth_data, 0, sizeof (ospfh->u.auth_data)); */
2568 /* Fill rest of OSPF header. */
2570 ospf_fill_header (struct ospf_interface
*oi
,
2571 struct stream
*s
, u_int16_t length
)
2573 struct ospf_header
*ospfh
;
2575 ospfh
= (struct ospf_header
*) STREAM_DATA (s
);
2578 ospfh
->length
= htons (length
);
2580 /* Calculate checksum. */
2581 if (ntohs (ospfh
->auth_type
) != OSPF_AUTH_CRYPTOGRAPHIC
)
2582 ospfh
->checksum
= in_cksum (ospfh
, length
);
2584 ospfh
->checksum
= 0;
2586 /* Add Authentication Data. */
2587 ospf_make_auth (oi
, ospfh
);
2591 ospf_make_hello (struct ospf_interface
*oi
, struct stream
*s
)
2593 struct ospf_neighbor
*nbr
;
2594 struct route_node
*rn
;
2595 u_int16_t length
= OSPF_HELLO_MIN_SIZE
;
2596 struct in_addr mask
;
2600 /* Set netmask of interface. */
2601 if (oi
->type
!= OSPF_IFTYPE_POINTOPOINT
&&
2602 oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
2603 masklen2ip (oi
->address
->prefixlen
, &mask
);
2605 memset ((char *) &mask
, 0, sizeof (struct in_addr
));
2606 stream_put_ipv4 (s
, mask
.s_addr
);
2608 /* Set Hello Interval. */
2609 stream_putw (s
, OSPF_IF_PARAM (oi
, v_hello
));
2611 if (IS_DEBUG_OSPF_EVENT
)
2612 zlog_debug ("make_hello: options: %x, int: %s",
2613 OPTIONS(oi
), IF_NAME (oi
));
2616 stream_putc (s
, OPTIONS (oi
));
2618 /* Set Router Priority. */
2619 stream_putc (s
, PRIORITY (oi
));
2621 /* Set Router Dead Interval. */
2622 stream_putl (s
, OSPF_IF_PARAM (oi
, v_wait
));
2624 /* Set Designated Router. */
2625 stream_put_ipv4 (s
, DR (oi
).s_addr
);
2629 /* Set Backup Designated Router. */
2630 stream_put_ipv4 (s
, BDR (oi
).s_addr
);
2632 /* Add neighbor seen. */
2633 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
2634 if ((nbr
= rn
->info
))
2635 if (nbr
->router_id
.s_addr
!= 0) /* Ignore 0.0.0.0 node. */
2636 if (nbr
->state
!= NSM_Attempt
) /* Ignore Down neighbor. */
2637 if (nbr
->state
!= NSM_Down
) /* This is myself for DR election. */
2638 if (!IPV4_ADDR_SAME (&nbr
->router_id
, &oi
->ospf
->router_id
))
2640 /* Check neighbor is sane? */
2641 if (nbr
->d_router
.s_addr
!= 0
2642 && IPV4_ADDR_SAME (&nbr
->d_router
, &oi
->address
->u
.prefix4
)
2643 && IPV4_ADDR_SAME (&nbr
->bd_router
, &oi
->address
->u
.prefix4
))
2646 stream_put_ipv4 (s
, nbr
->router_id
.s_addr
);
2650 /* Let neighbor generate BackupSeen. */
2653 stream_set_putp (s
, p
);
2654 stream_put_ipv4 (s
, 0);
2661 ospf_make_db_desc (struct ospf_interface
*oi
, struct ospf_neighbor
*nbr
,
2664 struct ospf_lsa
*lsa
;
2665 u_int16_t length
= OSPF_DB_DESC_MIN_SIZE
;
2669 struct ospf_lsdb
*lsdb
;
2671 /* Set Interface MTU. */
2672 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
2675 stream_putw (s
, oi
->ifp
->mtu
);
2678 options
= OPTIONS (oi
);
2679 #ifdef HAVE_OPAQUE_LSA
2680 if (CHECK_FLAG (oi
->ospf
->config
, OSPF_OPAQUE_CAPABLE
))
2682 if (IS_SET_DD_I (nbr
->dd_flags
)
2683 || CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
))
2685 * Set O-bit in the outgoing DD packet for capablity negotiation,
2686 * if one of following case is applicable.
2688 * 1) WaitTimer expiration event triggered the neighbor state to
2689 * change to Exstart, but no (valid) DD packet has received
2690 * from the neighbor yet.
2692 * 2) At least one DD packet with O-bit on has received from the
2695 SET_FLAG (options
, OSPF_OPTION_O
);
2697 #endif /* HAVE_OPAQUE_LSA */
2698 stream_putc (s
, options
);
2700 /* Keep pointer to flags. */
2701 pp
= stream_get_putp (s
);
2702 stream_putc (s
, nbr
->dd_flags
);
2704 /* Set DD Sequence Number. */
2705 stream_putl (s
, nbr
->dd_seqnum
);
2707 if (ospf_db_summary_isempty (nbr
))
2709 if (nbr
->state
>= NSM_Exchange
)
2711 nbr
->dd_flags
&= ~OSPF_DD_FLAG_M
;
2712 /* Set DD flags again */
2713 stream_set_putp (s
, pp
);
2714 stream_putc (s
, nbr
->dd_flags
);
2719 /* Describe LSA Header from Database Summary List. */
2720 lsdb
= &nbr
->db_sum
;
2722 for (i
= OSPF_MIN_LSA
; i
< OSPF_MAX_LSA
; i
++)
2724 struct route_table
*table
= lsdb
->type
[i
].db
;
2725 struct route_node
*rn
;
2727 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
2728 if ((lsa
= rn
->info
) != NULL
)
2730 #ifdef HAVE_OPAQUE_LSA
2731 if (IS_OPAQUE_LSA (lsa
->data
->type
)
2732 && (! CHECK_FLAG (options
, OSPF_OPTION_O
)))
2734 /* Suppress advertising opaque-informations. */
2735 /* Remove LSA from DB summary list. */
2736 ospf_lsdb_delete (lsdb
, lsa
);
2739 #endif /* HAVE_OPAQUE_LSA */
2741 if (!CHECK_FLAG (lsa
->flags
, OSPF_LSA_DISCARD
))
2743 struct lsa_header
*lsah
;
2746 /* DD packet overflows interface MTU. */
2747 if (length
+ OSPF_LSA_HEADER_SIZE
> ospf_packet_max (oi
))
2750 /* Keep pointer to LS age. */
2751 lsah
= (struct lsa_header
*) (STREAM_DATA (s
) +
2752 stream_get_putp (s
));
2754 /* Proceed stream pointer. */
2755 stream_put (s
, lsa
->data
, OSPF_LSA_HEADER_SIZE
);
2756 length
+= OSPF_LSA_HEADER_SIZE
;
2759 ls_age
= LS_AGE (lsa
);
2760 lsah
->ls_age
= htons (ls_age
);
2764 /* Remove LSA from DB summary list. */
2765 ospf_lsdb_delete (lsdb
, lsa
);
2773 ospf_make_ls_req_func (struct stream
*s
, u_int16_t
*length
,
2774 unsigned long delta
, struct ospf_neighbor
*nbr
,
2775 struct ospf_lsa
*lsa
)
2777 struct ospf_interface
*oi
;
2781 /* LS Request packet overflows interface MTU. */
2782 if (*length
+ delta
> ospf_packet_max(oi
))
2785 stream_putl (s
, lsa
->data
->type
);
2786 stream_put_ipv4 (s
, lsa
->data
->id
.s_addr
);
2787 stream_put_ipv4 (s
, lsa
->data
->adv_router
.s_addr
);
2789 ospf_lsa_unlock (nbr
->ls_req_last
);
2790 nbr
->ls_req_last
= ospf_lsa_lock (lsa
);
2797 ospf_make_ls_req (struct ospf_neighbor
*nbr
, struct stream
*s
)
2799 struct ospf_lsa
*lsa
;
2800 u_int16_t length
= OSPF_LS_REQ_MIN_SIZE
;
2801 unsigned long delta
= stream_get_putp(s
)+12;
2802 struct route_table
*table
;
2803 struct route_node
*rn
;
2805 struct ospf_lsdb
*lsdb
;
2807 lsdb
= &nbr
->ls_req
;
2809 for (i
= OSPF_MIN_LSA
; i
< OSPF_MAX_LSA
; i
++)
2811 table
= lsdb
->type
[i
].db
;
2812 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
2813 if ((lsa
= (rn
->info
)) != NULL
)
2814 if (ospf_make_ls_req_func (s
, &length
, delta
, nbr
, lsa
) == 0)
2816 route_unlock_node (rn
);
2824 ls_age_increment (struct ospf_lsa
*lsa
, int delay
)
2828 age
= IS_LSA_MAXAGE (lsa
) ? OSPF_LSA_MAXAGE
: LS_AGE (lsa
) + delay
;
2830 return (age
> OSPF_LSA_MAXAGE
? OSPF_LSA_MAXAGE
: age
);
2834 ospf_make_ls_upd (struct ospf_interface
*oi
, struct list
*update
, struct stream
*s
)
2836 struct ospf_lsa
*lsa
;
2837 struct listnode
*node
;
2838 u_int16_t length
= OSPF_LS_UPD_MIN_SIZE
;
2839 unsigned int size_noauth
;
2840 unsigned long delta
= stream_get_putp (s
);
2844 if (IS_DEBUG_OSPF_EVENT
)
2845 zlog_debug ("ospf_make_ls_upd: Start");
2847 pp
= stream_get_putp (s
);
2848 ospf_output_forward (s
, OSPF_LS_UPD_MIN_SIZE
);
2850 /* Calculate amount of packet usable for data. */
2851 size_noauth
= stream_get_size(s
) - ospf_packet_authspace(oi
);
2853 while ((node
= listhead (update
)) != NULL
)
2855 struct lsa_header
*lsah
;
2858 if (IS_DEBUG_OSPF_EVENT
)
2859 zlog_debug ("ospf_make_ls_upd: List Iteration");
2861 lsa
= getdata (node
);
2866 if (length
+ delta
+ ntohs (lsa
->data
->length
) > size_noauth
)
2869 /* Keep pointer to LS age. */
2870 lsah
= (struct lsa_header
*) (STREAM_DATA (s
) + stream_get_putp (s
));
2872 /* Put LSA to Link State Request. */
2873 stream_put (s
, lsa
->data
, ntohs (lsa
->data
->length
));
2876 /* each hop must increment an lsa_age by transmit_delay
2877 of OSPF interface */
2878 ls_age
= ls_age_increment (lsa
, OSPF_IF_PARAM (oi
, transmit_delay
));
2879 lsah
->ls_age
= htons (ls_age
);
2881 length
+= ntohs (lsa
->data
->length
);
2884 list_delete_node (update
, node
);
2885 ospf_lsa_unlock (lsa
);
2888 /* Now set #LSAs. */
2889 stream_set_putp (s
, pp
);
2890 stream_putl (s
, count
);
2892 stream_set_putp (s
, s
->endp
);
2894 if (IS_DEBUG_OSPF_EVENT
)
2895 zlog_debug ("ospf_make_ls_upd: Stop");
2900 ospf_make_ls_ack (struct ospf_interface
*oi
, struct list
*ack
, struct stream
*s
)
2902 struct list
*rm_list
;
2903 struct listnode
*node
;
2904 u_int16_t length
= OSPF_LS_ACK_MIN_SIZE
;
2905 unsigned long delta
= stream_get_putp(s
) + 24;
2906 struct ospf_lsa
*lsa
;
2908 rm_list
= list_new ();
2910 for (node
= listhead (ack
); node
; nextnode (node
))
2912 lsa
= getdata (node
);
2915 if (length
+ delta
> ospf_packet_max (oi
))
2918 stream_put (s
, lsa
->data
, OSPF_LSA_HEADER_SIZE
);
2919 length
+= OSPF_LSA_HEADER_SIZE
;
2921 listnode_add (rm_list
, lsa
);
2924 /* Remove LSA from LS-Ack list. */
2925 for (node
= listhead (rm_list
); node
; nextnode (node
))
2927 lsa
= (struct ospf_lsa
*) getdata (node
);
2929 listnode_delete (ack
, lsa
);
2930 ospf_lsa_unlock (lsa
);
2933 list_delete (rm_list
);
2939 ospf_hello_send_sub (struct ospf_interface
*oi
, struct in_addr
*addr
)
2941 struct ospf_packet
*op
;
2942 u_int16_t length
= OSPF_HEADER_SIZE
;
2944 op
= ospf_packet_new (oi
->ifp
->mtu
);
2946 /* Prepare OSPF common header. */
2947 ospf_make_header (OSPF_MSG_HELLO
, oi
, op
->s
);
2949 /* Prepare OSPF Hello body. */
2950 length
+= ospf_make_hello (oi
, op
->s
);
2952 /* Fill OSPF header. */
2953 ospf_fill_header (oi
, op
->s
, length
);
2955 /* Set packet length. */
2956 op
->length
= length
;
2958 op
->dst
.s_addr
= addr
->s_addr
;
2960 /* Add packet to the interface output queue. */
2961 ospf_packet_add (oi
, op
);
2963 /* Hook thread to write packet. */
2964 OSPF_ISM_WRITE_ON (oi
->ospf
);
2968 ospf_poll_send (struct ospf_nbr_nbma
*nbr_nbma
)
2970 struct ospf_interface
*oi
;
2975 /* If this is passive interface, do not send OSPF Hello. */
2976 if (OSPF_IF_PARAM (oi
, passive_interface
) == OSPF_IF_PASSIVE
)
2979 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
2982 if (nbr_nbma
->nbr
!= NULL
&& nbr_nbma
->nbr
->state
!= NSM_Down
)
2985 if (PRIORITY(oi
) == 0)
2988 if (nbr_nbma
->priority
== 0
2989 && oi
->state
!= ISM_DR
&& oi
->state
!= ISM_Backup
)
2992 ospf_hello_send_sub (oi
, &nbr_nbma
->addr
);
2996 ospf_poll_timer (struct thread
*thread
)
2998 struct ospf_nbr_nbma
*nbr_nbma
;
3000 nbr_nbma
= THREAD_ARG (thread
);
3001 nbr_nbma
->t_poll
= NULL
;
3003 if (IS_DEBUG_OSPF (nsm
, NSM_TIMERS
))
3004 zlog (NULL
, LOG_DEBUG
, "NSM[%s:%s]: Timer (Poll timer expire)",
3005 IF_NAME (nbr_nbma
->oi
), inet_ntoa (nbr_nbma
->addr
));
3007 ospf_poll_send (nbr_nbma
);
3009 if (nbr_nbma
->v_poll
> 0)
3010 OSPF_POLL_TIMER_ON (nbr_nbma
->t_poll
, ospf_poll_timer
,
3018 ospf_hello_reply_timer (struct thread
*thread
)
3020 struct ospf_neighbor
*nbr
;
3022 nbr
= THREAD_ARG (thread
);
3023 nbr
->t_hello_reply
= NULL
;
3027 if (IS_DEBUG_OSPF (nsm
, NSM_TIMERS
))
3028 zlog (NULL
, LOG_DEBUG
, "NSM[%s:%s]: Timer (hello-reply timer expire)",
3029 IF_NAME (nbr
->oi
), inet_ntoa (nbr
->router_id
));
3031 ospf_hello_send_sub (nbr
->oi
, &nbr
->address
.u
.prefix4
);
3036 /* Send OSPF Hello. */
3038 ospf_hello_send (struct ospf_interface
*oi
)
3040 struct ospf_packet
*op
;
3041 u_int16_t length
= OSPF_HEADER_SIZE
;
3043 /* If this is passive interface, do not send OSPF Hello. */
3044 if (OSPF_IF_PARAM (oi
, passive_interface
) == OSPF_IF_PASSIVE
)
3047 op
= ospf_packet_new (oi
->ifp
->mtu
);
3049 /* Prepare OSPF common header. */
3050 ospf_make_header (OSPF_MSG_HELLO
, oi
, op
->s
);
3052 /* Prepare OSPF Hello body. */
3053 length
+= ospf_make_hello (oi
, op
->s
);
3055 /* Fill OSPF header. */
3056 ospf_fill_header (oi
, op
->s
, length
);
3058 /* Set packet length. */
3059 op
->length
= length
;
3061 if (oi
->type
== OSPF_IFTYPE_NBMA
)
3063 struct ospf_neighbor
*nbr
;
3064 struct route_node
*rn
;
3066 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
3067 if ((nbr
= rn
->info
))
3068 if (nbr
!= oi
->nbr_self
)
3069 if (nbr
->state
!= NSM_Down
)
3071 /* RFC 2328 Section 9.5.1
3072 If the router is not eligible to become Designated Router,
3073 it must periodically send Hello Packets to both the
3074 Designated Router and the Backup Designated Router (if they
3076 if (PRIORITY(oi
) == 0 &&
3077 IPV4_ADDR_CMP(&DR(oi
), &nbr
->address
.u
.prefix4
) &&
3078 IPV4_ADDR_CMP(&BDR(oi
), &nbr
->address
.u
.prefix4
))
3081 /* If the router is eligible to become Designated Router, it
3082 must periodically send Hello Packets to all neighbors that
3083 are also eligible. In addition, if the router is itself the
3084 Designated Router or Backup Designated Router, it must also
3085 send periodic Hello Packets to all other neighbors. */
3087 if (nbr
->priority
== 0 && oi
->state
== ISM_DROther
)
3089 /* if oi->state == Waiting, send hello to all neighbors */
3091 struct ospf_packet
*op_dup
;
3093 op_dup
= ospf_packet_dup(op
);
3094 op_dup
->dst
= nbr
->address
.u
.prefix4
;
3096 /* Add packet to the interface output queue. */
3097 ospf_packet_add (oi
, op_dup
);
3099 OSPF_ISM_WRITE_ON (oi
->ospf
);
3103 ospf_packet_free (op
);
3107 /* Decide destination address. */
3108 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3109 op
->dst
.s_addr
= oi
->vl_data
->peer_addr
.s_addr
;
3111 op
->dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3113 /* Add packet to the interface output queue. */
3114 ospf_packet_add (oi
, op
);
3116 /* Hook thread to write packet. */
3117 OSPF_ISM_WRITE_ON (oi
->ospf
);
3121 /* Send OSPF Database Description. */
3123 ospf_db_desc_send (struct ospf_neighbor
*nbr
)
3125 struct ospf_interface
*oi
;
3126 struct ospf_packet
*op
;
3127 u_int16_t length
= OSPF_HEADER_SIZE
;
3130 op
= ospf_packet_new (oi
->ifp
->mtu
);
3132 /* Prepare OSPF common header. */
3133 ospf_make_header (OSPF_MSG_DB_DESC
, oi
, op
->s
);
3135 /* Prepare OSPF Database Description body. */
3136 length
+= ospf_make_db_desc (oi
, nbr
, op
->s
);
3138 /* Fill OSPF header. */
3139 ospf_fill_header (oi
, op
->s
, length
);
3141 /* Set packet length. */
3142 op
->length
= length
;
3144 /* Decide destination address. */
3145 op
->dst
= nbr
->address
.u
.prefix4
;
3147 /* Add packet to the interface output queue. */
3148 ospf_packet_add (oi
, op
);
3150 /* Hook thread to write packet. */
3151 OSPF_ISM_WRITE_ON (oi
->ospf
);
3153 /* Remove old DD packet, then copy new one and keep in neighbor structure. */
3155 ospf_packet_free (nbr
->last_send
);
3156 nbr
->last_send
= ospf_packet_dup (op
);
3157 gettimeofday (&nbr
->last_send_ts
, NULL
);
3160 /* Re-send Database Description. */
3162 ospf_db_desc_resend (struct ospf_neighbor
*nbr
)
3164 struct ospf_interface
*oi
;
3168 /* Add packet to the interface output queue. */
3169 ospf_packet_add (oi
, ospf_packet_dup (nbr
->last_send
));
3171 /* Hook thread to write packet. */
3172 OSPF_ISM_WRITE_ON (oi
->ospf
);
3175 /* Send Link State Request. */
3177 ospf_ls_req_send (struct ospf_neighbor
*nbr
)
3179 struct ospf_interface
*oi
;
3180 struct ospf_packet
*op
;
3181 u_int16_t length
= OSPF_HEADER_SIZE
;
3184 op
= ospf_packet_new (oi
->ifp
->mtu
);
3186 /* Prepare OSPF common header. */
3187 ospf_make_header (OSPF_MSG_LS_REQ
, oi
, op
->s
);
3189 /* Prepare OSPF Link State Request body. */
3190 length
+= ospf_make_ls_req (nbr
, op
->s
);
3191 if (length
== OSPF_HEADER_SIZE
)
3193 ospf_packet_free (op
);
3197 /* Fill OSPF header. */
3198 ospf_fill_header (oi
, op
->s
, length
);
3200 /* Set packet length. */
3201 op
->length
= length
;
3203 /* Decide destination address. */
3204 op
->dst
= nbr
->address
.u
.prefix4
;
3206 /* Add packet to the interface output queue. */
3207 ospf_packet_add (oi
, op
);
3209 /* Hook thread to write packet. */
3210 OSPF_ISM_WRITE_ON (oi
->ospf
);
3212 /* Add Link State Request Retransmission Timer. */
3213 OSPF_NSM_TIMER_ON (nbr
->t_ls_req
, ospf_ls_req_timer
, nbr
->v_ls_req
);
3216 /* Send Link State Update with an LSA. */
3218 ospf_ls_upd_send_lsa (struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
,
3221 struct list
*update
;
3223 update
= list_new ();
3225 listnode_add (update
, lsa
);
3226 ospf_ls_upd_send (nbr
, update
, flag
);
3228 list_delete (update
);
3231 /* Determine size for packet. Must be at least big enough to accomodate next
3232 * LSA on list, which may be bigger than MTU size.
3234 * Return pointer to new ospf_packet
3235 * NULL if we can not allocate, eg because LSA is bigger than imposed limit
3236 * on packet sizes (in which case offending LSA is deleted from update list)
3238 static struct ospf_packet
*
3239 ospf_ls_upd_packet_new (struct list
*update
, struct ospf_interface
*oi
)
3241 struct ospf_lsa
*lsa
;
3242 struct listnode
*ln
;
3244 static char warned
= 0;
3246 ln
= listhead (update
);
3251 if ((OSPF_LS_UPD_MIN_SIZE
+ ntohs (lsa
->data
->length
))
3252 > ospf_packet_max (oi
))
3256 zlog_warn ("ospf_ls_upd_packet_new: oversized LSA encountered!"
3257 "will need to fragment. Not optimal. Try divide up"
3258 " your network with areas. Use 'debug ospf packet send'"
3259 " to see details, or look at 'show ip ospf database ..'");
3263 if (IS_DEBUG_OSPF_PACKET (0, SEND
))
3264 zlog_debug ("ospf_ls_upd_packet_new: oversized LSA id:%s,"
3265 " %d bytes originated by %s, will be fragmented!",
3266 inet_ntoa (lsa
->data
->id
),
3267 ntohs (lsa
->data
->length
),
3268 inet_ntoa (lsa
->data
->adv_router
));
3271 * Allocate just enough to fit this LSA only, to avoid including other
3272 * LSAs in fragmented LSA Updates.
3274 size
= ntohs (lsa
->data
->length
) + (oi
->ifp
->mtu
- ospf_packet_max (oi
))
3275 + OSPF_LS_UPD_MIN_SIZE
;
3278 size
= oi
->ifp
->mtu
;
3280 /* XXX Should this be - sizeof(struct ip)?? -gdt */
3281 if (size
> OSPF_MAX_PACKET_SIZE
)
3283 zlog_warn ("ospf_ls_upd_packet_new: oversized LSA id:%s too big,"
3284 " %d bytes, packet size %ld, dropping it completely."
3285 " OSPF routing is broken!",
3286 inet_ntoa (lsa
->data
->id
), ntohs (lsa
->data
->length
),
3288 list_delete_node (update
, ln
);
3292 return ospf_packet_new (size
);
3296 ospf_ls_upd_queue_send (struct ospf_interface
*oi
, struct list
*update
,
3297 struct in_addr addr
)
3299 struct ospf_packet
*op
;
3300 u_int16_t length
= OSPF_HEADER_SIZE
;
3302 if (IS_DEBUG_OSPF_EVENT
)
3303 zlog_debug ("listcount = %d, dst %s", listcount (update
), inet_ntoa(addr
));
3305 op
= ospf_ls_upd_packet_new (update
, oi
);
3307 /* Prepare OSPF common header. */
3308 ospf_make_header (OSPF_MSG_LS_UPD
, oi
, op
->s
);
3310 /* Prepare OSPF Link State Update body.
3311 * Includes Type-7 translation.
3313 length
+= ospf_make_ls_upd (oi
, update
, op
->s
);
3315 /* Fill OSPF header. */
3316 ospf_fill_header (oi
, op
->s
, length
);
3318 /* Set packet length. */
3319 op
->length
= length
;
3321 /* Decide destination address. */
3322 op
->dst
.s_addr
= addr
.s_addr
;
3324 /* Add packet to the interface output queue. */
3325 ospf_packet_add (oi
, op
);
3327 /* Hook thread to write packet. */
3328 OSPF_ISM_WRITE_ON (oi
->ospf
);
3332 ospf_ls_upd_send_queue_event (struct thread
*thread
)
3334 struct ospf_interface
*oi
= THREAD_ARG(thread
);
3335 struct route_node
*rn
;
3336 struct route_node
*rnext
;
3337 struct list
*update
;
3340 oi
->t_ls_upd_event
= NULL
;
3342 if (IS_DEBUG_OSPF_EVENT
)
3343 zlog_debug ("ospf_ls_upd_send_queue start");
3345 for (rn
= route_top (oi
->ls_upd_queue
); rn
; rn
= rnext
)
3347 rnext
= route_next (rn
);
3349 if (rn
->info
== NULL
)
3352 update
= (struct list
*)rn
->info
;
3354 ospf_ls_upd_queue_send (oi
, update
, rn
->p
.u
.prefix4
);
3356 /* list might not be empty. */
3357 if (listcount(update
) == 0)
3359 list_delete (rn
->info
);
3361 route_unlock_node (rn
);
3369 if (IS_DEBUG_OSPF_EVENT
)
3370 zlog_debug ("ospf_ls_upd_send_queue: update lists not cleared,"
3371 " %d nodes to try again, raising new event", again
);
3372 oi
->t_ls_upd_event
=
3373 thread_add_event (master
, ospf_ls_upd_send_queue_event
, oi
, 0);
3376 if (IS_DEBUG_OSPF_EVENT
)
3377 zlog_debug ("ospf_ls_upd_send_queue stop");
3383 ospf_ls_upd_send (struct ospf_neighbor
*nbr
, struct list
*update
, int flag
)
3385 struct ospf_interface
*oi
;
3386 struct prefix_ipv4 p
;
3387 struct route_node
*rn
;
3393 p
.prefixlen
= IPV4_MAX_BITLEN
;
3395 /* Decide destination address. */
3396 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3397 p
.prefix
= oi
->vl_data
->peer_addr
;
3398 else if (flag
== OSPF_SEND_PACKET_DIRECT
)
3399 p
.prefix
= nbr
->address
.u
.prefix4
;
3400 else if (oi
->state
== ISM_DR
|| oi
->state
== ISM_Backup
)
3401 p
.prefix
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3402 else if ((oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
3403 && (flag
== OSPF_SEND_PACKET_INDIRECT
))
3404 p
.prefix
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3405 else if (oi
->type
== OSPF_IFTYPE_POINTOMULTIPOINT
)
3406 p
.prefix
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3408 p
.prefix
.s_addr
= htonl (OSPF_ALLDROUTERS
);
3410 if (oi
->type
== OSPF_IFTYPE_NBMA
)
3412 if (flag
== OSPF_SEND_PACKET_INDIRECT
)
3413 zlog_warn ("* LS-Update is directly sent on NBMA network.");
3414 if (IPV4_ADDR_SAME(&oi
->address
->u
.prefix4
, &p
.prefix
.s_addr
))
3415 zlog_warn ("* LS-Update is sent to myself.");
3418 rn
= route_node_get (oi
->ls_upd_queue
, (struct prefix
*) &p
);
3420 if (rn
->info
== NULL
)
3421 rn
->info
= list_new ();
3423 for (n
= listhead (update
); n
; nextnode (n
))
3424 listnode_add (rn
->info
, ospf_lsa_lock (getdata (n
)));
3426 if (oi
->t_ls_upd_event
== NULL
)
3427 oi
->t_ls_upd_event
=
3428 thread_add_event (master
, ospf_ls_upd_send_queue_event
, oi
, 0);
3432 ospf_ls_ack_send_list (struct ospf_interface
*oi
, struct list
*ack
,
3435 struct ospf_packet
*op
;
3436 u_int16_t length
= OSPF_HEADER_SIZE
;
3438 op
= ospf_packet_new (oi
->ifp
->mtu
);
3440 /* Prepare OSPF common header. */
3441 ospf_make_header (OSPF_MSG_LS_ACK
, oi
, op
->s
);
3443 /* Prepare OSPF Link State Acknowledgment body. */
3444 length
+= ospf_make_ls_ack (oi
, ack
, op
->s
);
3446 /* Fill OSPF header. */
3447 ospf_fill_header (oi
, op
->s
, length
);
3449 /* Set packet length. */
3450 op
->length
= length
;
3452 /* Set destination IP address. */
3455 /* Add packet to the interface output queue. */
3456 ospf_packet_add (oi
, op
);
3458 /* Hook thread to write packet. */
3459 OSPF_ISM_WRITE_ON (oi
->ospf
);
3463 ospf_ls_ack_send_event (struct thread
*thread
)
3465 struct ospf_interface
*oi
= THREAD_ARG (thread
);
3467 oi
->t_ls_ack_direct
= NULL
;
3469 while (listcount (oi
->ls_ack_direct
.ls_ack
))
3470 ospf_ls_ack_send_list (oi
, oi
->ls_ack_direct
.ls_ack
,
3471 oi
->ls_ack_direct
.dst
);
3477 ospf_ls_ack_send (struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
3479 struct ospf_interface
*oi
= nbr
->oi
;
3481 if (listcount (oi
->ls_ack_direct
.ls_ack
) == 0)
3482 oi
->ls_ack_direct
.dst
= nbr
->address
.u
.prefix4
;
3484 listnode_add (oi
->ls_ack_direct
.ls_ack
, ospf_lsa_lock (lsa
));
3486 if (oi
->t_ls_ack_direct
== NULL
)
3487 oi
->t_ls_ack_direct
=
3488 thread_add_event (master
, ospf_ls_ack_send_event
, oi
, 0);
3491 /* Send Link State Acknowledgment delayed. */
3493 ospf_ls_ack_send_delayed (struct ospf_interface
*oi
)
3497 /* Decide destination address. */
3498 /* RFC2328 Section 13.5 On non-broadcast
3499 networks, delayed Link State Acknowledgment packets must be
3500 unicast separately over each adjacency (i.e., neighbor whose
3501 state is >= Exchange). */
3502 if (oi
->type
== OSPF_IFTYPE_NBMA
)
3504 struct ospf_neighbor
*nbr
;
3505 struct route_node
*rn
;
3507 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
3508 if ((nbr
= rn
->info
) != NULL
)
3509 if (nbr
!= oi
->nbr_self
&& nbr
->state
>= NSM_Exchange
)
3510 while (listcount (oi
->ls_ack
))
3511 ospf_ls_ack_send_list (oi
, oi
->ls_ack
, nbr
->address
.u
.prefix4
);
3514 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3515 dst
.s_addr
= oi
->vl_data
->peer_addr
.s_addr
;
3516 else if (oi
->state
== ISM_DR
|| oi
->state
== ISM_Backup
)
3517 dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3518 else if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
3519 dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3520 else if (oi
->type
== OSPF_IFTYPE_POINTOMULTIPOINT
)
3521 dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3523 dst
.s_addr
= htonl (OSPF_ALLDROUTERS
);
3525 while (listcount (oi
->ls_ack
))
3526 ospf_ls_ack_send_list (oi
, oi
->ls_ack
, dst
);