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
)
197 zlog_err("ospf_packet_add(interface %s in state %d [%s], packet type %s, "
198 "destination %s) called with NULL obuf, ignoring "
199 "(please report this bug)!\n",
200 IF_NAME(oi
), oi
->state
, LOOKUP (ospf_ism_state_msg
, oi
->state
),
201 ospf_packet_type_str
[stream_getc_from(op
->s
, 1)],
202 inet_ntoa (op
->dst
));
206 /* Add packet to end of queue. */
207 ospf_fifo_push (oi
->obuf
, op
);
209 /* Debug of packet fifo*/
210 /* ospf_fifo_debug (oi->obuf); */
214 ospf_packet_delete (struct ospf_interface
*oi
)
216 struct ospf_packet
*op
;
218 op
= ospf_fifo_pop (oi
->obuf
);
221 ospf_packet_free (op
);
225 ospf_stream_copy (struct stream
*new, struct stream
*s
)
231 memcpy (new->data
, s
->data
, stream_get_endp (s
));
237 ospf_packet_dup (struct ospf_packet
*op
)
239 struct ospf_packet
*new;
241 if (stream_get_endp(op
->s
) != op
->length
)
242 zlog_warn ("ospf_packet_dup stream %ld ospf_packet %d size mismatch",
243 STREAM_SIZE(op
->s
), op
->length
);
245 /* Reserve space for MD5 authentication that may be added later. */
246 new = ospf_packet_new (stream_get_endp(op
->s
) + OSPF_AUTH_MD5_SIZE
);
247 ospf_stream_copy (new->s
, op
->s
);
250 new->length
= op
->length
;
257 ospf_packet_authspace (struct ospf_interface
*oi
)
261 if ( ospf_auth_type (oi
) == OSPF_AUTH_CRYPTOGRAPHIC
)
262 auth
= OSPF_AUTH_MD5_SIZE
;
268 ospf_packet_max (struct ospf_interface
*oi
)
272 max
= oi
->ifp
->mtu
- ospf_packet_authspace(oi
);
274 max
-= (OSPF_HEADER_SIZE
+ sizeof (struct ip
));
281 ospf_check_md5_digest (struct ospf_interface
*oi
, struct stream
*s
,
286 unsigned char digest
[OSPF_AUTH_MD5_SIZE
];
287 unsigned char *pdigest
;
288 struct crypt_key
*ck
;
289 struct ospf_header
*ospfh
;
290 struct ospf_neighbor
*nbr
;
293 ibuf
= STREAM_PNT (s
);
294 ospfh
= (struct ospf_header
*) ibuf
;
296 /* Get pointer to the end of the packet. */
297 pdigest
= ibuf
+ length
;
299 /* Get secret key. */
300 ck
= ospf_crypt_key_lookup (OSPF_IF_PARAM (oi
, auth_crypt
),
301 ospfh
->u
.crypt
.key_id
);
304 zlog_warn ("interface %s: ospf_check_md5 no key %d",
305 IF_NAME (oi
), ospfh
->u
.crypt
.key_id
);
309 /* check crypto seqnum. */
310 nbr
= ospf_nbr_lookup_by_routerid (oi
->nbrs
, &ospfh
->router_id
);
312 if (nbr
&& ntohl(nbr
->crypt_seqnum
) > ntohl(ospfh
->u
.crypt
.crypt_seqnum
))
314 zlog_warn ("interface %s: ospf_check_md5 bad sequence %d (expect %d)",
316 ntohl(ospfh
->u
.crypt
.crypt_seqnum
),
317 ntohl(nbr
->crypt_seqnum
));
321 /* Generate a digest for the ospf packet - their digest + our digest. */
323 md5_process_bytes (ibuf
, length
, &ctx
);
324 md5_process_bytes (ck
->auth_key
, OSPF_AUTH_MD5_SIZE
, &ctx
);
325 md5_finish_ctx (&ctx
, digest
);
327 /* compare the two */
328 if (memcmp (pdigest
, digest
, OSPF_AUTH_MD5_SIZE
))
330 zlog_warn ("interface %s: ospf_check_md5 checksum mismatch",
335 /* save neighbor's crypt_seqnum */
337 nbr
->crypt_seqnum
= ospfh
->u
.crypt
.crypt_seqnum
;
341 /* This function is called from ospf_write(), it will detect the
342 authentication scheme and if it is MD5, it will change the sequence
343 and update the MD5 digest. */
345 ospf_make_md5_digest (struct ospf_interface
*oi
, struct ospf_packet
*op
)
347 struct ospf_header
*ospfh
;
348 unsigned char digest
[OSPF_AUTH_MD5_SIZE
];
352 struct crypt_key
*ck
;
355 ibuf
= STREAM_DATA (op
->s
);
356 ospfh
= (struct ospf_header
*) ibuf
;
358 if (ntohs (ospfh
->auth_type
) != OSPF_AUTH_CRYPTOGRAPHIC
)
361 /* We do this here so when we dup a packet, we don't have to
362 waste CPU rewriting other headers. */
363 t
= (time(NULL
) & 0xFFFFFFFF);
364 oi
->crypt_seqnum
= ( t
> oi
->crypt_seqnum
? t
: oi
->crypt_seqnum
++);
365 ospfh
->u
.crypt
.crypt_seqnum
= htonl (oi
->crypt_seqnum
);
367 /* Get MD5 Authentication key from auth_key list. */
368 if (list_isempty (OSPF_IF_PARAM (oi
, auth_crypt
)))
369 auth_key
= (char *) "";
372 ck
= getdata (OSPF_IF_PARAM (oi
, auth_crypt
)->tail
);
373 auth_key
= (char *) ck
->auth_key
;
376 /* Generate a digest for the entire packet + our secret key. */
378 md5_process_bytes (ibuf
, ntohs (ospfh
->length
), &ctx
);
379 md5_process_bytes (auth_key
, OSPF_AUTH_MD5_SIZE
, &ctx
);
380 md5_finish_ctx (&ctx
, digest
);
382 /* Append md5 digest to the end of the stream. */
383 stream_put (op
->s
, digest
, OSPF_AUTH_MD5_SIZE
);
385 /* We do *NOT* increment the OSPF header length. */
386 op
->length
= ntohs (ospfh
->length
) + OSPF_AUTH_MD5_SIZE
;
388 if (stream_get_endp(op
->s
) != op
->length
)
389 zlog_warn("ospf_make_md5_digest: length mismatch stream %ld ospf_packet %d", stream_get_endp(op
->s
), op
->length
);
391 return OSPF_AUTH_MD5_SIZE
;
396 ospf_ls_req_timer (struct thread
*thread
)
398 struct ospf_neighbor
*nbr
;
400 nbr
= THREAD_ARG (thread
);
401 nbr
->t_ls_req
= NULL
;
403 /* Send Link State Request. */
404 if (ospf_ls_request_count (nbr
))
405 ospf_ls_req_send (nbr
);
407 /* Set Link State Request retransmission timer. */
408 OSPF_NSM_TIMER_ON (nbr
->t_ls_req
, ospf_ls_req_timer
, nbr
->v_ls_req
);
414 ospf_ls_req_event (struct ospf_neighbor
*nbr
)
418 thread_cancel (nbr
->t_ls_req
);
419 nbr
->t_ls_req
= NULL
;
421 nbr
->t_ls_req
= thread_add_event (master
, ospf_ls_req_timer
, nbr
, 0);
424 /* Cyclic timer function. Fist registered in ospf_nbr_new () in
427 ospf_ls_upd_timer (struct thread
*thread
)
429 struct ospf_neighbor
*nbr
;
431 nbr
= THREAD_ARG (thread
);
432 nbr
->t_ls_upd
= NULL
;
434 /* Send Link State Update. */
435 if (ospf_ls_retransmit_count (nbr
) > 0)
438 struct ospf_lsdb
*lsdb
;
441 int retransmit_interval
;
443 gettimeofday (&now
, NULL
);
444 retransmit_interval
= OSPF_IF_PARAM (nbr
->oi
, retransmit_interval
);
446 lsdb
= &nbr
->ls_rxmt
;
447 update
= list_new ();
449 for (i
= OSPF_MIN_LSA
; i
< OSPF_MAX_LSA
; i
++)
451 struct route_table
*table
= lsdb
->type
[i
].db
;
452 struct route_node
*rn
;
454 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
456 struct ospf_lsa
*lsa
;
458 if ((lsa
= rn
->info
) != NULL
)
459 /* Don't retransmit an LSA if we received it within
460 the last RxmtInterval seconds - this is to allow the
461 neighbour a chance to acknowledge the LSA as it may
462 have ben just received before the retransmit timer
463 fired. This is a small tweak to what is in the RFC,
464 but it will cut out out a lot of retransmit traffic
466 if (tv_cmp (tv_sub (now
, lsa
->tv_recv
),
467 int2tv (retransmit_interval
)) >= 0)
468 listnode_add (update
, rn
->info
);
472 if (listcount (update
) > 0)
473 ospf_ls_upd_send (nbr
, update
, OSPF_SEND_PACKET_DIRECT
);
474 list_delete (update
);
477 /* Set LS Update retransmission timer. */
478 OSPF_NSM_TIMER_ON (nbr
->t_ls_upd
, ospf_ls_upd_timer
, nbr
->v_ls_upd
);
484 ospf_ls_ack_timer (struct thread
*thread
)
486 struct ospf_interface
*oi
;
488 oi
= THREAD_ARG (thread
);
491 /* Send Link State Acknowledgment. */
492 if (listcount (oi
->ls_ack
) > 0)
493 ospf_ls_ack_send_delayed (oi
);
495 /* Set LS Ack timer. */
496 OSPF_ISM_TIMER_ON (oi
->t_ls_ack
, ospf_ls_ack_timer
, oi
->v_ls_ack
);
501 #ifdef WANT_OSPF_WRITE_FRAGMENT
503 ospf_write_frags (int fd
, struct ospf_packet
*op
, struct ip
*iph
,
504 struct msghdr
*msg
, unsigned int maxdatasize
,
505 unsigned int mtu
, int flags
, u_char type
)
507 #define OSPF_WRITE_FRAG_SHIFT 3
512 assert ( op
->length
== stream_get_endp(op
->s
) );
513 assert (msg
->msg_iovlen
== 2);
517 * SunOS, BSD and BSD derived kernels likely will clear ip_id, as
518 * well as the IP_MF flag, making this all quite pointless.
520 * However, for a system on which IP_MF is left alone, and ip_id left
521 * alone or else which sets same ip_id for each fragment this might
524 * XXX-TODO: It would be much nicer to have the kernel's use their
525 * existing fragmentation support to do this for us. Bugs/RFEs need to
526 * be raised against the various kernels.
530 iph
->ip_off
|= IP_MF
;
532 /* ip frag offset is expressed in units of 8byte words */
533 offset
= maxdatasize
>> OSPF_WRITE_FRAG_SHIFT
;
535 iovp
= &msg
->msg_iov
[1];
537 while ( (stream_get_endp(op
->s
) - stream_get_getp (op
->s
))
540 /* data length of this frag is to next offset value */
541 iovp
->iov_len
= offset
<< OSPF_WRITE_FRAG_SHIFT
;
542 iph
->ip_len
= iovp
->iov_len
+ sizeof (struct ip
);
543 assert (iph
->ip_len
<= mtu
);
545 sockopt_iphdrincl_swab_htosys (iph
);
547 ret
= sendmsg (fd
, msg
, flags
);
549 sockopt_iphdrincl_swab_systoh (iph
);
552 zlog_warn ("*** ospf_write_frags: sendmsg failed to %s,"
553 " id %d, off %d, len %d failed with %s",
554 inet_ntoa (iph
->ip_dst
),
558 safe_strerror (errno
));
560 if (IS_DEBUG_OSPF_PACKET (type
- 1, SEND
))
562 zlog_debug ("ospf_write_frags: sent id %d, off %d, len %d to %s\n",
563 iph
->ip_id
, iph
->ip_off
, iph
->ip_len
,
564 inet_ntoa (iph
->ip_dst
));
565 if (IS_DEBUG_OSPF_PACKET (type
- 1, DETAIL
))
567 zlog_debug ("-----------------IP Header Dump----------------------");
568 ospf_ip_header_dump (iph
);
569 zlog_debug ("-----------------------------------------------------");
573 iph
->ip_off
+= offset
;
574 stream_forward (op
->s
, iovp
->iov_len
);
575 iovp
->iov_base
= STREAM_PNT (op
->s
);
578 /* setup for final fragment */
579 iovp
->iov_len
= stream_get_endp(op
->s
) - stream_get_getp (op
->s
);
580 iph
->ip_len
= iovp
->iov_len
+ sizeof (struct ip
);
581 iph
->ip_off
&= (~IP_MF
);
583 #endif /* WANT_OSPF_WRITE_FRAGMENT */
586 ospf_write (struct thread
*thread
)
588 struct ospf
*ospf
= THREAD_ARG (thread
);
589 struct ospf_interface
*oi
;
590 struct ospf_packet
*op
;
591 struct sockaddr_in sa_dst
;
598 struct listnode
*node
;
599 #ifdef WANT_OSPF_WRITE_FRAGMENT
600 static u_int16_t ipid
= 0;
601 #endif /* WANT_OSPF_WRITE_FRAGMENT */
602 u_int16_t maxdatasize
;
603 #define OSPF_WRITE_IPHL_SHIFT 2
605 ospf
->t_write
= NULL
;
607 node
= listhead (ospf
->oi_write_q
);
612 #ifdef WANT_OSPF_WRITE_FRAGMENT
613 /* seed ipid static with low order bits of time */
615 ipid
= (time(NULL
) & 0xffff);
616 #endif /* WANT_OSPF_WRITE_FRAGMENT */
618 /* convenience - max OSPF data per packet */
619 maxdatasize
= oi
->ifp
->mtu
- sizeof (struct ip
);
621 /* Get one packet from queue. */
622 op
= ospf_fifo_head (oi
->obuf
);
624 assert (op
->length
>= OSPF_HEADER_SIZE
);
626 if (op
->dst
.s_addr
== htonl (OSPF_ALLSPFROUTERS
)
627 || op
->dst
.s_addr
== htonl (OSPF_ALLDROUTERS
))
628 ospf_if_ipmulticast (ospf
, oi
->address
, oi
->ifp
->ifindex
);
630 /* Rewrite the md5 signature & update the seq */
631 ospf_make_md5_digest (oi
, op
);
633 /* Retrieve OSPF packet type. */
634 stream_set_getp (op
->s
, 1);
635 type
= stream_getc (op
->s
);
637 /* reset get pointer */
638 stream_set_getp (op
->s
, 0);
640 memset (&iph
, 0, sizeof (struct ip
));
641 memset (&sa_dst
, 0, sizeof (sa_dst
));
643 sa_dst
.sin_family
= AF_INET
;
645 sa_dst
.sin_len
= sizeof(sa_dst
);
646 #endif /* HAVE_SIN_LEN */
647 sa_dst
.sin_addr
= op
->dst
;
648 sa_dst
.sin_port
= htons (0);
650 /* Set DONTROUTE flag if dst is unicast. */
651 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
652 if (!IN_MULTICAST (htonl (op
->dst
.s_addr
)))
653 flags
= MSG_DONTROUTE
;
655 iph
.ip_hl
= sizeof (struct ip
) >> OSPF_WRITE_IPHL_SHIFT
;
656 /* it'd be very strange for header to not be 4byte-word aligned but.. */
657 if ( sizeof (struct ip
)
658 > (unsigned int)(iph
.ip_hl
<< OSPF_WRITE_IPHL_SHIFT
) )
659 iph
.ip_hl
++; /* we presume sizeof struct ip cant overflow ip_hl.. */
661 iph
.ip_v
= IPVERSION
;
662 iph
.ip_tos
= IPTOS_PREC_INTERNETCONTROL
;
663 iph
.ip_len
= (iph
.ip_hl
<< OSPF_WRITE_IPHL_SHIFT
) + op
->length
;
665 #ifdef WANT_OSPF_WRITE_FRAGMENT
666 /* XXX-MT: not thread-safe at all..
667 * XXX: this presumes this is only programme sending OSPF packets
668 * otherwise, no guarantee ipid will be unique
671 #endif /* WANT_OSPF_WRITE_FRAGMENT */
674 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
675 iph
.ip_ttl
= OSPF_VL_IP_TTL
;
677 iph
.ip_ttl
= OSPF_IP_TTL
;
678 iph
.ip_p
= IPPROTO_OSPFIGP
;
680 iph
.ip_src
.s_addr
= oi
->address
->u
.prefix4
.s_addr
;
681 iph
.ip_dst
.s_addr
= op
->dst
.s_addr
;
683 memset (&msg
, 0, sizeof (msg
));
684 msg
.msg_name
= (caddr_t
) &sa_dst
;
685 msg
.msg_namelen
= sizeof (sa_dst
);
688 iov
[0].iov_base
= (char*)&iph
;
689 iov
[0].iov_len
= iph
.ip_hl
<< OSPF_WRITE_IPHL_SHIFT
;
690 iov
[1].iov_base
= STREAM_PNT (op
->s
);
691 iov
[1].iov_len
= op
->length
;
693 /* Sadly we can not rely on kernels to fragment packets because of either
694 * IP_HDRINCL and/or multicast destination being set.
696 #ifdef WANT_OSPF_WRITE_FRAGMENT
697 if ( op
->length
> maxdatasize
)
698 ospf_write_frags (ospf
->fd
, op
, &iph
, &msg
, maxdatasize
,
699 oi
->ifp
->mtu
, flags
, type
);
700 #endif /* WANT_OSPF_WRITE_FRAGMENT */
702 /* send final fragment (could be first) */
703 sockopt_iphdrincl_swab_htosys (&iph
);
704 ret
= sendmsg (ospf
->fd
, &msg
, flags
);
705 sockopt_iphdrincl_swab_systoh (&iph
);
708 zlog_warn ("*** sendmsg in ospf_write to %s failed with %s",
709 inet_ntoa (iph
.ip_dst
), safe_strerror (errno
));
711 /* Show debug sending packet. */
712 if (IS_DEBUG_OSPF_PACKET (type
- 1, SEND
))
714 if (IS_DEBUG_OSPF_PACKET (type
- 1, DETAIL
))
716 zlog_debug ("-----------------------------------------------------");
717 ospf_ip_header_dump (&iph
);
718 stream_set_getp (op
->s
, 0);
719 ospf_packet_dump (op
->s
);
722 zlog_debug ("%s sent to [%s] via [%s].",
723 ospf_packet_type_str
[type
], inet_ntoa (op
->dst
),
726 if (IS_DEBUG_OSPF_PACKET (type
- 1, DETAIL
))
727 zlog_debug ("-----------------------------------------------------");
730 /* Now delete packet from queue. */
731 ospf_packet_delete (oi
);
733 if (ospf_fifo_head (oi
->obuf
) == NULL
)
736 list_delete_node (ospf
->oi_write_q
, node
);
739 /* If packets still remain in queue, call write thread. */
740 if (!list_isempty (ospf
->oi_write_q
))
742 thread_add_write (master
, ospf_write
, ospf
, ospf
->fd
);
747 /* OSPF Hello message read -- RFC2328 Section 10.5. */
749 ospf_hello (struct ip
*iph
, struct ospf_header
*ospfh
,
750 struct stream
* s
, struct ospf_interface
*oi
, int size
)
752 struct ospf_hello
*hello
;
753 struct ospf_neighbor
*nbr
;
757 /* increment statistics. */
760 hello
= (struct ospf_hello
*) STREAM_PNT (s
);
762 /* If Hello is myself, silently discard. */
763 if (IPV4_ADDR_SAME (&ospfh
->router_id
, &oi
->ospf
->router_id
))
765 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, RECV
))
767 zlog_debug ("ospf_header[%s/%s]: selforiginated, "
769 ospf_packet_type_str
[ospfh
->type
],
770 inet_ntoa (iph
->ip_src
));
775 /* If incoming interface is passive one, ignore Hello. */
776 if (OSPF_IF_PARAM (oi
, passive_interface
) == OSPF_IF_PASSIVE
) {
777 zlog_info ("Packet %s [HELLO:RECV]: oi is passive",
778 inet_ntoa (ospfh
->router_id
));
782 /* get neighbor prefix. */
784 p
.prefixlen
= ip_masklen (hello
->network_mask
);
785 p
.u
.prefix4
= iph
->ip_src
;
787 /* Compare network mask. */
788 /* Checking is ignored for Point-to-Point and Virtual link. */
789 if (oi
->type
!= OSPF_IFTYPE_POINTOPOINT
790 && oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
791 if (oi
->address
->prefixlen
!= p
.prefixlen
)
793 zlog_warn ("Packet %s [Hello:RECV]: NetworkMask mismatch.",
794 inet_ntoa (ospfh
->router_id
));
798 /* Compare Hello Interval. */
799 if (OSPF_IF_PARAM (oi
, v_hello
) != ntohs (hello
->hello_interval
))
801 zlog_warn ("Packet %s [Hello:RECV]: HelloInterval mismatch.",
802 inet_ntoa (ospfh
->router_id
));
806 /* Compare Router Dead Interval. */
807 if (OSPF_IF_PARAM (oi
, v_wait
) != ntohl (hello
->dead_interval
))
809 zlog_warn ("Packet %s [Hello:RECV]: RouterDeadInterval mismatch.",
810 inet_ntoa (ospfh
->router_id
));
814 if (IS_DEBUG_OSPF_EVENT
)
815 zlog_debug ("Packet %s [Hello:RECV]: Options %s",
816 inet_ntoa (ospfh
->router_id
),
817 ospf_options_dump (hello
->options
));
819 /* Compare options. */
820 #define REJECT_IF_TBIT_ON 1 /* XXX */
821 #ifdef REJECT_IF_TBIT_ON
822 if (CHECK_FLAG (hello
->options
, OSPF_OPTION_T
))
825 * This router does not support non-zero TOS.
826 * Drop this Hello packet not to establish neighbor relationship.
828 zlog_warn ("Packet %s [Hello:RECV]: T-bit on, drop it.",
829 inet_ntoa (ospfh
->router_id
));
832 #endif /* REJECT_IF_TBIT_ON */
834 #ifdef HAVE_OPAQUE_LSA
835 if (CHECK_FLAG (oi
->ospf
->config
, OSPF_OPAQUE_CAPABLE
)
836 && CHECK_FLAG (hello
->options
, OSPF_OPTION_O
))
839 * This router does know the correct usage of O-bit
840 * the bit should be set in DD packet only.
842 zlog_warn ("Packet %s [Hello:RECV]: O-bit abuse?",
843 inet_ntoa (ospfh
->router_id
));
844 #ifdef STRICT_OBIT_USAGE_CHECK
845 return; /* Reject this packet. */
846 #else /* STRICT_OBIT_USAGE_CHECK */
847 UNSET_FLAG (hello
->options
, OSPF_OPTION_O
); /* Ignore O-bit. */
848 #endif /* STRICT_OBIT_USAGE_CHECK */
850 #endif /* HAVE_OPAQUE_LSA */
852 /* new for NSSA is to ensure that NP is on and E is off */
854 if (oi
->area
->external_routing
== OSPF_AREA_NSSA
)
856 if (! (CHECK_FLAG (OPTIONS (oi
), OSPF_OPTION_NP
)
857 && CHECK_FLAG (hello
->options
, OSPF_OPTION_NP
)
858 && ! CHECK_FLAG (OPTIONS (oi
), OSPF_OPTION_E
)
859 && ! CHECK_FLAG (hello
->options
, OSPF_OPTION_E
)))
861 zlog_warn ("NSSA-Packet-%s[Hello:RECV]: my options: %x, his options %x", inet_ntoa (ospfh
->router_id
), OPTIONS (oi
), hello
->options
);
864 if (IS_DEBUG_OSPF_NSSA
)
865 zlog_debug ("NSSA-Hello:RECV:Packet from %s:", inet_ntoa(ospfh
->router_id
));
868 /* The setting of the E-bit found in the Hello Packet's Options
869 field must match this area's ExternalRoutingCapability A
870 mismatch causes processing to stop and the packet to be
871 dropped. The setting of the rest of the bits in the Hello
872 Packet's Options field should be ignored. */
873 if (CHECK_FLAG (OPTIONS (oi
), OSPF_OPTION_E
) !=
874 CHECK_FLAG (hello
->options
, OSPF_OPTION_E
))
876 zlog_warn ("Packet %s [Hello:RECV]: my options: %x, his options %x",
877 inet_ntoa(ospfh
->router_id
), OPTIONS (oi
), hello
->options
);
881 /* get neighbour struct */
882 nbr
= ospf_nbr_get (oi
, ospfh
, iph
, &p
);
884 /* neighbour must be valid, ospf_nbr_get creates if none existed */
887 old_state
= nbr
->state
;
889 /* Add event to thread. */
890 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_HelloReceived
);
892 /* RFC2328 Section 9.5.1
893 If the router is not eligible to become Designated Router,
894 (snip) It must also send an Hello Packet in reply to an
895 Hello Packet received from any eligible neighbor (other than
896 the current Designated Router and Backup Designated Router). */
897 if (oi
->type
== OSPF_IFTYPE_NBMA
)
898 if (PRIORITY(oi
) == 0 && hello
->priority
> 0
899 && IPV4_ADDR_CMP(&DR(oi
), &iph
->ip_src
)
900 && IPV4_ADDR_CMP(&BDR(oi
), &iph
->ip_src
))
901 OSPF_NSM_TIMER_ON (nbr
->t_hello_reply
, ospf_hello_reply_timer
,
902 OSPF_HELLO_REPLY_DELAY
);
904 /* on NBMA network type, it happens to receive bidirectional Hello packet
905 without advance 1-Way Received event.
906 To avoid incorrect DR-seletion, raise 1-Way Received event.*/
907 if (oi
->type
== OSPF_IFTYPE_NBMA
&&
908 (old_state
== NSM_Down
|| old_state
== NSM_Attempt
))
910 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_OneWayReceived
);
911 nbr
->priority
= hello
->priority
;
912 nbr
->d_router
= hello
->d_router
;
913 nbr
->bd_router
= hello
->bd_router
;
917 if (ospf_nbr_bidirectional (&oi
->ospf
->router_id
, hello
->neighbors
,
918 size
- OSPF_HELLO_MIN_SIZE
))
920 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_TwoWayReceived
);
921 nbr
->options
|= hello
->options
;
925 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_OneWayReceived
);
926 /* Set neighbor information. */
927 nbr
->priority
= hello
->priority
;
928 nbr
->d_router
= hello
->d_router
;
929 nbr
->bd_router
= hello
->bd_router
;
933 /* If neighbor itself declares DR and no BDR exists,
934 cause event BackupSeen */
935 if (IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &hello
->d_router
))
936 if (hello
->bd_router
.s_addr
== 0 && oi
->state
== ISM_Waiting
)
937 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_BackupSeen
);
939 /* neighbor itself declares BDR. */
940 if (oi
->state
== ISM_Waiting
&&
941 IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &hello
->bd_router
))
942 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_BackupSeen
);
944 /* had not previously. */
945 if ((IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &hello
->d_router
) &&
946 IPV4_ADDR_CMP (&nbr
->address
.u
.prefix4
, &nbr
->d_router
)) ||
947 (IPV4_ADDR_CMP (&nbr
->address
.u
.prefix4
, &hello
->d_router
) &&
948 IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &nbr
->d_router
)))
949 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_NeighborChange
);
951 /* had not previously. */
952 if ((IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &hello
->bd_router
) &&
953 IPV4_ADDR_CMP (&nbr
->address
.u
.prefix4
, &nbr
->bd_router
)) ||
954 (IPV4_ADDR_CMP (&nbr
->address
.u
.prefix4
, &hello
->bd_router
) &&
955 IPV4_ADDR_SAME (&nbr
->address
.u
.prefix4
, &nbr
->bd_router
)))
956 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_NeighborChange
);
958 /* Neighbor priority check. */
959 if (nbr
->priority
>= 0 && nbr
->priority
!= hello
->priority
)
960 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_NeighborChange
);
962 /* Set neighbor information. */
963 nbr
->priority
= hello
->priority
;
964 nbr
->d_router
= hello
->d_router
;
965 nbr
->bd_router
= hello
->bd_router
;
968 /* Save DD flags/options/Seqnum received. */
970 ospf_db_desc_save_current (struct ospf_neighbor
*nbr
,
971 struct ospf_db_desc
*dd
)
973 nbr
->last_recv
.flags
= dd
->flags
;
974 nbr
->last_recv
.options
= dd
->options
;
975 nbr
->last_recv
.dd_seqnum
= ntohl (dd
->dd_seqnum
);
978 /* Process rest of DD packet. */
980 ospf_db_desc_proc (struct stream
*s
, struct ospf_interface
*oi
,
981 struct ospf_neighbor
*nbr
, struct ospf_db_desc
*dd
,
984 struct ospf_lsa
*new, *find
;
985 struct lsa_header
*lsah
;
987 stream_forward (s
, OSPF_DB_DESC_MIN_SIZE
);
988 for (size
-= OSPF_DB_DESC_MIN_SIZE
;
989 size
>= OSPF_LSA_HEADER_SIZE
; size
-= OSPF_LSA_HEADER_SIZE
)
991 lsah
= (struct lsa_header
*) STREAM_PNT (s
);
992 stream_forward (s
, OSPF_LSA_HEADER_SIZE
);
994 /* Unknown LS type. */
995 if (lsah
->type
< OSPF_MIN_LSA
|| lsah
->type
>= OSPF_MAX_LSA
)
997 zlog_warn ("Packet [DD:RECV]: Unknown LS type %d.", lsah
->type
);
998 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1002 #ifdef HAVE_OPAQUE_LSA
1003 if (IS_OPAQUE_LSA (lsah
->type
)
1004 && ! CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
))
1006 zlog_warn ("LSA[Type%d:%s]: Opaque capability mismatch?", lsah
->type
, inet_ntoa (lsah
->id
));
1007 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1010 #endif /* HAVE_OPAQUE_LSA */
1014 case OSPF_AS_EXTERNAL_LSA
:
1015 #ifdef HAVE_OPAQUE_LSA
1016 case OSPF_OPAQUE_AS_LSA
:
1017 #endif /* HAVE_OPAQUE_LSA */
1018 /* Check for stub area. Reject if AS-External from stub but
1019 allow if from NSSA. */
1020 if (oi
->area
->external_routing
== OSPF_AREA_STUB
)
1022 zlog_warn ("Packet [DD:RECV]: LSA[Type%d:%s] from %s area.",
1023 lsah
->type
, inet_ntoa (lsah
->id
),
1024 (oi
->area
->external_routing
== OSPF_AREA_STUB
) ?\
1026 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1034 /* Create LS-request object. */
1035 new = ospf_ls_request_new (lsah
);
1037 /* Lookup received LSA, then add LS request list. */
1038 find
= ospf_lsa_lookup_by_header (oi
->area
, lsah
);
1039 if (!find
|| ospf_lsa_more_recent (find
, new) < 0)
1041 ospf_ls_request_add (nbr
, new);
1042 ospf_lsa_discard (new);
1046 /* Received LSA is not recent. */
1047 if (IS_DEBUG_OSPF_EVENT
)
1048 zlog_debug ("Packet [DD:RECV]: LSA received Type %d, "
1049 "ID %s is not recent.", lsah
->type
, inet_ntoa (lsah
->id
));
1050 ospf_lsa_discard (new);
1056 if (IS_SET_DD_MS (nbr
->dd_flags
))
1059 /* Entire DD packet sent. */
1060 if (!IS_SET_DD_M (dd
->flags
) && !IS_SET_DD_M (nbr
->dd_flags
))
1061 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_ExchangeDone
);
1063 /* Send new DD packet. */
1064 ospf_db_desc_send (nbr
);
1069 nbr
->dd_seqnum
= ntohl (dd
->dd_seqnum
);
1071 /* When master's more flags is not set. */
1072 if (!IS_SET_DD_M (dd
->flags
) && ospf_db_summary_isempty (nbr
))
1074 nbr
->dd_flags
&= ~(OSPF_DD_FLAG_M
);
1075 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_ExchangeDone
);
1078 /* Send DD packet in reply. */
1079 ospf_db_desc_send (nbr
);
1082 /* Save received neighbor values from DD. */
1083 ospf_db_desc_save_current (nbr
, dd
);
1087 ospf_db_desc_is_dup (struct ospf_db_desc
*dd
, struct ospf_neighbor
*nbr
)
1089 /* Is DD duplicated? */
1090 if (dd
->options
== nbr
->last_recv
.options
&&
1091 dd
->flags
== nbr
->last_recv
.flags
&&
1092 dd
->dd_seqnum
== htonl (nbr
->last_recv
.dd_seqnum
))
1098 /* OSPF Database Description message read -- RFC2328 Section 10.6. */
1100 ospf_db_desc (struct ip
*iph
, struct ospf_header
*ospfh
,
1101 struct stream
*s
, struct ospf_interface
*oi
, u_int16_t size
)
1103 struct ospf_db_desc
*dd
;
1104 struct ospf_neighbor
*nbr
;
1106 /* Increment statistics. */
1109 dd
= (struct ospf_db_desc
*) STREAM_PNT (s
);
1111 nbr
= ospf_nbr_lookup (oi
, iph
, ospfh
);
1114 zlog_warn ("Packet[DD]: Unknown Neighbor %s",
1115 inet_ntoa (ospfh
->router_id
));
1120 if (ntohs (dd
->mtu
) > oi
->ifp
->mtu
)
1122 zlog_warn ("Packet[DD]: Neighbor %s MTU %u is larger than [%s]'s MTU %u",
1123 inet_ntoa (nbr
->router_id
), ntohs (dd
->mtu
),
1124 IF_NAME (oi
), oi
->ifp
->mtu
);
1129 * XXX HACK by Hasso Tepper. Setting N/P bit in NSSA area DD packets is not
1130 * required. In fact at least JunOS sends DD packets with P bit clear.
1131 * Until proper solution is developped, this hack should help.
1133 * Update: According to the RFCs, N bit is specified /only/ for Hello
1134 * options, unfortunately its use in DD options is not specified. Hence some
1135 * implementations follow E-bit semantics and set it in DD options, and some
1136 * treat it as unspecified and hence follow the directive "default for
1137 * options is clear", ie unset.
1139 * Reset the flag, as ospfd follows E-bit semantics.
1141 if ( (oi
->area
->external_routing
== OSPF_AREA_NSSA
)
1142 && (CHECK_FLAG (nbr
->options
, OSPF_OPTION_NP
))
1143 && (!CHECK_FLAG (dd
->options
, OSPF_OPTION_NP
)) )
1145 if (IS_DEBUG_OSPF_EVENT
)
1146 zlog_debug ("Packet[DD]: Neighbour %s: Has NSSA capability, sends with N bit clear in DD options",
1147 inet_ntoa (nbr
->router_id
) );
1148 SET_FLAG (dd
->options
, OSPF_OPTION_NP
);
1151 #ifdef REJECT_IF_TBIT_ON
1152 if (CHECK_FLAG (dd
->options
, OSPF_OPTION_T
))
1155 * In Hello protocol, optional capability must have checked
1156 * to prevent this T-bit enabled router be my neighbor.
1158 zlog_warn ("Packet[DD]: Neighbor %s: T-bit on?", inet_ntoa (nbr
->router_id
));
1161 #endif /* REJECT_IF_TBIT_ON */
1163 #ifdef HAVE_OPAQUE_LSA
1164 if (CHECK_FLAG (dd
->options
, OSPF_OPTION_O
)
1165 && !CHECK_FLAG (oi
->ospf
->config
, OSPF_OPAQUE_CAPABLE
))
1168 * This node is not configured to handle O-bit, for now.
1169 * Clear it to ignore unsupported capability proposed by neighbor.
1171 UNSET_FLAG (dd
->options
, OSPF_OPTION_O
);
1173 #endif /* HAVE_OPAQUE_LSA */
1175 /* Process DD packet by neighbor status. */
1181 zlog_warn ("Packet[DD]: Neighbor %s state is %s, packet discarded.",
1182 inet_ntoa(nbr
->router_id
),
1183 LOOKUP (ospf_nsm_state_msg
, nbr
->state
));
1186 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_TwoWayReceived
);
1187 /* If the new state is ExStart, the processing of the current
1188 packet should then continue in this new state by falling
1189 through to case ExStart below. */
1190 if (nbr
->state
!= NSM_ExStart
)
1194 if ((IS_SET_DD_ALL (dd
->flags
) == OSPF_DD_FLAG_ALL
) &&
1195 (size
== OSPF_DB_DESC_MIN_SIZE
))
1197 if (IPV4_ADDR_CMP (&nbr
->router_id
, &oi
->ospf
->router_id
) > 0)
1199 /* We're Slave---obey */
1200 zlog_info ("Packet[DD]: Neighbor %s Negotiation done (Slave).",
1201 inet_ntoa(nbr
->router_id
));
1202 nbr
->dd_seqnum
= ntohl (dd
->dd_seqnum
);
1203 nbr
->dd_flags
&= ~(OSPF_DD_FLAG_MS
|OSPF_DD_FLAG_I
); /* Reset I/MS */
1207 /* We're Master, ignore the initial DBD from Slave */
1208 zlog_warn ("Packet[DD]: Neighbor %s: Initial DBD from Slave, "
1209 "ignoring.", inet_ntoa(nbr
->router_id
));
1213 /* Ack from the Slave */
1214 else if (!IS_SET_DD_MS (dd
->flags
) && !IS_SET_DD_I (dd
->flags
) &&
1215 ntohl (dd
->dd_seqnum
) == nbr
->dd_seqnum
&&
1216 IPV4_ADDR_CMP (&nbr
->router_id
, &oi
->ospf
->router_id
) < 0)
1218 zlog_info ("Packet[DD]: Neighbor %s Negotiation done (Master).",
1219 inet_ntoa(nbr
->router_id
));
1220 nbr
->dd_flags
&= ~OSPF_DD_FLAG_I
;
1224 zlog_warn ("Packet[DD]: Neighbor %s Negotiation fails.",
1225 inet_ntoa(nbr
->router_id
));
1229 /* This is where the real Options are saved */
1230 nbr
->options
= dd
->options
;
1232 #ifdef HAVE_OPAQUE_LSA
1233 if (CHECK_FLAG (oi
->ospf
->config
, OSPF_OPAQUE_CAPABLE
))
1235 if (IS_DEBUG_OSPF_EVENT
)
1236 zlog_debug ("Neighbor[%s] is %sOpaque-capable.",
1237 inet_ntoa (nbr
->router_id
),
1238 CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
) ? "" : "NOT ");
1240 if (! CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
)
1241 && IPV4_ADDR_SAME (&DR (oi
), &nbr
->address
.u
.prefix4
))
1243 zlog_warn ("DR-neighbor[%s] is NOT opaque-capable; Opaque-LSAs cannot be reliably advertised in this network.", inet_ntoa (nbr
->router_id
));
1244 /* This situation is undesirable, but not a real error. */
1247 #endif /* HAVE_OPAQUE_LSA */
1249 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_NegotiationDone
);
1251 /* continue processing rest of packet. */
1252 ospf_db_desc_proc (s
, oi
, nbr
, dd
, size
);
1255 if (ospf_db_desc_is_dup (dd
, nbr
))
1257 if (IS_SET_DD_MS (nbr
->dd_flags
))
1258 /* Master: discard duplicated DD packet. */
1259 zlog_warn ("Packet[DD] (Master): Neighbor %s packet duplicated.",
1260 inet_ntoa (nbr
->router_id
));
1262 /* Slave: cause to retransmit the last Database Description. */
1264 zlog_warn ("Packet[DD] [Slave]: Neighbor %s packet duplicated.",
1265 inet_ntoa (nbr
->router_id
));
1266 ospf_db_desc_resend (nbr
);
1271 /* Otherwise DD packet should be checked. */
1272 /* Check Master/Slave bit mismatch */
1273 if (IS_SET_DD_MS (dd
->flags
) != IS_SET_DD_MS (nbr
->last_recv
.flags
))
1275 zlog_warn ("Packet[DD]: Neighbor %s MS-bit mismatch.",
1276 inet_ntoa(nbr
->router_id
));
1277 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1278 if (IS_DEBUG_OSPF_EVENT
)
1279 zlog_debug ("Packet[DD]: dd->flags=%d, nbr->dd_flags=%d",
1280 dd
->flags
, nbr
->dd_flags
);
1284 /* Check initialize bit is set. */
1285 if (IS_SET_DD_I (dd
->flags
))
1287 zlog_warn ("Packet[DD]: Neighbor %s I-bit set.",
1288 inet_ntoa(nbr
->router_id
));
1289 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1293 /* Check DD Options. */
1294 if (dd
->options
!= nbr
->options
)
1296 #ifdef ORIGINAL_CODING
1297 /* Save the new options for debugging */
1298 nbr
->options
= dd
->options
;
1299 #endif /* ORIGINAL_CODING */
1300 zlog_warn ("Packet[DD]: Neighbor %s options mismatch.",
1301 inet_ntoa(nbr
->router_id
));
1302 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1306 /* Check DD sequence number. */
1307 if ((IS_SET_DD_MS (nbr
->dd_flags
) &&
1308 ntohl (dd
->dd_seqnum
) != nbr
->dd_seqnum
) ||
1309 (!IS_SET_DD_MS (nbr
->dd_flags
) &&
1310 ntohl (dd
->dd_seqnum
) != nbr
->dd_seqnum
+ 1))
1312 zlog_warn ("Packet[DD]: Neighbor %s sequence number mismatch.",
1313 inet_ntoa(nbr
->router_id
));
1314 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1318 /* Continue processing rest of packet. */
1319 ospf_db_desc_proc (s
, oi
, nbr
, dd
, size
);
1323 if (ospf_db_desc_is_dup (dd
, nbr
))
1325 if (IS_SET_DD_MS (nbr
->dd_flags
))
1327 /* Master should discard duplicate DD packet. */
1328 zlog_warn("Packet[DD]: Neighbor %s duplicated, packet discarded.",
1329 inet_ntoa(nbr
->router_id
));
1334 struct timeval t
, now
;
1335 gettimeofday (&now
, NULL
);
1336 t
= tv_sub (now
, nbr
->last_send_ts
);
1337 if (tv_cmp (t
, int2tv (nbr
->v_inactivity
)) < 0)
1339 /* In states Loading and Full the slave must resend
1340 its last Database Description packet in response to
1341 duplicate Database Description packets received
1342 from the master. For this reason the slave must
1343 wait RouterDeadInterval seconds before freeing the
1344 last Database Description packet. Reception of a
1345 Database Description packet from the master after
1346 this interval will generate a SeqNumberMismatch
1347 neighbor event. RFC2328 Section 10.8 */
1348 ospf_db_desc_resend (nbr
);
1354 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_SeqNumberMismatch
);
1357 zlog_warn ("Packet[DD]: Neighbor %s NSM illegal status %u.",
1358 inet_ntoa(nbr
->router_id
), nbr
->state
);
1363 #define OSPF_LSA_KEY_SIZE 12 /* type(4) + id(4) + ar(4) */
1365 /* OSPF Link State Request Read -- RFC2328 Section 10.7. */
1367 ospf_ls_req (struct ip
*iph
, struct ospf_header
*ospfh
,
1368 struct stream
*s
, struct ospf_interface
*oi
, u_int16_t size
)
1370 struct ospf_neighbor
*nbr
;
1372 struct in_addr ls_id
;
1373 struct in_addr adv_router
;
1374 struct ospf_lsa
*find
;
1375 struct list
*ls_upd
;
1376 unsigned int length
;
1378 /* Increment statistics. */
1381 nbr
= ospf_nbr_lookup (oi
, iph
, ospfh
);
1384 zlog_warn ("Link State Request: Unknown Neighbor %s.",
1385 inet_ntoa (ospfh
->router_id
));
1389 /* Neighbor State should be Exchange or later. */
1390 if (nbr
->state
!= NSM_Exchange
&&
1391 nbr
->state
!= NSM_Loading
&&
1392 nbr
->state
!= NSM_Full
)
1394 zlog_warn ("Link State Request received from %s: "
1395 "Neighbor state is %s, packet discarded.",
1396 inet_ntoa (ospfh
->router_id
),
1397 LOOKUP (ospf_nsm_state_msg
, nbr
->state
));
1401 /* Send Link State Update for ALL requested LSAs. */
1402 ls_upd
= list_new ();
1403 length
= OSPF_HEADER_SIZE
+ OSPF_LS_UPD_MIN_SIZE
;
1405 while (size
>= OSPF_LSA_KEY_SIZE
)
1407 /* Get one slice of Link State Request. */
1408 ls_type
= stream_getl (s
);
1409 ls_id
.s_addr
= stream_get_ipv4 (s
);
1410 adv_router
.s_addr
= stream_get_ipv4 (s
);
1412 /* Verify LSA type. */
1413 if (ls_type
< OSPF_MIN_LSA
|| ls_type
>= OSPF_MAX_LSA
)
1415 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_BadLSReq
);
1416 list_delete (ls_upd
);
1420 /* Search proper LSA in LSDB. */
1421 find
= ospf_lsa_lookup (oi
->area
, ls_type
, ls_id
, adv_router
);
1424 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_BadLSReq
);
1425 list_delete (ls_upd
);
1429 /* Packet overflows MTU size, send immediately. */
1430 if (length
+ ntohs (find
->data
->length
) > ospf_packet_max (oi
))
1432 if (oi
->type
== OSPF_IFTYPE_NBMA
)
1433 ospf_ls_upd_send (nbr
, ls_upd
, OSPF_SEND_PACKET_DIRECT
);
1435 ospf_ls_upd_send (nbr
, ls_upd
, OSPF_SEND_PACKET_INDIRECT
);
1437 /* Only remove list contents. Keep ls_upd. */
1438 list_delete_all_node (ls_upd
);
1440 length
= OSPF_HEADER_SIZE
+ OSPF_LS_UPD_MIN_SIZE
;
1443 /* Append LSA to update list. */
1444 listnode_add (ls_upd
, find
);
1445 length
+= ntohs (find
->data
->length
);
1447 size
-= OSPF_LSA_KEY_SIZE
;
1450 /* Send rest of Link State Update. */
1451 if (listcount (ls_upd
) > 0)
1453 if (oi
->type
== OSPF_IFTYPE_NBMA
)
1454 ospf_ls_upd_send (nbr
, ls_upd
, OSPF_SEND_PACKET_DIRECT
);
1456 ospf_ls_upd_send (nbr
, ls_upd
, OSPF_SEND_PACKET_INDIRECT
);
1458 list_delete (ls_upd
);
1464 /* Get the list of LSAs from Link State Update packet.
1465 And process some validation -- RFC2328 Section 13. (1)-(2). */
1466 static struct list
*
1467 ospf_ls_upd_list_lsa (struct ospf_neighbor
*nbr
, struct stream
*s
,
1468 struct ospf_interface
*oi
, size_t size
)
1470 u_int16_t count
, sum
;
1472 struct lsa_header
*lsah
;
1473 struct ospf_lsa
*lsa
;
1478 count
= stream_getl (s
);
1479 size
-= OSPF_LS_UPD_MIN_SIZE
; /* # LSAs */
1481 for (; size
>= OSPF_LSA_HEADER_SIZE
&& count
> 0;
1482 size
-= length
, stream_forward (s
, length
), count
--)
1484 lsah
= (struct lsa_header
*) STREAM_PNT (s
);
1485 length
= ntohs (lsah
->length
);
1489 zlog_warn ("Link State Update: LSA length exceeds packet size.");
1493 /* Validate the LSA's LS checksum. */
1494 sum
= lsah
->checksum
;
1495 if (sum
!= ospf_lsa_checksum (lsah
))
1497 zlog_warn ("Link State Update: LSA checksum error %x, %x.",
1498 sum
, lsah
->checksum
);
1502 /* Examine the LSA's LS type. */
1503 if (lsah
->type
< OSPF_MIN_LSA
|| lsah
->type
>= OSPF_MAX_LSA
)
1505 zlog_warn ("Link State Update: Unknown LS type %d", lsah
->type
);
1510 * What if the received LSA's age is greater than MaxAge?
1511 * Treat it as a MaxAge case -- endo.
1513 if (ntohs (lsah
->ls_age
) > OSPF_LSA_MAXAGE
)
1514 lsah
->ls_age
= htons (OSPF_LSA_MAXAGE
);
1516 #ifdef HAVE_OPAQUE_LSA
1517 if (CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
))
1519 #ifdef STRICT_OBIT_USAGE_CHECK
1520 if ((IS_OPAQUE_LSA(lsah
->type
) &&
1521 ! CHECK_FLAG (lsah
->options
, OSPF_OPTION_O
))
1522 || (! IS_OPAQUE_LSA(lsah
->type
) &&
1523 CHECK_FLAG (lsah
->options
, OSPF_OPTION_O
)))
1526 * This neighbor must know the exact usage of O-bit;
1527 * the bit will be set in Type-9,10,11 LSAs only.
1529 zlog_warn ("LSA[Type%d:%s]: O-bit abuse?", lsah
->type
, inet_ntoa (lsah
->id
));
1532 #endif /* STRICT_OBIT_USAGE_CHECK */
1534 /* Do not take in AS External Opaque-LSAs if we are a stub. */
1535 if (lsah
->type
== OSPF_OPAQUE_AS_LSA
1536 && nbr
->oi
->area
->external_routing
!= OSPF_AREA_DEFAULT
)
1538 if (IS_DEBUG_OSPF_EVENT
)
1539 zlog_debug ("LSA[Type%d:%s]: We are a stub, don't take this LSA.", lsah
->type
, inet_ntoa (lsah
->id
));
1543 else if (IS_OPAQUE_LSA(lsah
->type
))
1545 zlog_warn ("LSA[Type%d:%s]: Opaque capability mismatch?", lsah
->type
, inet_ntoa (lsah
->id
));
1548 #endif /* HAVE_OPAQUE_LSA */
1550 /* Create OSPF LSA instance. */
1551 lsa
= ospf_lsa_new ();
1553 /* We may wish to put some error checking if type NSSA comes in
1554 and area not in NSSA mode */
1557 case OSPF_AS_EXTERNAL_LSA
:
1558 #ifdef HAVE_OPAQUE_LSA
1559 case OSPF_OPAQUE_AS_LSA
:
1562 case OSPF_OPAQUE_LINK_LSA
:
1563 lsa
->oi
= oi
; /* Remember incoming interface for flooding control. */
1565 #endif /* HAVE_OPAQUE_LSA */
1567 lsa
->area
= oi
->area
;
1571 lsa
->data
= ospf_lsa_data_new (length
);
1572 memcpy (lsa
->data
, lsah
, length
);
1574 if (IS_DEBUG_OSPF_EVENT
)
1575 zlog_debug("LSA[Type%d:%s]: %p new LSA created with Link State Update",
1576 lsa
->data
->type
, inet_ntoa (lsa
->data
->id
), lsa
);
1577 listnode_add (lsas
, lsa
);
1583 /* Cleanup Update list. */
1585 ospf_upd_list_clean (struct list
*lsas
)
1587 struct listnode
*node
;
1588 struct ospf_lsa
*lsa
;
1590 for (node
= listhead (lsas
); node
; nextnode (node
))
1591 if ((lsa
= getdata (node
)) != NULL
)
1592 ospf_lsa_discard (lsa
);
1597 /* OSPF Link State Update message read -- RFC2328 Section 13. */
1599 ospf_ls_upd (struct ip
*iph
, struct ospf_header
*ospfh
,
1600 struct stream
*s
, struct ospf_interface
*oi
, u_int16_t size
)
1602 struct ospf_neighbor
*nbr
;
1604 #ifdef HAVE_OPAQUE_LSA
1605 struct list
*mylsa_acks
, *mylsa_upds
;
1606 #endif /* HAVE_OPAQUE_LSA */
1607 struct listnode
*node
, *next
;
1608 struct ospf_lsa
*lsa
= NULL
;
1609 /* unsigned long ls_req_found = 0; */
1611 /* Dis-assemble the stream, update each entry, re-encapsulate for flooding */
1613 /* Increment statistics. */
1616 /* Check neighbor. */
1617 nbr
= ospf_nbr_lookup (oi
, iph
, ospfh
);
1620 zlog_warn ("Link State Update: Unknown Neighbor %s on int: %s",
1621 inet_ntoa (ospfh
->router_id
), IF_NAME (oi
));
1625 /* Check neighbor state. */
1626 if (nbr
->state
< NSM_Exchange
)
1628 zlog_warn ("Link State Update: "
1629 "Neighbor[%s] state %s is less than Exchange",
1630 inet_ntoa (ospfh
->router_id
),
1631 LOOKUP(ospf_nsm_state_msg
, nbr
->state
));
1635 /* Get list of LSAs from Link State Update packet. - Also perorms Stages
1636 * 1 (validate LSA checksum) and 2 (check for LSA consistent type)
1639 lsas
= ospf_ls_upd_list_lsa (nbr
, s
, oi
, size
);
1641 #ifdef HAVE_OPAQUE_LSA
1643 * Prepare two kinds of lists to clean up unwanted self-originated
1644 * Opaque-LSAs from the routing domain as soon as possible.
1646 mylsa_acks
= list_new (); /* Let the sender cease retransmission. */
1647 mylsa_upds
= list_new (); /* Flush target LSAs if necessary. */
1650 * If self-originated Opaque-LSAs that have flooded before restart
1651 * are contained in the received LSUpd message, corresponding LSReq
1652 * messages to be sent may have to be modified.
1653 * To eliminate possible race conditions such that flushing and normal
1654 * updating for the same LSA would take place alternately, this trick
1655 * must be done before entering to the loop below.
1657 ospf_opaque_adjust_lsreq (nbr
, lsas
);
1658 #endif /* HAVE_OPAQUE_LSA */
1660 #define DISCARD_LSA(L,N) {\
1661 if (IS_DEBUG_OSPF_EVENT) \
1662 zlog_debug ("ospf_lsa_discard() in ospf_ls_upd() point %d: lsa %p Type-%d", N, lsa, (int) lsa->data->type); \
1663 ospf_lsa_discard (L); \
1666 /* Process each LSA received in the one packet. */
1667 for (node
= listhead (lsas
); node
; node
= next
)
1669 struct ospf_lsa
*ls_ret
, *current
;
1674 lsa
= getdata (node
);
1676 if (IS_DEBUG_OSPF_NSSA
)
1678 char buf1
[INET_ADDRSTRLEN
];
1679 char buf2
[INET_ADDRSTRLEN
];
1680 char buf3
[INET_ADDRSTRLEN
];
1682 zlog_debug("LSA Type-%d from %s, ID: %s, ADV: %s",
1684 inet_ntop (AF_INET
, &ospfh
->router_id
,
1685 buf1
, INET_ADDRSTRLEN
),
1686 inet_ntop (AF_INET
, &lsa
->data
->id
,
1687 buf2
, INET_ADDRSTRLEN
),
1688 inet_ntop (AF_INET
, &lsa
->data
->adv_router
,
1689 buf3
, INET_ADDRSTRLEN
));
1692 listnode_delete (lsas
, lsa
); /* We don't need it in list anymore */
1694 /* Validate Checksum - Done above by ospf_ls_upd_list_lsa() */
1696 /* LSA Type - Done above by ospf_ls_upd_list_lsa() */
1698 /* Do not take in AS External LSAs if we are a stub or NSSA. */
1700 /* Do not take in AS NSSA if this neighbor and we are not NSSA */
1702 /* Do take in Type-7's if we are an NSSA */
1704 /* If we are also an ABR, later translate them to a Type-5 packet */
1706 /* Later, an NSSA Re-fresh can Re-fresh Type-7's and an ABR will
1707 translate them to a separate Type-5 packet. */
1709 if (lsa
->data
->type
== OSPF_AS_EXTERNAL_LSA
)
1710 /* Reject from STUB or NSSA */
1711 if (nbr
->oi
->area
->external_routing
!= OSPF_AREA_DEFAULT
)
1713 DISCARD_LSA (lsa
, 1);
1714 if (IS_DEBUG_OSPF_NSSA
)
1715 zlog_debug("Incoming External LSA Discarded: We are NSSA/STUB Area");
1718 if (lsa
->data
->type
== OSPF_AS_NSSA_LSA
)
1719 if (nbr
->oi
->area
->external_routing
!= OSPF_AREA_NSSA
)
1721 DISCARD_LSA (lsa
,2);
1722 if (IS_DEBUG_OSPF_NSSA
)
1723 zlog_debug("Incoming NSSA LSA Discarded: Not NSSA Area");
1726 /* Find the LSA in the current database. */
1728 current
= ospf_lsa_lookup_by_header (oi
->area
, lsa
->data
);
1730 /* If the LSA's LS age is equal to MaxAge, and there is currently
1731 no instance of the LSA in the router's link state database,
1732 and none of router's neighbors are in states Exchange or Loading,
1733 then take the following actions. */
1735 if (IS_LSA_MAXAGE (lsa
) && !current
&&
1736 (ospf_nbr_count (oi
, NSM_Exchange
) +
1737 ospf_nbr_count (oi
, NSM_Loading
)) == 0)
1739 /* Response Link State Acknowledgment. */
1740 ospf_ls_ack_send (nbr
, lsa
);
1743 zlog_warn("Link State Update[%s]: LS age is equal to MaxAge.",
1745 DISCARD_LSA (lsa
, 3);
1748 #ifdef HAVE_OPAQUE_LSA
1749 if (IS_OPAQUE_LSA (lsa
->data
->type
)
1750 && IPV4_ADDR_SAME (&lsa
->data
->adv_router
, &oi
->ospf
->router_id
))
1753 * Even if initial flushing seems to be completed, there might
1754 * be a case that self-originated LSA with MaxAge still remain
1755 * in the routing domain.
1756 * Just send an LSAck message to cease retransmission.
1758 if (IS_LSA_MAXAGE (lsa
))
1760 zlog_warn ("LSA[%s]: Boomerang effect?", dump_lsa_key (lsa
));
1761 ospf_ls_ack_send (nbr
, lsa
);
1762 ospf_lsa_discard (lsa
);
1764 if (current
!= NULL
&& ! IS_LSA_MAXAGE (current
))
1765 ospf_opaque_lsa_refresh_schedule (current
);
1770 * If an instance of self-originated Opaque-LSA is not found
1771 * in the LSDB, there are some possible cases here.
1773 * 1) This node lost opaque-capability after restart.
1774 * 2) Else, a part of opaque-type is no more supported.
1775 * 3) Else, a part of opaque-id is no more supported.
1777 * Anyway, it is still this node's responsibility to flush it.
1778 * Otherwise, the LSA instance remains in the routing domain
1779 * until its age reaches to MaxAge.
1781 if (current
== NULL
)
1783 if (IS_DEBUG_OSPF_EVENT
)
1784 zlog_debug ("LSA[%s]: Previously originated Opaque-LSA, not found in the LSDB.", dump_lsa_key (lsa
));
1786 SET_FLAG (lsa
->flags
, OSPF_LSA_SELF
);
1787 listnode_add (mylsa_upds
, ospf_lsa_dup (lsa
));
1788 listnode_add (mylsa_acks
, ospf_lsa_lock (lsa
));
1792 #endif /* HAVE_OPAQUE_LSA */
1793 /* It might be happen that received LSA is self-originated network LSA, but
1794 * router ID is cahnged. So, we should check if LSA is a network-LSA whose
1795 * Link State ID is one of the router's own IP interface addresses but whose
1796 * Advertising Router is not equal to the router's own Router ID
1797 * According to RFC 2328 12.4.2 and 13.4 this LSA should be flushed.
1800 if(lsa
->data
->type
== OSPF_NETWORK_LSA
)
1802 struct listnode
*oi_node
;
1805 for(oi_node
= listhead(oi
->ospf
->oiflist
); oi_node
; oi_node
= nextnode(oi_node
))
1807 struct ospf_interface
*out_if
= getdata(oi_node
);
1811 if((IPV4_ADDR_SAME(&out_if
->address
->u
.prefix4
, &lsa
->data
->id
)) &&
1812 (!(IPV4_ADDR_SAME(&oi
->ospf
->router_id
, &lsa
->data
->adv_router
))))
1814 if(out_if
->network_lsa_self
)
1816 ospf_lsa_flush_area(lsa
,out_if
->area
);
1817 if(IS_DEBUG_OSPF_EVENT
)
1818 zlog_debug ("ospf_lsa_discard() in ospf_ls_upd() point 9: lsa %p Type-%d",
1819 lsa
, (int) lsa
->data
->type
);
1820 ospf_lsa_discard (lsa
);
1830 /* (5) Find the instance of this LSA that is currently contained
1831 in the router's link state database. If there is no
1832 database copy, or the received LSA is more recent than
1833 the database copy the following steps must be performed. */
1835 if (current
== NULL
||
1836 (ret
= ospf_lsa_more_recent (current
, lsa
)) < 0)
1838 /* Actual flooding procedure. */
1839 if (ospf_flood (oi
->ospf
, nbr
, current
, lsa
) < 0) /* Trap NSSA later. */
1840 DISCARD_LSA (lsa
, 4);
1844 /* (6) Else, If there is an instance of the LSA on the sending
1845 neighbor's Link state request list, an error has occurred in
1846 the Database Exchange process. In this case, restart the
1847 Database Exchange process by generating the neighbor event
1848 BadLSReq for the sending neighbor and stop processing the
1849 Link State Update packet. */
1851 if (ospf_ls_request_lookup (nbr
, lsa
))
1853 OSPF_NSM_EVENT_SCHEDULE (nbr
, NSM_BadLSReq
);
1854 zlog_warn("LSA[%s] instance exists on Link state request list",
1857 /* Clean list of LSAs. */
1858 ospf_upd_list_clean (lsas
);
1859 /* this lsa is not on lsas list already. */
1860 ospf_lsa_discard (lsa
);
1861 #ifdef HAVE_OPAQUE_LSA
1862 list_delete (mylsa_acks
);
1863 list_delete (mylsa_upds
);
1864 #endif /* HAVE_OPAQUE_LSA */
1868 /* If the received LSA is the same instance as the database copy
1869 (i.e., neither one is more recent) the following two steps
1870 should be performed: */
1874 /* If the LSA is listed in the Link state retransmission list
1875 for the receiving adjacency, the router itself is expecting
1876 an acknowledgment for this LSA. The router should treat the
1877 received LSA as an acknowledgment by removing the LSA from
1878 the Link state retransmission list. This is termed an
1879 "implied acknowledgment". */
1881 ls_ret
= ospf_ls_retransmit_lookup (nbr
, lsa
);
1885 ospf_ls_retransmit_delete (nbr
, ls_ret
);
1887 /* Delayed acknowledgment sent if advertisement received
1888 from Designated Router, otherwise do nothing. */
1889 if (oi
->state
== ISM_Backup
)
1890 if (NBR_IS_DR (nbr
))
1891 listnode_add (oi
->ls_ack
, ospf_lsa_lock (lsa
));
1893 DISCARD_LSA (lsa
, 5);
1896 /* Acknowledge the receipt of the LSA by sending a
1897 Link State Acknowledgment packet back out the receiving
1900 ospf_ls_ack_send (nbr
, lsa
);
1901 DISCARD_LSA (lsa
, 6);
1905 /* The database copy is more recent. If the database copy
1906 has LS age equal to MaxAge and LS sequence number equal to
1907 MaxSequenceNumber, simply discard the received LSA without
1908 acknowledging it. (In this case, the LSA's LS sequence number is
1909 wrapping, and the MaxSequenceNumber LSA must be completely
1910 flushed before any new LSA instance can be introduced). */
1912 else if (ret
> 0) /* Database copy is more recent */
1914 if (IS_LSA_MAXAGE (current
) &&
1915 current
->data
->ls_seqnum
== htonl (OSPF_MAX_SEQUENCE_NUMBER
))
1917 DISCARD_LSA (lsa
, 7);
1919 /* Otherwise, as long as the database copy has not been sent in a
1920 Link State Update within the last MinLSArrival seconds, send the
1921 database copy back to the sending neighbor, encapsulated within
1922 a Link State Update Packet. The Link State Update Packet should
1923 be sent directly to the neighbor. In so doing, do not put the
1924 database copy of the LSA on the neighbor's link state
1925 retransmission list, and do not acknowledge the received (less
1926 recent) LSA instance. */
1931 gettimeofday (&now
, NULL
);
1933 if (tv_cmp (tv_sub (now
, current
->tv_orig
),
1934 int2tv (OSPF_MIN_LS_ARRIVAL
)) > 0)
1935 /* Trap NSSA type later.*/
1936 ospf_ls_upd_send_lsa (nbr
, current
, OSPF_SEND_PACKET_DIRECT
);
1937 DISCARD_LSA (lsa
, 8);
1942 #ifdef HAVE_OPAQUE_LSA
1944 * Now that previously originated Opaque-LSAs those which not yet
1945 * installed into LSDB are captured, take several steps to clear
1946 * them completely from the routing domain, before proceeding to
1947 * origination for the current target Opaque-LSAs.
1949 while (listcount (mylsa_acks
) > 0)
1950 ospf_ls_ack_send_list (oi
, mylsa_acks
, nbr
->address
.u
.prefix4
);
1952 if (listcount (mylsa_upds
) > 0)
1953 ospf_opaque_self_originated_lsa_received (nbr
, mylsa_upds
);
1955 list_delete (mylsa_upds
);
1956 list_delete (mylsa_acks
);
1957 #endif /* HAVE_OPAQUE_LSA */
1959 assert (listcount (lsas
) == 0);
1963 /* OSPF Link State Acknowledgment message read -- RFC2328 Section 13.7. */
1965 ospf_ls_ack (struct ip
*iph
, struct ospf_header
*ospfh
,
1966 struct stream
*s
, struct ospf_interface
*oi
, u_int16_t size
)
1968 struct ospf_neighbor
*nbr
;
1969 #ifdef HAVE_OPAQUE_LSA
1970 struct list
*opaque_acks
;
1971 #endif /* HAVE_OPAQUE_LSA */
1973 /* increment statistics. */
1976 nbr
= ospf_nbr_lookup (oi
, iph
, ospfh
);
1979 zlog_warn ("Link State Acknowledgment: Unknown Neighbor %s.",
1980 inet_ntoa (ospfh
->router_id
));
1984 if (nbr
->state
< NSM_Exchange
)
1986 zlog_warn ("Link State Acknowledgment: "
1987 "Neighbor[%s] state %s is less than Exchange",
1988 inet_ntoa (ospfh
->router_id
),
1989 LOOKUP(ospf_nsm_state_msg
, nbr
->state
));
1993 #ifdef HAVE_OPAQUE_LSA
1994 opaque_acks
= list_new ();
1995 #endif /* HAVE_OPAQUE_LSA */
1997 while (size
>= OSPF_LSA_HEADER_SIZE
)
1999 struct ospf_lsa
*lsa
, *lsr
;
2001 lsa
= ospf_lsa_new ();
2002 lsa
->data
= (struct lsa_header
*) STREAM_PNT (s
);
2004 /* lsah = (struct lsa_header *) STREAM_PNT (s); */
2005 size
-= OSPF_LSA_HEADER_SIZE
;
2006 stream_forward (s
, OSPF_LSA_HEADER_SIZE
);
2008 if (lsa
->data
->type
< OSPF_MIN_LSA
|| lsa
->data
->type
>= OSPF_MAX_LSA
)
2011 ospf_lsa_discard (lsa
);
2015 lsr
= ospf_ls_retransmit_lookup (nbr
, lsa
);
2017 if (lsr
!= NULL
&& lsr
->data
->ls_seqnum
== lsa
->data
->ls_seqnum
)
2019 #ifdef HAVE_OPAQUE_LSA
2020 /* Keep this LSA entry for later reference. */
2021 if (IS_OPAQUE_LSA (lsr
->data
->type
))
2022 listnode_add (opaque_acks
, ospf_lsa_dup (lsr
));
2023 #endif /* HAVE_OPAQUE_LSA */
2025 ospf_ls_retransmit_delete (nbr
, lsr
);
2029 ospf_lsa_discard (lsa
);
2032 #ifdef HAVE_OPAQUE_LSA
2033 if (listcount (opaque_acks
) > 0)
2034 ospf_opaque_ls_ack_received (nbr
, opaque_acks
);
2036 list_delete (opaque_acks
);
2038 #endif /* HAVE_OPAQUE_LSA */
2042 ospf_recv_packet (int fd
, struct interface
**ifp
)
2047 struct stream
*ibuf
;
2048 unsigned int ifindex
= 0;
2050 /* Header and data both require alignment. */
2051 char buff
[CMSG_SPACE(SOPT_SIZE_CMSG_IFINDEX_IPV4())];
2054 memset (&msgh
, 0, sizeof (struct msghdr
));
2055 msgh
.msg_iov
= &iov
;
2056 msgh
.msg_iovlen
= 1;
2057 msgh
.msg_control
= (caddr_t
) buff
;
2058 msgh
.msg_controllen
= sizeof (buff
);
2060 ret
= recvfrom (fd
, (void *)&iph
, sizeof (iph
), MSG_PEEK
, NULL
, 0);
2062 if (ret
!= sizeof (iph
))
2064 zlog_warn ("ospf_recv_packet packet smaller than ip header");
2065 /* XXX: We peeked, and thus perhaps should discard this packet. */
2069 sockopt_iphdrincl_swab_systoh (&iph
);
2071 ip_len
= iph
.ip_len
;
2073 #if !defined(GNU_LINUX) && (OpenBSD < 200311)
2075 * Kernel network code touches incoming IP header parameters,
2076 * before protocol specific processing.
2078 * 1) Convert byteorder to host representation.
2079 * --> ip_len, ip_id, ip_off
2081 * 2) Adjust ip_len to strip IP header size!
2082 * --> If user process receives entire IP packet via RAW
2083 * socket, it must consider adding IP header size to
2084 * the "ip_len" field of "ip" structure.
2086 * For more details, see <netinet/ip_input.c>.
2088 ip_len
= ip_len
+ (iph
.ip_hl
<< 2);
2091 ibuf
= stream_new (ip_len
);
2092 iov
.iov_base
= STREAM_DATA (ibuf
);
2093 iov
.iov_len
= ip_len
;
2094 ret
= recvmsg (fd
, &msgh
, 0);
2096 ifindex
= getsockopt_ifindex (AF_INET
, &msgh
);
2098 *ifp
= if_lookup_by_index (ifindex
);
2102 zlog_warn ("ospf_recv_packet short read. "
2103 "ip_len %d bytes read %d", ip_len
, ret
);
2111 struct ospf_interface
*
2112 ospf_associate_packet_vl (struct ospf
*ospf
, struct interface
*ifp
,
2113 struct ip
*iph
, struct ospf_header
*ospfh
)
2115 struct ospf_interface
*rcv_oi
;
2116 struct ospf_vl_data
*vl_data
;
2117 struct ospf_area
*vl_area
;
2118 struct listnode
*node
;
2120 if (IN_MULTICAST (ntohl (iph
->ip_dst
.s_addr
)) ||
2121 !OSPF_IS_AREA_BACKBONE (ospfh
))
2124 /* look for local OSPF interface matching the destination
2125 * to determine Area ID. We presume therefore the destination address
2126 * is unique, or at least (for "unnumbered" links), not used in other
2129 if ((rcv_oi
= ospf_if_lookup_by_local_addr (ospf
, NULL
,
2130 iph
->ip_dst
)) == NULL
)
2133 for (node
= listhead (ospf
->vlinks
); node
; nextnode (node
))
2135 if ((vl_data
= getdata (node
)) == NULL
)
2138 vl_area
= ospf_area_lookup_by_area_id (ospf
, vl_data
->vl_area_id
);
2142 if (OSPF_AREA_SAME (&vl_area
, &rcv_oi
->area
) &&
2143 IPV4_ADDR_SAME (&vl_data
->vl_peer
, &ospfh
->router_id
))
2145 if (IS_DEBUG_OSPF_EVENT
)
2146 zlog_debug ("associating packet with %s",
2147 IF_NAME (vl_data
->vl_oi
));
2148 if (! CHECK_FLAG (vl_data
->vl_oi
->ifp
->flags
, IFF_UP
))
2150 if (IS_DEBUG_OSPF_EVENT
)
2151 zlog_debug ("This VL is not up yet, sorry");
2155 return vl_data
->vl_oi
;
2159 if (IS_DEBUG_OSPF_EVENT
)
2160 zlog_debug ("couldn't find any VL to associate the packet with");
2166 ospf_check_area_id (struct ospf_interface
*oi
, struct ospf_header
*ospfh
)
2168 /* Check match the Area ID of the receiving interface. */
2169 if (OSPF_AREA_SAME (&oi
->area
, &ospfh
))
2175 /* Unbound socket will accept any Raw IP packets if proto is matched.
2176 To prevent it, compare src IP address and i/f address with masking
2177 i/f network mask. */
2179 ospf_check_network_mask (struct ospf_interface
*oi
, struct in_addr ip_src
)
2181 struct in_addr mask
, me
, him
;
2183 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
||
2184 oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
2187 masklen2ip (oi
->address
->prefixlen
, &mask
);
2189 me
.s_addr
= oi
->address
->u
.prefix4
.s_addr
& mask
.s_addr
;
2190 him
.s_addr
= ip_src
.s_addr
& mask
.s_addr
;
2192 if (IPV4_ADDR_SAME (&me
, &him
))
2199 ospf_check_auth (struct ospf_interface
*oi
, struct stream
*ibuf
,
2200 struct ospf_header
*ospfh
)
2203 struct crypt_key
*ck
;
2205 switch (ntohs (ospfh
->auth_type
))
2207 case OSPF_AUTH_NULL
:
2210 case OSPF_AUTH_SIMPLE
:
2211 if (!memcmp (OSPF_IF_PARAM (oi
, auth_simple
), ospfh
->u
.auth_data
, OSPF_AUTH_SIMPLE_SIZE
))
2216 case OSPF_AUTH_CRYPTOGRAPHIC
:
2217 if ((ck
= getdata (OSPF_IF_PARAM (oi
,auth_crypt
)->tail
)) == NULL
)
2223 /* This is very basic, the digest processing is elsewhere */
2224 if (ospfh
->u
.crypt
.auth_data_len
== OSPF_AUTH_MD5_SIZE
&&
2225 ospfh
->u
.crypt
.key_id
== ck
->key_id
&&
2226 ntohs (ospfh
->length
) + OSPF_AUTH_SIMPLE_SIZE
<= stream_get_size (ibuf
))
2240 ospf_check_sum (struct ospf_header
*ospfh
)
2244 int in_cksum (void *ptr
, int nbytes
);
2246 /* clear auth_data for checksum. */
2247 memset (ospfh
->u
.auth_data
, 0, OSPF_AUTH_SIMPLE_SIZE
);
2249 /* keep checksum and clear. */
2250 sum
= ospfh
->checksum
;
2251 memset (&ospfh
->checksum
, 0, sizeof (u_int16_t
));
2253 /* calculate checksum. */
2254 ret
= in_cksum (ospfh
, ntohs (ospfh
->length
));
2258 zlog_info ("ospf_check_sum(): checksum mismatch, my %X, his %X",
2266 /* OSPF Header verification. */
2268 ospf_verify_header (struct stream
*ibuf
, struct ospf_interface
*oi
,
2269 struct ip
*iph
, struct ospf_header
*ospfh
)
2271 /* check version. */
2272 if (ospfh
->version
!= OSPF_VERSION
)
2274 zlog_warn ("interface %s: ospf_read version number mismatch.",
2279 /* Check Area ID. */
2280 if (!ospf_check_area_id (oi
, ospfh
))
2282 zlog_warn ("interface %s: ospf_read invalid Area ID %s.",
2283 IF_NAME (oi
), inet_ntoa (ospfh
->area_id
));
2287 /* Check network mask, Silently discarded. */
2288 if (! ospf_check_network_mask (oi
, iph
->ip_src
))
2290 zlog_warn ("interface %s: ospf_read network address is not same [%s]",
2291 IF_NAME (oi
), inet_ntoa (iph
->ip_src
));
2295 /* Check authentication. */
2296 if (ospf_auth_type (oi
) != ntohs (ospfh
->auth_type
))
2298 zlog_warn ("interface %s: ospf_read authentication type mismatch.",
2303 if (! ospf_check_auth (oi
, ibuf
, ospfh
))
2305 zlog_warn ("interface %s: ospf_read authentication failed.",
2310 /* if check sum is invalid, packet is discarded. */
2311 if (ntohs (ospfh
->auth_type
) != OSPF_AUTH_CRYPTOGRAPHIC
)
2313 if (! ospf_check_sum (ospfh
))
2315 zlog_warn ("interface %s: ospf_read packet checksum error %s",
2316 IF_NAME (oi
), inet_ntoa (ospfh
->router_id
));
2322 if (ospfh
->checksum
!= 0)
2324 if (ospf_check_md5_digest (oi
, ibuf
, ntohs (ospfh
->length
)) == 0)
2326 zlog_warn ("interface %s: ospf_read md5 authentication failed.",
2335 /* Starting point of packet process function. */
2337 ospf_read (struct thread
*thread
)
2340 struct stream
*ibuf
;
2342 struct ospf_interface
*oi
;
2344 struct ospf_header
*ospfh
;
2346 struct interface
*ifp
;
2348 /* first of all get interface pointer. */
2349 ospf
= THREAD_ARG (thread
);
2350 ospf
->t_read
= NULL
;
2352 /* read OSPF packet. */
2353 ibuf
= ospf_recv_packet (ospf
->fd
, &ifp
);
2357 iph
= (struct ip
*) STREAM_DATA (ibuf
);
2358 sockopt_iphdrincl_swab_systoh (iph
);
2361 /* Handle cases where the platform does not support retrieving the ifindex,
2362 and also platforms (such as Solaris 8) that claim to support ifindex
2363 retrieval but do not. */
2364 ifp
= if_lookup_address (iph
->ip_src
);
2372 /* prepare for next packet. */
2373 ospf
->t_read
= thread_add_read (master
, ospf_read
, ospf
, ospf
->fd
);
2375 /* IP Header dump. */
2376 if (IS_DEBUG_OSPF_PACKET(0, RECV
))
2377 ospf_ip_header_dump (iph
);
2379 /* Self-originated packet should be discarded silently. */
2380 if (ospf_if_lookup_by_local_addr (ospf
, NULL
, iph
->ip_src
))
2382 if (IS_DEBUG_OSPF_PACKET (0, RECV
))
2384 zlog_debug ("ospf_read[%s]: Dropping self-originated packet",
2385 inet_ntoa (iph
->ip_src
));
2391 /* Adjust size to message length. */
2392 stream_forward (ibuf
, iph
->ip_hl
* 4);
2394 /* Get ospf packet header. */
2395 ospfh
= (struct ospf_header
*) STREAM_PNT (ibuf
);
2397 /* associate packet with ospf interface */
2398 oi
= ospf_if_lookup_recv_if (ospf
, iph
->ip_src
);
2400 /* if no local ospf_interface,
2401 * or header area is backbone but ospf_interface is not
2402 * check for VLINK interface
2404 if ( (oi
== NULL
) ||
2405 (OSPF_IS_AREA_ID_BACKBONE(ospfh
->area_id
)
2406 && !OSPF_IS_AREA_ID_BACKBONE(oi
->area
->area_id
))
2409 if ((oi
= ospf_associate_packet_vl (ospf
, ifp
, iph
, ospfh
)) == NULL
)
2411 zlog_warn ("Packet from [%s] received on link %s"
2412 " but no ospf_interface",
2413 inet_ntoa (iph
->ip_src
), ifp
->name
);
2419 /* else it must be a local ospf interface, check it was received on
2422 else if (oi
->ifp
!= ifp
)
2424 zlog_warn ("Packet from [%s] received on wrong link %s",
2425 inet_ntoa (iph
->ip_src
), ifp
->name
);
2429 else if (oi
->state
== ISM_Down
)
2431 zlog_warn ("Ignoring packet from [%s] received on interface that is "
2432 "down [%s]; interface flags are %s",
2433 inet_ntoa (iph
->ip_src
), ifp
->name
, if_flag_dump(ifp
->flags
));
2439 * If the received packet is destined for AllDRouters, the packet
2440 * should be accepted only if the received ospf interface state is
2441 * either DR or Backup -- endo.
2443 if (iph
->ip_dst
.s_addr
== htonl (OSPF_ALLDROUTERS
)
2444 && (oi
->state
!= ISM_DR
&& oi
->state
!= ISM_Backup
))
2446 zlog_info ("Packet for AllDRouters from [%s] via [%s] (ISM: %s)",
2447 inet_ntoa (iph
->ip_src
), IF_NAME (oi
),
2448 LOOKUP (ospf_ism_state_msg
, oi
->state
));
2453 /* Show debug receiving packet. */
2454 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, RECV
))
2456 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, DETAIL
))
2458 zlog_debug ("-----------------------------------------------------");
2459 ospf_packet_dump (ibuf
);
2462 zlog_debug ("%s received from [%s] via [%s]",
2463 ospf_packet_type_str
[ospfh
->type
],
2464 inet_ntoa (ospfh
->router_id
), IF_NAME (oi
));
2465 zlog_debug (" src [%s],", inet_ntoa (iph
->ip_src
));
2466 zlog_debug (" dst [%s]", inet_ntoa (iph
->ip_dst
));
2468 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, DETAIL
))
2469 zlog_debug ("-----------------------------------------------------");
2472 /* Some header verification. */
2473 ret
= ospf_verify_header (ibuf
, oi
, iph
, ospfh
);
2476 if (IS_DEBUG_OSPF_PACKET (ospfh
->type
- 1, RECV
))
2478 zlog_debug ("ospf_read[%s/%s]: Header check failed, "
2480 ospf_packet_type_str
[ospfh
->type
],
2481 inet_ntoa (iph
->ip_src
));
2487 stream_forward (ibuf
, OSPF_HEADER_SIZE
);
2489 /* Adjust size to message length. */
2490 length
= ntohs (ospfh
->length
) - OSPF_HEADER_SIZE
;
2492 /* Read rest of the packet and call each sort of packet routine. */
2493 switch (ospfh
->type
)
2495 case OSPF_MSG_HELLO
:
2496 ospf_hello (iph
, ospfh
, ibuf
, oi
, length
);
2498 case OSPF_MSG_DB_DESC
:
2499 ospf_db_desc (iph
, ospfh
, ibuf
, oi
, length
);
2501 case OSPF_MSG_LS_REQ
:
2502 ospf_ls_req (iph
, ospfh
, ibuf
, oi
, length
);
2504 case OSPF_MSG_LS_UPD
:
2505 ospf_ls_upd (iph
, ospfh
, ibuf
, oi
, length
);
2507 case OSPF_MSG_LS_ACK
:
2508 ospf_ls_ack (iph
, ospfh
, ibuf
, oi
, length
);
2511 zlog (NULL
, LOG_WARNING
,
2512 "interface %s: OSPF packet header type %d is illegal",
2513 IF_NAME (oi
), ospfh
->type
);
2521 /* Make OSPF header. */
2523 ospf_make_header (int type
, struct ospf_interface
*oi
, struct stream
*s
)
2525 struct ospf_header
*ospfh
;
2527 ospfh
= (struct ospf_header
*) STREAM_DATA (s
);
2529 ospfh
->version
= (u_char
) OSPF_VERSION
;
2530 ospfh
->type
= (u_char
) type
;
2532 ospfh
->router_id
= oi
->ospf
->router_id
;
2534 ospfh
->checksum
= 0;
2535 ospfh
->area_id
= oi
->area
->area_id
;
2536 ospfh
->auth_type
= htons (ospf_auth_type (oi
));
2538 memset (ospfh
->u
.auth_data
, 0, OSPF_AUTH_SIMPLE_SIZE
);
2540 ospf_output_forward (s
, OSPF_HEADER_SIZE
);
2543 /* Make Authentication Data. */
2545 ospf_make_auth (struct ospf_interface
*oi
, struct ospf_header
*ospfh
)
2547 struct crypt_key
*ck
;
2549 switch (ospf_auth_type (oi
))
2551 case OSPF_AUTH_NULL
:
2552 /* memset (ospfh->u.auth_data, 0, sizeof (ospfh->u.auth_data)); */
2554 case OSPF_AUTH_SIMPLE
:
2555 memcpy (ospfh
->u
.auth_data
, OSPF_IF_PARAM (oi
, auth_simple
),
2556 OSPF_AUTH_SIMPLE_SIZE
);
2558 case OSPF_AUTH_CRYPTOGRAPHIC
:
2559 /* If key is not set, then set 0. */
2560 if (list_isempty (OSPF_IF_PARAM (oi
, auth_crypt
)))
2562 ospfh
->u
.crypt
.zero
= 0;
2563 ospfh
->u
.crypt
.key_id
= 0;
2564 ospfh
->u
.crypt
.auth_data_len
= OSPF_AUTH_MD5_SIZE
;
2568 ck
= getdata (OSPF_IF_PARAM (oi
, auth_crypt
)->tail
);
2569 ospfh
->u
.crypt
.zero
= 0;
2570 ospfh
->u
.crypt
.key_id
= ck
->key_id
;
2571 ospfh
->u
.crypt
.auth_data_len
= OSPF_AUTH_MD5_SIZE
;
2573 /* note: the seq is done in ospf_make_md5_digest() */
2576 /* memset (ospfh->u.auth_data, 0, sizeof (ospfh->u.auth_data)); */
2583 /* Fill rest of OSPF header. */
2585 ospf_fill_header (struct ospf_interface
*oi
,
2586 struct stream
*s
, u_int16_t length
)
2588 struct ospf_header
*ospfh
;
2590 ospfh
= (struct ospf_header
*) STREAM_DATA (s
);
2593 ospfh
->length
= htons (length
);
2595 /* Calculate checksum. */
2596 if (ntohs (ospfh
->auth_type
) != OSPF_AUTH_CRYPTOGRAPHIC
)
2597 ospfh
->checksum
= in_cksum (ospfh
, length
);
2599 ospfh
->checksum
= 0;
2601 /* Add Authentication Data. */
2602 ospf_make_auth (oi
, ospfh
);
2606 ospf_make_hello (struct ospf_interface
*oi
, struct stream
*s
)
2608 struct ospf_neighbor
*nbr
;
2609 struct route_node
*rn
;
2610 u_int16_t length
= OSPF_HELLO_MIN_SIZE
;
2611 struct in_addr mask
;
2615 /* Set netmask of interface. */
2616 if (oi
->type
!= OSPF_IFTYPE_POINTOPOINT
&&
2617 oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
2618 masklen2ip (oi
->address
->prefixlen
, &mask
);
2620 memset ((char *) &mask
, 0, sizeof (struct in_addr
));
2621 stream_put_ipv4 (s
, mask
.s_addr
);
2623 /* Set Hello Interval. */
2624 stream_putw (s
, OSPF_IF_PARAM (oi
, v_hello
));
2626 if (IS_DEBUG_OSPF_EVENT
)
2627 zlog_debug ("make_hello: options: %x, int: %s",
2628 OPTIONS(oi
), IF_NAME (oi
));
2631 stream_putc (s
, OPTIONS (oi
));
2633 /* Set Router Priority. */
2634 stream_putc (s
, PRIORITY (oi
));
2636 /* Set Router Dead Interval. */
2637 stream_putl (s
, OSPF_IF_PARAM (oi
, v_wait
));
2639 /* Set Designated Router. */
2640 stream_put_ipv4 (s
, DR (oi
).s_addr
);
2642 p
= stream_get_putp (s
);
2644 /* Set Backup Designated Router. */
2645 stream_put_ipv4 (s
, BDR (oi
).s_addr
);
2647 /* Add neighbor seen. */
2648 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
2649 if ((nbr
= rn
->info
))
2650 if (nbr
->router_id
.s_addr
!= 0) /* Ignore 0.0.0.0 node. */
2651 if (nbr
->state
!= NSM_Attempt
) /* Ignore Down neighbor. */
2652 if (nbr
->state
!= NSM_Down
) /* This is myself for DR election. */
2653 if (!IPV4_ADDR_SAME (&nbr
->router_id
, &oi
->ospf
->router_id
))
2655 /* Check neighbor is sane? */
2656 if (nbr
->d_router
.s_addr
!= 0
2657 && IPV4_ADDR_SAME (&nbr
->d_router
, &oi
->address
->u
.prefix4
)
2658 && IPV4_ADDR_SAME (&nbr
->bd_router
, &oi
->address
->u
.prefix4
))
2661 stream_put_ipv4 (s
, nbr
->router_id
.s_addr
);
2665 /* Let neighbor generate BackupSeen. */
2667 stream_putl_at (s
, p
, 0); /* ipv4 address, normally */
2673 ospf_make_db_desc (struct ospf_interface
*oi
, struct ospf_neighbor
*nbr
,
2676 struct ospf_lsa
*lsa
;
2677 u_int16_t length
= OSPF_DB_DESC_MIN_SIZE
;
2681 struct ospf_lsdb
*lsdb
;
2683 /* Set Interface MTU. */
2684 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
2687 stream_putw (s
, oi
->ifp
->mtu
);
2690 options
= OPTIONS (oi
);
2691 #ifdef HAVE_OPAQUE_LSA
2692 if (CHECK_FLAG (oi
->ospf
->config
, OSPF_OPAQUE_CAPABLE
))
2694 if (IS_SET_DD_I (nbr
->dd_flags
)
2695 || CHECK_FLAG (nbr
->options
, OSPF_OPTION_O
))
2697 * Set O-bit in the outgoing DD packet for capablity negotiation,
2698 * if one of following case is applicable.
2700 * 1) WaitTimer expiration event triggered the neighbor state to
2701 * change to Exstart, but no (valid) DD packet has received
2702 * from the neighbor yet.
2704 * 2) At least one DD packet with O-bit on has received from the
2707 SET_FLAG (options
, OSPF_OPTION_O
);
2709 #endif /* HAVE_OPAQUE_LSA */
2710 stream_putc (s
, options
);
2712 /* Keep pointer to flags. */
2713 pp
= stream_get_putp (s
);
2714 stream_putc (s
, nbr
->dd_flags
);
2716 /* Set DD Sequence Number. */
2717 stream_putl (s
, nbr
->dd_seqnum
);
2719 if (ospf_db_summary_isempty (nbr
))
2721 if (nbr
->state
>= NSM_Exchange
)
2723 nbr
->dd_flags
&= ~OSPF_DD_FLAG_M
;
2724 /* Set DD flags again */
2725 stream_putc_at (s
, pp
, nbr
->dd_flags
);
2730 /* Describe LSA Header from Database Summary List. */
2731 lsdb
= &nbr
->db_sum
;
2733 for (i
= OSPF_MIN_LSA
; i
< OSPF_MAX_LSA
; i
++)
2735 struct route_table
*table
= lsdb
->type
[i
].db
;
2736 struct route_node
*rn
;
2738 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
2739 if ((lsa
= rn
->info
) != NULL
)
2741 #ifdef HAVE_OPAQUE_LSA
2742 if (IS_OPAQUE_LSA (lsa
->data
->type
)
2743 && (! CHECK_FLAG (options
, OSPF_OPTION_O
)))
2745 /* Suppress advertising opaque-informations. */
2746 /* Remove LSA from DB summary list. */
2747 ospf_lsdb_delete (lsdb
, lsa
);
2750 #endif /* HAVE_OPAQUE_LSA */
2752 if (!CHECK_FLAG (lsa
->flags
, OSPF_LSA_DISCARD
))
2754 struct lsa_header
*lsah
;
2757 /* DD packet overflows interface MTU. */
2758 if (length
+ OSPF_LSA_HEADER_SIZE
> ospf_packet_max (oi
))
2761 /* Keep pointer to LS age. */
2762 lsah
= (struct lsa_header
*) (STREAM_DATA (s
) +
2763 stream_get_putp (s
));
2765 /* Proceed stream pointer. */
2766 stream_put (s
, lsa
->data
, OSPF_LSA_HEADER_SIZE
);
2767 length
+= OSPF_LSA_HEADER_SIZE
;
2770 ls_age
= LS_AGE (lsa
);
2771 lsah
->ls_age
= htons (ls_age
);
2775 /* Remove LSA from DB summary list. */
2776 ospf_lsdb_delete (lsdb
, lsa
);
2784 ospf_make_ls_req_func (struct stream
*s
, u_int16_t
*length
,
2785 unsigned long delta
, struct ospf_neighbor
*nbr
,
2786 struct ospf_lsa
*lsa
)
2788 struct ospf_interface
*oi
;
2792 /* LS Request packet overflows interface MTU. */
2793 if (*length
+ delta
> ospf_packet_max(oi
))
2796 stream_putl (s
, lsa
->data
->type
);
2797 stream_put_ipv4 (s
, lsa
->data
->id
.s_addr
);
2798 stream_put_ipv4 (s
, lsa
->data
->adv_router
.s_addr
);
2800 ospf_lsa_unlock (nbr
->ls_req_last
);
2801 nbr
->ls_req_last
= ospf_lsa_lock (lsa
);
2808 ospf_make_ls_req (struct ospf_neighbor
*nbr
, struct stream
*s
)
2810 struct ospf_lsa
*lsa
;
2811 u_int16_t length
= OSPF_LS_REQ_MIN_SIZE
;
2812 unsigned long delta
= stream_get_putp(s
)+12;
2813 struct route_table
*table
;
2814 struct route_node
*rn
;
2816 struct ospf_lsdb
*lsdb
;
2818 lsdb
= &nbr
->ls_req
;
2820 for (i
= OSPF_MIN_LSA
; i
< OSPF_MAX_LSA
; i
++)
2822 table
= lsdb
->type
[i
].db
;
2823 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
2824 if ((lsa
= (rn
->info
)) != NULL
)
2825 if (ospf_make_ls_req_func (s
, &length
, delta
, nbr
, lsa
) == 0)
2827 route_unlock_node (rn
);
2835 ls_age_increment (struct ospf_lsa
*lsa
, int delay
)
2839 age
= IS_LSA_MAXAGE (lsa
) ? OSPF_LSA_MAXAGE
: LS_AGE (lsa
) + delay
;
2841 return (age
> OSPF_LSA_MAXAGE
? OSPF_LSA_MAXAGE
: age
);
2845 ospf_make_ls_upd (struct ospf_interface
*oi
, struct list
*update
, struct stream
*s
)
2847 struct ospf_lsa
*lsa
;
2848 struct listnode
*node
;
2849 u_int16_t length
= OSPF_LS_UPD_MIN_SIZE
;
2850 unsigned int size_noauth
;
2851 unsigned long delta
= stream_get_putp (s
);
2855 if (IS_DEBUG_OSPF_EVENT
)
2856 zlog_debug ("ospf_make_ls_upd: Start");
2858 pp
= stream_get_putp (s
);
2859 ospf_output_forward (s
, OSPF_LS_UPD_MIN_SIZE
);
2861 /* Calculate amount of packet usable for data. */
2862 size_noauth
= stream_get_size(s
) - ospf_packet_authspace(oi
);
2864 while ((node
= listhead (update
)) != NULL
)
2866 struct lsa_header
*lsah
;
2869 if (IS_DEBUG_OSPF_EVENT
)
2870 zlog_debug ("ospf_make_ls_upd: List Iteration");
2872 lsa
= getdata (node
);
2877 if (length
+ delta
+ ntohs (lsa
->data
->length
) > size_noauth
)
2880 /* Keep pointer to LS age. */
2881 lsah
= (struct lsa_header
*) (STREAM_DATA (s
) + stream_get_putp (s
));
2883 /* Put LSA to Link State Request. */
2884 stream_put (s
, lsa
->data
, ntohs (lsa
->data
->length
));
2887 /* each hop must increment an lsa_age by transmit_delay
2888 of OSPF interface */
2889 ls_age
= ls_age_increment (lsa
, OSPF_IF_PARAM (oi
, transmit_delay
));
2890 lsah
->ls_age
= htons (ls_age
);
2892 length
+= ntohs (lsa
->data
->length
);
2895 list_delete_node (update
, node
);
2896 ospf_lsa_unlock (lsa
);
2899 /* Now set #LSAs. */
2900 stream_putl_at (s
, pp
, count
);
2902 if (IS_DEBUG_OSPF_EVENT
)
2903 zlog_debug ("ospf_make_ls_upd: Stop");
2908 ospf_make_ls_ack (struct ospf_interface
*oi
, struct list
*ack
, struct stream
*s
)
2910 struct list
*rm_list
;
2911 struct listnode
*node
;
2912 u_int16_t length
= OSPF_LS_ACK_MIN_SIZE
;
2913 unsigned long delta
= stream_get_putp(s
) + 24;
2914 struct ospf_lsa
*lsa
;
2916 rm_list
= list_new ();
2918 for (node
= listhead (ack
); node
; nextnode (node
))
2920 lsa
= getdata (node
);
2923 if (length
+ delta
> ospf_packet_max (oi
))
2926 stream_put (s
, lsa
->data
, OSPF_LSA_HEADER_SIZE
);
2927 length
+= OSPF_LSA_HEADER_SIZE
;
2929 listnode_add (rm_list
, lsa
);
2932 /* Remove LSA from LS-Ack list. */
2933 for (node
= listhead (rm_list
); node
; nextnode (node
))
2935 lsa
= (struct ospf_lsa
*) getdata (node
);
2937 listnode_delete (ack
, lsa
);
2938 ospf_lsa_unlock (lsa
);
2941 list_delete (rm_list
);
2947 ospf_hello_send_sub (struct ospf_interface
*oi
, struct in_addr
*addr
)
2949 struct ospf_packet
*op
;
2950 u_int16_t length
= OSPF_HEADER_SIZE
;
2952 op
= ospf_packet_new (oi
->ifp
->mtu
);
2954 /* Prepare OSPF common header. */
2955 ospf_make_header (OSPF_MSG_HELLO
, oi
, op
->s
);
2957 /* Prepare OSPF Hello body. */
2958 length
+= ospf_make_hello (oi
, op
->s
);
2960 /* Fill OSPF header. */
2961 ospf_fill_header (oi
, op
->s
, length
);
2963 /* Set packet length. */
2964 op
->length
= length
;
2966 op
->dst
.s_addr
= addr
->s_addr
;
2968 /* Add packet to the interface output queue. */
2969 ospf_packet_add (oi
, op
);
2971 /* Hook thread to write packet. */
2972 OSPF_ISM_WRITE_ON (oi
->ospf
);
2976 ospf_poll_send (struct ospf_nbr_nbma
*nbr_nbma
)
2978 struct ospf_interface
*oi
;
2983 /* If this is passive interface, do not send OSPF Hello. */
2984 if (OSPF_IF_PARAM (oi
, passive_interface
) == OSPF_IF_PASSIVE
)
2987 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
2990 if (nbr_nbma
->nbr
!= NULL
&& nbr_nbma
->nbr
->state
!= NSM_Down
)
2993 if (PRIORITY(oi
) == 0)
2996 if (nbr_nbma
->priority
== 0
2997 && oi
->state
!= ISM_DR
&& oi
->state
!= ISM_Backup
)
3000 ospf_hello_send_sub (oi
, &nbr_nbma
->addr
);
3004 ospf_poll_timer (struct thread
*thread
)
3006 struct ospf_nbr_nbma
*nbr_nbma
;
3008 nbr_nbma
= THREAD_ARG (thread
);
3009 nbr_nbma
->t_poll
= NULL
;
3011 if (IS_DEBUG_OSPF (nsm
, NSM_TIMERS
))
3012 zlog (NULL
, LOG_DEBUG
, "NSM[%s:%s]: Timer (Poll timer expire)",
3013 IF_NAME (nbr_nbma
->oi
), inet_ntoa (nbr_nbma
->addr
));
3015 ospf_poll_send (nbr_nbma
);
3017 if (nbr_nbma
->v_poll
> 0)
3018 OSPF_POLL_TIMER_ON (nbr_nbma
->t_poll
, ospf_poll_timer
,
3026 ospf_hello_reply_timer (struct thread
*thread
)
3028 struct ospf_neighbor
*nbr
;
3030 nbr
= THREAD_ARG (thread
);
3031 nbr
->t_hello_reply
= NULL
;
3035 if (IS_DEBUG_OSPF (nsm
, NSM_TIMERS
))
3036 zlog (NULL
, LOG_DEBUG
, "NSM[%s:%s]: Timer (hello-reply timer expire)",
3037 IF_NAME (nbr
->oi
), inet_ntoa (nbr
->router_id
));
3039 ospf_hello_send_sub (nbr
->oi
, &nbr
->address
.u
.prefix4
);
3044 /* Send OSPF Hello. */
3046 ospf_hello_send (struct ospf_interface
*oi
)
3048 struct ospf_packet
*op
;
3049 u_int16_t length
= OSPF_HEADER_SIZE
;
3051 /* If this is passive interface, do not send OSPF Hello. */
3052 if (OSPF_IF_PARAM (oi
, passive_interface
) == OSPF_IF_PASSIVE
)
3055 op
= ospf_packet_new (oi
->ifp
->mtu
);
3057 /* Prepare OSPF common header. */
3058 ospf_make_header (OSPF_MSG_HELLO
, oi
, op
->s
);
3060 /* Prepare OSPF Hello body. */
3061 length
+= ospf_make_hello (oi
, op
->s
);
3063 /* Fill OSPF header. */
3064 ospf_fill_header (oi
, op
->s
, length
);
3066 /* Set packet length. */
3067 op
->length
= length
;
3069 if (oi
->type
== OSPF_IFTYPE_NBMA
)
3071 struct ospf_neighbor
*nbr
;
3072 struct route_node
*rn
;
3074 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
3075 if ((nbr
= rn
->info
))
3076 if (nbr
!= oi
->nbr_self
)
3077 if (nbr
->state
!= NSM_Down
)
3079 /* RFC 2328 Section 9.5.1
3080 If the router is not eligible to become Designated Router,
3081 it must periodically send Hello Packets to both the
3082 Designated Router and the Backup Designated Router (if they
3084 if (PRIORITY(oi
) == 0 &&
3085 IPV4_ADDR_CMP(&DR(oi
), &nbr
->address
.u
.prefix4
) &&
3086 IPV4_ADDR_CMP(&BDR(oi
), &nbr
->address
.u
.prefix4
))
3089 /* If the router is eligible to become Designated Router, it
3090 must periodically send Hello Packets to all neighbors that
3091 are also eligible. In addition, if the router is itself the
3092 Designated Router or Backup Designated Router, it must also
3093 send periodic Hello Packets to all other neighbors. */
3095 if (nbr
->priority
== 0 && oi
->state
== ISM_DROther
)
3097 /* if oi->state == Waiting, send hello to all neighbors */
3099 struct ospf_packet
*op_dup
;
3101 op_dup
= ospf_packet_dup(op
);
3102 op_dup
->dst
= nbr
->address
.u
.prefix4
;
3104 /* Add packet to the interface output queue. */
3105 ospf_packet_add (oi
, op_dup
);
3107 OSPF_ISM_WRITE_ON (oi
->ospf
);
3111 ospf_packet_free (op
);
3115 /* Decide destination address. */
3116 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3117 op
->dst
.s_addr
= oi
->vl_data
->peer_addr
.s_addr
;
3119 op
->dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3121 /* Add packet to the interface output queue. */
3122 ospf_packet_add (oi
, op
);
3124 /* Hook thread to write packet. */
3125 OSPF_ISM_WRITE_ON (oi
->ospf
);
3129 /* Send OSPF Database Description. */
3131 ospf_db_desc_send (struct ospf_neighbor
*nbr
)
3133 struct ospf_interface
*oi
;
3134 struct ospf_packet
*op
;
3135 u_int16_t length
= OSPF_HEADER_SIZE
;
3138 op
= ospf_packet_new (oi
->ifp
->mtu
);
3140 /* Prepare OSPF common header. */
3141 ospf_make_header (OSPF_MSG_DB_DESC
, oi
, op
->s
);
3143 /* Prepare OSPF Database Description body. */
3144 length
+= ospf_make_db_desc (oi
, nbr
, op
->s
);
3146 /* Fill OSPF header. */
3147 ospf_fill_header (oi
, op
->s
, length
);
3149 /* Set packet length. */
3150 op
->length
= length
;
3152 /* Decide destination address. */
3153 op
->dst
= nbr
->address
.u
.prefix4
;
3155 /* Add packet to the interface output queue. */
3156 ospf_packet_add (oi
, op
);
3158 /* Hook thread to write packet. */
3159 OSPF_ISM_WRITE_ON (oi
->ospf
);
3161 /* Remove old DD packet, then copy new one and keep in neighbor structure. */
3163 ospf_packet_free (nbr
->last_send
);
3164 nbr
->last_send
= ospf_packet_dup (op
);
3165 gettimeofday (&nbr
->last_send_ts
, NULL
);
3168 /* Re-send Database Description. */
3170 ospf_db_desc_resend (struct ospf_neighbor
*nbr
)
3172 struct ospf_interface
*oi
;
3176 /* Add packet to the interface output queue. */
3177 ospf_packet_add (oi
, ospf_packet_dup (nbr
->last_send
));
3179 /* Hook thread to write packet. */
3180 OSPF_ISM_WRITE_ON (oi
->ospf
);
3183 /* Send Link State Request. */
3185 ospf_ls_req_send (struct ospf_neighbor
*nbr
)
3187 struct ospf_interface
*oi
;
3188 struct ospf_packet
*op
;
3189 u_int16_t length
= OSPF_HEADER_SIZE
;
3192 op
= ospf_packet_new (oi
->ifp
->mtu
);
3194 /* Prepare OSPF common header. */
3195 ospf_make_header (OSPF_MSG_LS_REQ
, oi
, op
->s
);
3197 /* Prepare OSPF Link State Request body. */
3198 length
+= ospf_make_ls_req (nbr
, op
->s
);
3199 if (length
== OSPF_HEADER_SIZE
)
3201 ospf_packet_free (op
);
3205 /* Fill OSPF header. */
3206 ospf_fill_header (oi
, op
->s
, length
);
3208 /* Set packet length. */
3209 op
->length
= length
;
3211 /* Decide destination address. */
3212 op
->dst
= nbr
->address
.u
.prefix4
;
3214 /* Add packet to the interface output queue. */
3215 ospf_packet_add (oi
, op
);
3217 /* Hook thread to write packet. */
3218 OSPF_ISM_WRITE_ON (oi
->ospf
);
3220 /* Add Link State Request Retransmission Timer. */
3221 OSPF_NSM_TIMER_ON (nbr
->t_ls_req
, ospf_ls_req_timer
, nbr
->v_ls_req
);
3224 /* Send Link State Update with an LSA. */
3226 ospf_ls_upd_send_lsa (struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
,
3229 struct list
*update
;
3231 update
= list_new ();
3233 listnode_add (update
, lsa
);
3234 ospf_ls_upd_send (nbr
, update
, flag
);
3236 list_delete (update
);
3239 /* Determine size for packet. Must be at least big enough to accomodate next
3240 * LSA on list, which may be bigger than MTU size.
3242 * Return pointer to new ospf_packet
3243 * NULL if we can not allocate, eg because LSA is bigger than imposed limit
3244 * on packet sizes (in which case offending LSA is deleted from update list)
3246 static struct ospf_packet
*
3247 ospf_ls_upd_packet_new (struct list
*update
, struct ospf_interface
*oi
)
3249 struct ospf_lsa
*lsa
;
3250 struct listnode
*ln
;
3252 static char warned
= 0;
3254 ln
= listhead (update
);
3259 if ((OSPF_LS_UPD_MIN_SIZE
+ ntohs (lsa
->data
->length
))
3260 > ospf_packet_max (oi
))
3264 zlog_warn ("ospf_ls_upd_packet_new: oversized LSA encountered!"
3265 "will need to fragment. Not optimal. Try divide up"
3266 " your network with areas. Use 'debug ospf packet send'"
3267 " to see details, or look at 'show ip ospf database ..'");
3271 if (IS_DEBUG_OSPF_PACKET (0, SEND
))
3272 zlog_debug ("ospf_ls_upd_packet_new: oversized LSA id:%s,"
3273 " %d bytes originated by %s, will be fragmented!",
3274 inet_ntoa (lsa
->data
->id
),
3275 ntohs (lsa
->data
->length
),
3276 inet_ntoa (lsa
->data
->adv_router
));
3279 * Allocate just enough to fit this LSA only, to avoid including other
3280 * LSAs in fragmented LSA Updates.
3282 size
= ntohs (lsa
->data
->length
) + (oi
->ifp
->mtu
- ospf_packet_max (oi
))
3283 + OSPF_LS_UPD_MIN_SIZE
;
3286 size
= oi
->ifp
->mtu
;
3288 /* XXX Should this be - sizeof(struct ip)?? -gdt */
3289 if (size
> OSPF_MAX_PACKET_SIZE
)
3291 zlog_warn ("ospf_ls_upd_packet_new: oversized LSA id:%s too big,"
3292 " %d bytes, packet size %ld, dropping it completely."
3293 " OSPF routing is broken!",
3294 inet_ntoa (lsa
->data
->id
), ntohs (lsa
->data
->length
),
3296 list_delete_node (update
, ln
);
3300 return ospf_packet_new (size
);
3304 ospf_ls_upd_queue_send (struct ospf_interface
*oi
, struct list
*update
,
3305 struct in_addr addr
)
3307 struct ospf_packet
*op
;
3308 u_int16_t length
= OSPF_HEADER_SIZE
;
3310 if (IS_DEBUG_OSPF_EVENT
)
3311 zlog_debug ("listcount = %d, dst %s", listcount (update
), inet_ntoa(addr
));
3313 op
= ospf_ls_upd_packet_new (update
, oi
);
3315 /* Prepare OSPF common header. */
3316 ospf_make_header (OSPF_MSG_LS_UPD
, oi
, op
->s
);
3318 /* Prepare OSPF Link State Update body.
3319 * Includes Type-7 translation.
3321 length
+= ospf_make_ls_upd (oi
, update
, op
->s
);
3323 /* Fill OSPF header. */
3324 ospf_fill_header (oi
, op
->s
, length
);
3326 /* Set packet length. */
3327 op
->length
= length
;
3329 /* Decide destination address. */
3330 op
->dst
.s_addr
= addr
.s_addr
;
3332 /* Add packet to the interface output queue. */
3333 ospf_packet_add (oi
, op
);
3335 /* Hook thread to write packet. */
3336 OSPF_ISM_WRITE_ON (oi
->ospf
);
3340 ospf_ls_upd_send_queue_event (struct thread
*thread
)
3342 struct ospf_interface
*oi
= THREAD_ARG(thread
);
3343 struct route_node
*rn
;
3344 struct route_node
*rnext
;
3345 struct list
*update
;
3348 oi
->t_ls_upd_event
= NULL
;
3350 if (IS_DEBUG_OSPF_EVENT
)
3351 zlog_debug ("ospf_ls_upd_send_queue start");
3353 for (rn
= route_top (oi
->ls_upd_queue
); rn
; rn
= rnext
)
3355 rnext
= route_next (rn
);
3357 if (rn
->info
== NULL
)
3360 update
= (struct list
*)rn
->info
;
3362 ospf_ls_upd_queue_send (oi
, update
, rn
->p
.u
.prefix4
);
3364 /* list might not be empty. */
3365 if (listcount(update
) == 0)
3367 list_delete (rn
->info
);
3369 route_unlock_node (rn
);
3377 if (IS_DEBUG_OSPF_EVENT
)
3378 zlog_debug ("ospf_ls_upd_send_queue: update lists not cleared,"
3379 " %d nodes to try again, raising new event", again
);
3380 oi
->t_ls_upd_event
=
3381 thread_add_event (master
, ospf_ls_upd_send_queue_event
, oi
, 0);
3384 if (IS_DEBUG_OSPF_EVENT
)
3385 zlog_debug ("ospf_ls_upd_send_queue stop");
3391 ospf_ls_upd_send (struct ospf_neighbor
*nbr
, struct list
*update
, int flag
)
3393 struct ospf_interface
*oi
;
3394 struct prefix_ipv4 p
;
3395 struct route_node
*rn
;
3401 p
.prefixlen
= IPV4_MAX_BITLEN
;
3403 /* Decide destination address. */
3404 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3405 p
.prefix
= oi
->vl_data
->peer_addr
;
3406 else if (flag
== OSPF_SEND_PACKET_DIRECT
)
3407 p
.prefix
= nbr
->address
.u
.prefix4
;
3408 else if (oi
->state
== ISM_DR
|| oi
->state
== ISM_Backup
)
3409 p
.prefix
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3410 else if ((oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
3411 && (flag
== OSPF_SEND_PACKET_INDIRECT
))
3412 p
.prefix
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3413 else if (oi
->type
== OSPF_IFTYPE_POINTOMULTIPOINT
)
3414 p
.prefix
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3416 p
.prefix
.s_addr
= htonl (OSPF_ALLDROUTERS
);
3418 if (oi
->type
== OSPF_IFTYPE_NBMA
)
3420 if (flag
== OSPF_SEND_PACKET_INDIRECT
)
3421 zlog_warn ("* LS-Update is directly sent on NBMA network.");
3422 if (IPV4_ADDR_SAME(&oi
->address
->u
.prefix4
, &p
.prefix
.s_addr
))
3423 zlog_warn ("* LS-Update is sent to myself.");
3426 rn
= route_node_get (oi
->ls_upd_queue
, (struct prefix
*) &p
);
3428 if (rn
->info
== NULL
)
3429 rn
->info
= list_new ();
3431 for (n
= listhead (update
); n
; nextnode (n
))
3432 listnode_add (rn
->info
, ospf_lsa_lock (getdata (n
)));
3434 if (oi
->t_ls_upd_event
== NULL
)
3435 oi
->t_ls_upd_event
=
3436 thread_add_event (master
, ospf_ls_upd_send_queue_event
, oi
, 0);
3440 ospf_ls_ack_send_list (struct ospf_interface
*oi
, struct list
*ack
,
3443 struct ospf_packet
*op
;
3444 u_int16_t length
= OSPF_HEADER_SIZE
;
3446 op
= ospf_packet_new (oi
->ifp
->mtu
);
3448 /* Prepare OSPF common header. */
3449 ospf_make_header (OSPF_MSG_LS_ACK
, oi
, op
->s
);
3451 /* Prepare OSPF Link State Acknowledgment body. */
3452 length
+= ospf_make_ls_ack (oi
, ack
, op
->s
);
3454 /* Fill OSPF header. */
3455 ospf_fill_header (oi
, op
->s
, length
);
3457 /* Set packet length. */
3458 op
->length
= length
;
3460 /* Set destination IP address. */
3463 /* Add packet to the interface output queue. */
3464 ospf_packet_add (oi
, op
);
3466 /* Hook thread to write packet. */
3467 OSPF_ISM_WRITE_ON (oi
->ospf
);
3471 ospf_ls_ack_send_event (struct thread
*thread
)
3473 struct ospf_interface
*oi
= THREAD_ARG (thread
);
3475 oi
->t_ls_ack_direct
= NULL
;
3477 while (listcount (oi
->ls_ack_direct
.ls_ack
))
3478 ospf_ls_ack_send_list (oi
, oi
->ls_ack_direct
.ls_ack
,
3479 oi
->ls_ack_direct
.dst
);
3485 ospf_ls_ack_send (struct ospf_neighbor
*nbr
, struct ospf_lsa
*lsa
)
3487 struct ospf_interface
*oi
= nbr
->oi
;
3489 if (listcount (oi
->ls_ack_direct
.ls_ack
) == 0)
3490 oi
->ls_ack_direct
.dst
= nbr
->address
.u
.prefix4
;
3492 listnode_add (oi
->ls_ack_direct
.ls_ack
, ospf_lsa_lock (lsa
));
3494 if (oi
->t_ls_ack_direct
== NULL
)
3495 oi
->t_ls_ack_direct
=
3496 thread_add_event (master
, ospf_ls_ack_send_event
, oi
, 0);
3499 /* Send Link State Acknowledgment delayed. */
3501 ospf_ls_ack_send_delayed (struct ospf_interface
*oi
)
3505 /* Decide destination address. */
3506 /* RFC2328 Section 13.5 On non-broadcast
3507 networks, delayed Link State Acknowledgment packets must be
3508 unicast separately over each adjacency (i.e., neighbor whose
3509 state is >= Exchange). */
3510 if (oi
->type
== OSPF_IFTYPE_NBMA
)
3512 struct ospf_neighbor
*nbr
;
3513 struct route_node
*rn
;
3515 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
3516 if ((nbr
= rn
->info
) != NULL
)
3517 if (nbr
!= oi
->nbr_self
&& nbr
->state
>= NSM_Exchange
)
3518 while (listcount (oi
->ls_ack
))
3519 ospf_ls_ack_send_list (oi
, oi
->ls_ack
, nbr
->address
.u
.prefix4
);
3522 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
3523 dst
.s_addr
= oi
->vl_data
->peer_addr
.s_addr
;
3524 else if (oi
->state
== ISM_DR
|| oi
->state
== ISM_Backup
)
3525 dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3526 else if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
3527 dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3528 else if (oi
->type
== OSPF_IFTYPE_POINTOMULTIPOINT
)
3529 dst
.s_addr
= htonl (OSPF_ALLSPFROUTERS
);
3531 dst
.s_addr
= htonl (OSPF_ALLDROUTERS
);
3533 while (listcount (oi
->ls_ack
))
3534 ospf_ls_ack_send_list (oi
, oi
->ls_ack
, dst
);