]>
git.ipfire.org Git - thirdparty/bird.git/blob - proto/ospf/iface.c
4 * (c) 1999--2005 Ondrej Filip <feela@network.cz>
5 * (c) 2009--2014 Ondrej Zajicek <santiago@crfreenet.org>
6 * (c) 2009--2014 CZ.NIC z.s.p.o.
8 * Can be freely distributed and used under the terms of the GNU GPL.
14 const char *ospf_is_names
[] = {
15 "Down", "Loopback", "Waiting", "PtP", "DROther", "Backup", "DR"
18 const char *ospf_ism_names
[] = {
19 "InterfaceUp", "WaitTimer", "BackupSeen", "NeighborChange",
20 "LoopInd", "UnloopInd", "InterfaceDown"
23 const char *ospf_it
[] = { "broadcast", "nbma", "ptp", "ptmp", "virtual link" };
27 poll_timer_hook(timer
* timer
)
29 ospf_send_hello(timer
->data
, OHS_POLL
, NULL
);
33 hello_timer_hook(timer
* timer
)
35 ospf_send_hello(timer
->data
, OHS_HELLO
, NULL
);
39 wait_timer_hook(timer
* timer
)
41 struct ospf_iface
*ifa
= (struct ospf_iface
*) timer
->data
;
42 struct ospf_proto
*p
= ifa
->oa
->po
;
44 OSPF_TRACE(D_EVENTS
, "Wait timer fired on %s", ifa
->ifname
);
45 ospf_iface_sm(ifa
, ISM_WAITF
);
49 ifa_tx_length(struct ospf_iface
*ifa
)
51 return ifa
->cf
->tx_length
?: ifa
->iface
->mtu
;
55 ifa_bufsize(struct ospf_iface
*ifa
)
57 uint bsize
= ifa
->cf
->rx_buffer
?: ifa
->iface
->mtu
;
58 return MAX(bsize
, ifa
->tx_length
);
62 ifa_flood_queue_size(struct ospf_iface
*ifa
)
64 return ifa
->tx_length
/ 24;
68 ospf_iface_assure_bufsize(struct ospf_iface
*ifa
, uint plen
)
70 plen
+= SIZE_OF_IP_HEADER
;
72 /* This is relevant just for OSPFv2 */
73 if (ifa
->autype
== OSPF_AUTH_CRYPT
)
74 plen
+= OSPF_AUTH_CRYPT_SIZE
;
76 if (plen
<= ifa
->sk
->tbsize
)
79 if (ifa
->cf
->rx_buffer
|| (plen
> 0xffff))
82 plen
= BIRD_ALIGN(plen
, 1024);
83 plen
= MIN(plen
, 0xffff);
84 sk_set_tbsize(ifa
->sk
, plen
);
90 find_nbma_node_(list
*nnl
, ip_addr ip
)
95 if (ipa_equal(nn
->ip
, ip
))
103 ospf_sk_open(struct ospf_iface
*ifa
)
105 struct ospf_proto
*p
= ifa
->oa
->po
;
107 sock
*sk
= sk_new(ifa
->pool
);
109 sk
->dport
= OSPF_PROTO
;
110 sk
->saddr
= ifa
->addr
->ip
;
111 sk
->iface
= ifa
->iface
;
113 sk
->tos
= ifa
->cf
->tx_tos
;
114 sk
->priority
= ifa
->cf
->tx_priority
;
115 sk
->rx_hook
= ospf_rx_hook
;
116 // sk->tx_hook = ospf_tx_hook;
117 sk
->err_hook
= ospf_err_hook
;
118 sk
->rbsize
= sk
->tbsize
= ifa_bufsize(ifa
);
119 sk
->data
= (void *) ifa
;
120 sk
->flags
= SKF_LADDR_RX
| (ifa
->check_ttl
? SKF_TTL_RX
: 0);
121 sk
->ttl
= ifa
->cf
->ttl_security
? 255 : 1;
126 /* 12 is an offset of the checksum in an OSPFv3 packet */
128 if (sk_set_ipv6_checksum(sk
, 12) < 0)
131 if ((ifa
->type
== OSPF_IT_BCAST
) || (ifa
->type
== OSPF_IT_PTP
))
133 if (ifa
->cf
->real_bcast
)
135 ifa
->all_routers
= ifa
->addr
->brd
;
136 ifa
->des_routers
= IPA_NONE
;
138 if (sk_setup_broadcast(sk
) < 0)
143 ifa
->all_routers
= ospf_is_v2(p
) ? IP4_OSPF_ALL_ROUTERS
: IP6_OSPF_ALL_ROUTERS
;
144 ifa
->des_routers
= ospf_is_v2(p
) ? IP4_OSPF_DES_ROUTERS
: IP6_OSPF_DES_ROUTERS
;
146 if (sk_setup_multicast(sk
) < 0)
149 if (sk_join_group(sk
, ifa
->all_routers
) < 0)
159 sk_log_error(sk
, p
->p
.name
);
165 ospf_sk_join_dr(struct ospf_iface
*ifa
)
170 if (sk_join_group(ifa
->sk
, ifa
->des_routers
) < 0)
171 sk_log_error(ifa
->sk
, ifa
->oa
->po
->p
.name
);
177 ospf_sk_leave_dr(struct ospf_iface
*ifa
)
182 if (sk_leave_group(ifa
->sk
, ifa
->des_routers
) < 0)
183 sk_log_error(ifa
->sk
, ifa
->oa
->po
->p
.name
);
189 ospf_open_vlink_sk(struct ospf_proto
*p
)
191 sock
*sk
= sk_new(p
->p
.pool
);
193 sk
->dport
= OSPF_PROTO
;
195 /* FIXME: configurable tos/priority ? */
196 sk
->tos
= IP_PREC_INTERNET_CONTROL
;
197 sk
->priority
= sk_priority_control
;
198 sk
->err_hook
= ospf_verr_hook
;
201 sk
->tbsize
= ospf_is_v2(p
) ? IP4_MIN_MTU
: IP6_MIN_MTU
;
202 sk
->data
= (void *) p
;
208 /* 12 is an offset of the checksum in an OSPFv3 packet */
210 if (sk_set_ipv6_checksum(sk
, 12) < 0)
217 sk_log_error(sk
, p
->p
.name
);
218 log(L_ERR
"%s: Cannot open virtual link socket", p
->p
.name
);
223 ospf_iface_down(struct ospf_iface
*ifa
)
225 struct ospf_proto
*p
= ifa
->oa
->po
;
226 struct ospf_neighbor
*n
, *nx
;
227 struct ospf_iface
*iff
;
229 if (ifa
->type
!= OSPF_IT_VLINK
)
231 if (ospf_is_v3(ifa
->oa
->po
))
232 OSPF_TRACE(D_EVENTS
, "Removing interface %s (IID %d) from area %R",
233 ifa
->ifname
, ifa
->instance_id
, ifa
->oa
->areaid
);
234 else if (ifa
->addr
->flags
& IA_PEER
)
235 OSPF_TRACE(D_EVENTS
, "Removing interface %s (peer %I) from area %R",
236 ifa
->ifname
, ifa
->addr
->opposite
, ifa
->oa
->areaid
);
238 OSPF_TRACE(D_EVENTS
, "Removing interface %s (%I/%d) from area %R",
239 ifa
->ifname
, ifa
->addr
->prefix
, ifa
->addr
->pxlen
, ifa
->oa
->areaid
);
241 /* First of all kill all the related vlinks */
242 WALK_LIST(iff
, p
->iface_list
)
244 if ((iff
->type
== OSPF_IT_VLINK
) && (iff
->vifa
== ifa
))
245 ospf_iface_sm(iff
, ISM_DOWN
);
249 WALK_LIST_DELSAFE(n
, nx
, ifa
->neigh_list
)
250 ospf_neigh_sm(n
, INM_KILLNBR
);
252 if (ifa
->hello_timer
)
253 tm_stop(ifa
->hello_timer
);
256 tm_stop(ifa
->poll_timer
);
259 tm_stop(ifa
->wait_timer
);
261 ospf_flush2_lsa(p
, &ifa
->link_lsa
);
262 ospf_flush2_lsa(p
, &ifa
->net_lsa
);
263 ospf_flush2_lsa(p
, &ifa
->pxn_lsa
);
265 if (ifa
->type
== OSPF_IT_VLINK
)
281 ospf_iface_remove(struct ospf_iface
*ifa
)
283 struct ospf_proto
*p
= ifa
->oa
->po
;
286 if (ifa
->type
== OSPF_IT_VLINK
)
287 OSPF_TRACE(D_EVENTS
, "Removing vlink to %R via area %R", ifa
->vid
, ifa
->voa
->areaid
);
289 /* Release LSAs from flood queue */
291 for (i
= 0; i
< ifa
->flood_queue_used
; i
++)
292 ifa
->flood_queue
[i
]->ret_count
--;
294 ospf_iface_sm(ifa
, ISM_DOWN
);
300 ospf_iface_shutdown(struct ospf_iface
*ifa
)
302 if (ifa
->state
> OSPF_IS_DOWN
)
303 ospf_send_hello(ifa
, OHS_SHUTDOWN
, NULL
);
307 * ospf_iface_chstate - handle changes of interface state
308 * @ifa: OSPF interface
311 * Many actions must be taken according to interface state changes. New network
312 * LSAs must be originated, flushed, new multicast sockets to listen for messages for
313 * %ALLDROUTERS have to be opened, etc.
316 ospf_iface_chstate(struct ospf_iface
*ifa
, u8 state
)
318 struct ospf_proto
*p
= ifa
->oa
->po
;
319 u8 oldstate
= ifa
->state
;
321 if (state
== oldstate
)
324 OSPF_TRACE(D_EVENTS
, "Interface %s changed state from %s to %s",
325 ifa
->ifname
, ospf_is_names
[oldstate
], ospf_is_names
[state
]);
329 if ((ifa
->type
== OSPF_IT_BCAST
) && ipa_nonzero(ifa
->des_routers
) && ifa
->sk
)
331 if ((state
== OSPF_IS_BACKUP
) || (state
== OSPF_IS_DR
))
332 ospf_sk_join_dr(ifa
);
334 ospf_sk_leave_dr(ifa
);
337 if ((oldstate
> OSPF_IS_LOOP
) && (state
<= OSPF_IS_LOOP
))
338 ospf_iface_down(ifa
);
340 /* RFC 2328 12.4 Event 2 - iface state change */
341 ospf_notify_rt_lsa(ifa
->oa
);
343 /* RFC 5340 4.4.3 Event 1 - iface state change */
344 ospf_notify_link_lsa(ifa
);
346 /* RFC 2328 12.4 Event 3 - iface enters/leaves DR state */
347 ospf_notify_net_lsa(ifa
);
351 * ospf_iface_sm - OSPF interface state machine
352 * @ifa: OSPF interface
353 * @event: event comming to state machine
355 * This fully respects 9.3 of RFC 2328 except we have slightly
356 * different handling of %DOWN and %LOOP state. We remove intefaces
357 * that are %DOWN. %DOWN state is used when an interface is waiting
358 * for a lock. %LOOP state is used when an interface does not have a
362 ospf_iface_sm(struct ospf_iface
*ifa
, int event
)
364 DBG("SM on %s. Event is '%s'\n", ifa
->ifname
, ospf_ism_names
[event
]);
369 if (ifa
->state
<= OSPF_IS_LOOP
)
371 /* Now, nothing should be adjacent */
372 if ((ifa
->type
== OSPF_IT_PTP
) ||
373 (ifa
->type
== OSPF_IT_PTMP
) ||
374 (ifa
->type
== OSPF_IT_VLINK
))
376 ospf_iface_chstate(ifa
, OSPF_IS_PTP
);
380 if (ifa
->priority
== 0)
381 ospf_iface_chstate(ifa
, OSPF_IS_DROTHER
);
384 ospf_iface_chstate(ifa
, OSPF_IS_WAITING
);
386 tm_start(ifa
->wait_timer
, ifa
->waitint
);
390 if (ifa
->hello_timer
)
391 tm_start(ifa
->hello_timer
, ifa
->helloint
);
394 tm_start(ifa
->poll_timer
, ifa
->pollint
);
396 ospf_send_hello(ifa
, OHS_HELLO
, NULL
);
402 if (ifa
->state
== OSPF_IS_WAITING
)
403 ospf_dr_election(ifa
);
407 if (ifa
->state
>= OSPF_IS_DROTHER
)
408 ospf_dr_election(ifa
);
412 if ((ifa
->state
> OSPF_IS_LOOP
) && ifa
->check_link
)
413 ospf_iface_chstate(ifa
, OSPF_IS_LOOP
);
417 /* Immediate go UP */
418 if (ifa
->state
== OSPF_IS_LOOP
)
419 ospf_iface_sm(ifa
, ISM_UP
);
423 ospf_iface_chstate(ifa
, OSPF_IS_DOWN
);
427 bug("OSPF_I_SM - Unknown event?");
434 ospf_iface_classify_(struct iface
*ifa
, struct ifa
*addr
)
436 if (ipa_nonzero(addr
->opposite
))
437 return (ifa
->flags
& IF_MULTICAST
) ? OSPF_IT_PTP
: OSPF_IT_PTMP
;
439 if ((ifa
->flags
& (IF_MULTIACCESS
| IF_MULTICAST
)) ==
440 (IF_MULTIACCESS
| IF_MULTICAST
))
441 return OSPF_IT_BCAST
;
443 if ((ifa
->flags
& (IF_MULTIACCESS
| IF_MULTICAST
)) == IF_MULTIACCESS
)
450 ospf_iface_classify(u8 type
, struct ifa
*addr
)
452 return (type
!= OSPF_IT_UNDEF
) ? type
: ospf_iface_classify_(addr
->iface
, addr
);
457 ospf_iface_find(struct ospf_proto
*p
, struct iface
*what
)
459 struct ospf_iface
*ifa
;
461 WALK_LIST(ifa
, p
->iface_list
)
462 if ((ifa
->iface
== what
) && (ifa
->type
!= OSPF_IT_VLINK
))
469 ospf_iface_add(struct object_lock
*lock
)
471 struct ospf_iface
*ifa
= lock
->data
;
472 struct ospf_proto
*p
= ifa
->oa
->po
;
474 /* Open socket if interface is not stub */
475 if (! ifa
->stub
&& ! ospf_sk_open(ifa
))
477 log(L_ERR
"%s: Cannot open socket for %s, declaring as stub", p
->p
.name
, ifa
->ifname
);
478 ifa
->ioprob
= OSPF_I_SK
;
484 ifa
->hello_timer
= tm_new_set(ifa
->pool
, hello_timer_hook
, ifa
, 0, ifa
->helloint
);
486 if (ifa
->type
== OSPF_IT_NBMA
)
487 ifa
->poll_timer
= tm_new_set(ifa
->pool
, poll_timer_hook
, ifa
, 0, ifa
->pollint
);
489 if ((ifa
->type
== OSPF_IT_BCAST
) || (ifa
->type
== OSPF_IT_NBMA
))
490 ifa
->wait_timer
= tm_new_set(ifa
->pool
, wait_timer_hook
, ifa
, 0, 0);
492 ifa
->flood_queue_size
= ifa_flood_queue_size(ifa
);
493 ifa
->flood_queue
= mb_allocz(ifa
->pool
, ifa
->flood_queue_size
* sizeof(void *));
496 /* Do iface UP, unless there is no link and we use link detection */
497 ospf_iface_sm(ifa
, (ifa
->check_link
&& !(ifa
->iface
->flags
& IF_LINK_UP
)) ? ISM_LOOP
: ISM_UP
);
501 add_nbma_node(struct ospf_iface
*ifa
, struct nbma_node
*src
, int found
)
503 struct nbma_node
*n
= mb_alloc(ifa
->pool
, sizeof(struct nbma_node
));
504 add_tail(&ifa
->nbma_list
, NODE n
);
506 n
->eligible
= src
->eligible
;
511 ospf_iface_stubby(struct ospf_iface_patt
*ip
, struct ifa
*addr
)
514 if (addr
->flags
& IA_HOST
)
517 /* a loopback iface */
518 if (addr
->iface
->flags
& IF_LOOPBACK
)
522 * For compatibility reasons on BSD systems, we force OSPF
523 * interfaces with non-primary IP prefixes to be stub.
525 #if defined(OSPFv2) && !defined(CONFIG_MC_PROPER_SRC)
526 if (!ip
->bsd_secondary
&& !(addr
->flags
& IA_PRIMARY
))
534 ospf_iface_new(struct ospf_area
*oa
, struct ifa
*addr
, struct ospf_iface_patt
*ip
)
536 struct ospf_proto
*p
= oa
->po
;
537 struct iface
*iface
= addr
->iface
;
538 struct ospf_iface
*ifa
;
542 OSPF_TRACE(D_EVENTS
, "Adding interface %s (IID %d) to area %R",
543 iface
->name
, ip
->instance_id
, oa
->areaid
);
544 else if (addr
->flags
& IA_PEER
)
545 OSPF_TRACE(D_EVENTS
, "Adding interface %s (peer %I) to area %R",
546 iface
->name
, addr
->opposite
, oa
->areaid
);
548 OSPF_TRACE(D_EVENTS
, "Adding interface %s (%I/%d) to area %R",
549 iface
->name
, addr
->prefix
, addr
->pxlen
, oa
->areaid
);
551 pool
= rp_new(p
->p
.pool
, "OSPF Interface");
552 ifa
= mb_allocz(pool
, sizeof(struct ospf_iface
));
559 ifa
->iface_id
= iface
->index
;
560 ifa
->ifname
= iface
->name
;
562 ifa
->cost
= ip
->cost
;
563 ifa
->rxmtint
= ip
->rxmtint
;
564 ifa
->inftransdelay
= ip
->inftransdelay
;
565 ifa
->priority
= ip
->priority
;
566 ifa
->helloint
= ip
->helloint
;
567 ifa
->pollint
= ip
->pollint
;
568 ifa
->strictnbma
= ip
->strictnbma
;
569 ifa
->waitint
= ip
->waitint
;
570 ifa
->deadint
= ip
->deadint
;
571 ifa
->stub
= ospf_iface_stubby(ip
, addr
);
572 ifa
->ioprob
= OSPF_I_OK
;
573 ifa
->tx_length
= ifa_tx_length(ifa
);
574 ifa
->check_link
= ip
->check_link
;
575 ifa
->ecmp_weight
= ip
->ecmp_weight
;
576 ifa
->check_ttl
= (ip
->ttl_security
== 1);
578 ifa
->autype
= ip
->autype
;
579 ifa
->passwords
= ip
->passwords
;
580 ifa
->instance_id
= ip
->instance_id
;
582 ifa
->ptp_netmask
= !(addr
->flags
& IA_PEER
);
583 if (ip
->ptp_netmask
< 2)
584 ifa
->ptp_netmask
= ip
->ptp_netmask
;
587 ifa
->type
= ospf_iface_classify(ip
->type
, addr
);
589 /* Check validity of interface type */
590 int old_type
= ifa
->type
;
591 u32 if_multi_flag
= ip
->real_bcast
? IF_BROADCAST
: IF_MULTICAST
;
593 if (ospf_is_v2(p
) && (ifa
->type
== OSPF_IT_BCAST
) && (addr
->flags
& IA_PEER
))
594 ifa
->type
= OSPF_IT_PTP
;
596 if (ospf_is_v2(p
) && (ifa
->type
== OSPF_IT_NBMA
) && (addr
->flags
& IA_PEER
))
597 ifa
->type
= OSPF_IT_PTMP
;
599 if ((ifa
->type
== OSPF_IT_BCAST
) && !(iface
->flags
& if_multi_flag
))
600 ifa
->type
= OSPF_IT_NBMA
;
602 if ((ifa
->type
== OSPF_IT_PTP
) && !(iface
->flags
& if_multi_flag
))
603 ifa
->type
= OSPF_IT_PTMP
;
605 if (ifa
->type
!= old_type
)
606 log(L_WARN
"%s: Cannot use interface %s as %s, forcing %s",
607 p
->p
.name
, iface
->name
, ospf_it
[old_type
], ospf_it
[ifa
->type
]);
610 if ((ifa
->type
== OSPF_IT_PTP
) || (ifa
->type
== OSPF_IT_PTMP
))
611 ifa
->link_lsa_suppression
= ip
->link_lsa_suppression
;
613 ifa
->state
= OSPF_IS_DOWN
;
614 init_list(&ifa
->neigh_list
);
615 init_list(&ifa
->nbma_list
);
617 struct nbma_node
*nb
;
618 WALK_LIST(nb
, ip
->nbma_list
)
620 /* In OSPFv3, addr is link-local while configured neighbors could
621 have global IP (although RFC 5340 C.5 says link-local addresses
622 should be used). Because OSPFv3 iface is not subnet-specific,
623 there is no need for ipa_in_net() check */
625 if (ospf_is_v2(p
) && !ipa_in_net(nb
->ip
, addr
->prefix
, addr
->pxlen
))
628 if (ospf_is_v3(p
) && !ipa_is_link_local(nb
->ip
))
629 log(L_WARN
"%s: Configured neighbor address (%I) should be link-local",
632 add_nbma_node(ifa
, nb
, 0);
635 add_tail(&oa
->po
->iface_list
, NODE ifa
);
637 struct object_lock
*lock
= olock_new(pool
);
638 lock
->addr
= ospf_is_v2(p
) ? ifa
->addr
->prefix
: IPA_NONE
;
639 lock
->type
= OBJLOCK_IP
;
640 lock
->port
= OSPF_PROTO
;
641 lock
->inst
= ifa
->instance_id
;
644 lock
->hook
= ospf_iface_add
;
650 ospf_iface_new_vlink(struct ospf_proto
*p
, struct ospf_iface_patt
*ip
)
652 struct ospf_iface
*ifa
;
658 OSPF_TRACE(D_EVENTS
, "Adding vlink to %R via area %R", ip
->vid
, ip
->voa
);
660 /* Vlink ifname is stored just after the ospf_iface structure */
662 pool
= rp_new(p
->p
.pool
, "OSPF Vlink");
663 ifa
= mb_allocz(pool
, sizeof(struct ospf_iface
) + 16);
664 ifa
->oa
= p
->backbone
;
668 /* Assign iface ID, for vlinks, this is ugly hack */
669 u32 vlink_id
= p
->last_vlink_id
++;
670 ifa
->iface_id
= vlink_id
+ OSPF_VLINK_ID_OFFSET
;
671 ifa
->ifname
= (void *) (ifa
+ 1);
672 bsprintf(ifa
->ifname
, "vlink%d", vlink_id
);
674 ifa
->voa
= ospf_find_area(p
, ip
->voa
);
676 ifa
->sk
= p
->vlink_sk
;
678 ifa
->helloint
= ip
->helloint
;
679 ifa
->rxmtint
= ip
->rxmtint
;
680 ifa
->waitint
= ip
->waitint
;
681 ifa
->deadint
= ip
->deadint
;
682 ifa
->inftransdelay
= ip
->inftransdelay
;
683 ifa
->tx_length
= ospf_is_v2(p
) ? IP4_MIN_MTU
: IP6_MIN_MTU
;
684 ifa
->autype
= ip
->autype
;
685 ifa
->passwords
= ip
->passwords
;
686 ifa
->instance_id
= ip
->instance_id
;
688 ifa
->type
= OSPF_IT_VLINK
;
690 ifa
->state
= OSPF_IS_DOWN
;
691 init_list(&ifa
->neigh_list
);
692 init_list(&ifa
->nbma_list
);
694 add_tail(&p
->iface_list
, NODE ifa
);
696 ifa
->hello_timer
= tm_new_set(ifa
->pool
, hello_timer_hook
, ifa
, 0, ifa
->helloint
);
698 ifa
->flood_queue_size
= ifa_flood_queue_size(ifa
);
699 ifa
->flood_queue
= mb_allocz(ifa
->pool
, ifa
->flood_queue_size
* sizeof(void *));
703 ospf_iface_change_timer(timer
*tm
, uint val
)
715 ospf_iface_update_flood_queue_size(struct ospf_iface
*ifa
)
717 uint old_size
= ifa
->flood_queue_size
;
718 uint new_size
= ifa_flood_queue_size(ifa
);
720 if (new_size
<= old_size
)
723 ifa
->flood_queue_size
= new_size
;
724 ifa
->flood_queue
= mb_realloc(ifa
->flood_queue
, new_size
* sizeof(void *));
725 bzero(ifa
->flood_queue
+ old_size
, (new_size
- old_size
) * sizeof(void *));
729 ospf_iface_reconfigure(struct ospf_iface
*ifa
, struct ospf_iface_patt
*new)
731 struct ospf_proto
*p
= ifa
->oa
->po
;
732 struct ospf_iface_patt
*old
= ifa
->cf
;
733 char *ifname
= ifa
->ifname
;
735 /* Type could be changed in ospf_iface_new(),
736 but if config values are same then also results are same */
737 int old_type
= ospf_iface_classify(old
->type
, ifa
->addr
);
738 int new_type
= ospf_iface_classify(new->type
, ifa
->addr
);
739 if (old_type
!= new_type
)
742 int new_stub
= ospf_iface_stubby(new, ifa
->addr
);
743 if (ifa
->stub
!= new_stub
)
746 /* Change of these options would require to reset the iface socket */
747 if ((new->real_bcast
!= old
->real_bcast
) ||
748 (new->tx_tos
!= old
->tx_tos
) ||
749 (new->tx_priority
!= old
->tx_priority
) ||
750 (new->ttl_security
!= old
->ttl_security
))
758 if (ifa
->helloint
!= new->helloint
)
760 OSPF_TRACE(D_EVENTS
, "Changing hello interval of %s from %d to %d",
761 ifname
, ifa
->helloint
, new->helloint
);
763 ifa
->helloint
= new->helloint
;
764 ospf_iface_change_timer(ifa
->hello_timer
, ifa
->helloint
);
768 if (ifa
->rxmtint
!= new->rxmtint
)
770 OSPF_TRACE(D_EVENTS
, "Changing retransmit interval of %s from %d to %d",
771 ifname
, ifa
->rxmtint
, new->rxmtint
);
773 ifa
->rxmtint
= new->rxmtint
;
774 /* FIXME: Update neighbors' timers */
778 if (ifa
->pollint
!= new->pollint
)
780 OSPF_TRACE(D_EVENTS
, "Changing poll interval of %s from %d to %d",
781 ifname
, ifa
->pollint
, new->pollint
);
783 ifa
->pollint
= new->pollint
;
784 ospf_iface_change_timer(ifa
->poll_timer
, ifa
->pollint
);
788 if (ifa
->waitint
!= new->waitint
)
790 OSPF_TRACE(D_EVENTS
, "Changing wait interval of %s from %d to %d",
791 ifname
, ifa
->waitint
, new->waitint
);
793 ifa
->waitint
= new->waitint
;
794 if (ifa
->wait_timer
&& ifa
->wait_timer
->expires
)
795 tm_start(ifa
->wait_timer
, ifa
->waitint
);
799 if (ifa
->deadint
!= new->deadint
)
801 OSPF_TRACE(D_EVENTS
, "Changing dead interval of %s from %d to %d",
802 ifname
, ifa
->deadint
, new->deadint
);
803 ifa
->deadint
= new->deadint
;
807 if (ifa
->inftransdelay
!= new->inftransdelay
)
809 OSPF_TRACE(D_EVENTS
, "Changing transmit delay of %s from %d to %d",
810 ifname
, ifa
->inftransdelay
, new->inftransdelay
);
811 ifa
->inftransdelay
= new->inftransdelay
;
815 if (ifa
->autype
!= new->autype
)
817 OSPF_TRACE(D_EVENTS
, "Changing authentication type of %s", ifname
);
818 ifa
->autype
= new->autype
;
821 /* Update passwords */
822 ifa
->passwords
= new->passwords
;
824 /* Remaining options are just for proper interfaces */
825 if (ifa
->type
== OSPF_IT_VLINK
)
830 if (ifa
->cost
!= new->cost
)
832 OSPF_TRACE(D_EVENTS
, "Changing cost of %s from %d to %d",
833 ifname
, ifa
->cost
, new->cost
);
835 ifa
->cost
= new->cost
;
839 if (ifa
->priority
!= new->priority
)
841 OSPF_TRACE(D_EVENTS
, "Changing priority of %s from %d to %d",
842 ifname
, ifa
->priority
, new->priority
);
844 ifa
->priority
= new->priority
;
845 ospf_notify_link_lsa(ifa
);
849 if (ifa
->strictnbma
!= new->strictnbma
)
851 OSPF_TRACE(D_EVENTS
, "Changing NBMA strictness of %s from %d to %d",
852 ifname
, ifa
->strictnbma
, new->strictnbma
);
853 ifa
->strictnbma
= new->strictnbma
;
856 struct nbma_node
*nb
, *nbx
;
858 /* NBMA LIST - remove or update old */
859 WALK_LIST_DELSAFE(nb
, nbx
, ifa
->nbma_list
)
861 struct nbma_node
*nb2
= find_nbma_node_(&new->nbma_list
, nb
->ip
);
864 if (nb
->eligible
!= nb2
->eligible
)
866 OSPF_TRACE(D_EVENTS
, "Changing eligibility of NBMA neighbor %I on %s",
868 nb
->eligible
= nb2
->eligible
;
873 OSPF_TRACE(D_EVENTS
, "Removing NBMA neighbor %I on %s",
880 /* NBMA LIST - add new */
881 WALK_LIST(nb
, new->nbma_list
)
883 /* See related note in ospf_iface_new() */
884 if (ospf_is_v2(p
) && !ipa_in_net(nb
->ip
, ifa
->addr
->prefix
, ifa
->addr
->pxlen
))
887 if (ospf_is_v3(p
) && !ipa_is_link_local(nb
->ip
))
888 log(L_WARN
"%s: Configured neighbor address (%I) should be link-local",
891 if (! find_nbma_node(ifa
, nb
->ip
))
893 OSPF_TRACE(D_EVENTS
, "Adding NBMA neighbor %I on %s",
895 add_nbma_node(ifa
, nb
, !!find_neigh_by_ip(ifa
, nb
->ip
));
899 int update_buffers
= 0;
902 if (old
->tx_length
!= new->tx_length
)
904 OSPF_TRACE(D_EVENTS
, "Changing TX length of %s from %d to %d",
905 ifname
, old
->tx_length
, new->tx_length
);
907 /* ifa cannot be vlink */
908 ifa
->tx_length
= ifa_tx_length(ifa
);
912 ospf_iface_update_flood_queue_size(ifa
);
916 if (old
->rx_buffer
!= new->rx_buffer
)
918 OSPF_TRACE(D_EVENTS
, "Changing buffer size of %s from %d to %d",
919 ifname
, old
->rx_buffer
, new->rx_buffer
);
921 /* ifa cannot be vlink */
925 /* Buffer size depends on both tx_length and rx_buffer options */
926 if (update_buffers
&& ifa
->sk
)
928 uint bsize
= ifa_bufsize(ifa
);
929 sk_set_rbsize(ifa
->sk
, bsize
);
930 sk_set_tbsize(ifa
->sk
, bsize
);
934 if (ifa
->check_link
!= new->check_link
)
936 OSPF_TRACE(D_EVENTS
, "%s link check for %s",
937 new->check_link
? "Enabling" : "Disabling", ifname
);
938 ifa
->check_link
= new->check_link
;
940 /* ifa cannot be vlink */
941 if (!(ifa
->iface
->flags
& IF_LINK_UP
))
942 ospf_iface_sm(ifa
, ifa
->check_link
? ISM_LOOP
: ISM_UNLOOP
);
946 if (ifa
->ecmp_weight
!= new->ecmp_weight
)
948 OSPF_TRACE(D_EVENTS
, "Changing ECMP weight of %s from %d to %d",
949 ifname
, (int)ifa
->ecmp_weight
+ 1, (int)new->ecmp_weight
+ 1);
950 ifa
->ecmp_weight
= new->ecmp_weight
;
953 /* Link LSA suppression */
954 if (((ifa
->type
== OSPF_IT_PTP
) || (ifa
->type
== OSPF_IT_PTMP
)) &&
955 (ifa
->link_lsa_suppression
!= new->link_lsa_suppression
))
957 OSPF_TRACE(D_EVENTS
, "Changing link LSA suppression of %s from %d to %d",
958 ifname
, ifa
->link_lsa_suppression
, new->link_lsa_suppression
);
960 ifa
->link_lsa_suppression
= new->link_lsa_suppression
;
961 ospf_notify_link_lsa(ifa
);
965 if (ifa
->bfd
!= new->bfd
)
967 OSPF_TRACE(D_EVENTS
, "%s BFD for %s",
968 new->bfd
? "Enabling" : "Disabling", ifname
);
971 struct ospf_neighbor
*n
;
972 WALK_LIST(n
, ifa
->neigh_list
)
973 ospf_neigh_update_bfd(n
, ifa
->bfd
);
977 /* instance_id is not updated - it is part of key */
984 * State for matching iface pattterns walk
986 * This is significantly different in OSPFv2 and OSPFv3.
987 * In OSPFv2, OSPF ifaces are created for each IP prefix (struct ifa)
988 * In OSPFv3, OSPF ifaces are created based on real iface (struct iface)
989 * We support instance_id for both OSPFv2 (RFC 6549) and OSPFv3.
991 * We process one ifa/iface and match it for all configured instance IDs. We
992 * maintain bitfields to track whether given instance ID was already matched.
993 * We have two bitfields, one global (active) and one per area (ignore), to
994 * detect misconfigured cases where one iface with one instance ID matches in
998 struct ospf_mip_walk
{
999 u32 active
[8]; /* Bitfield of active instance IDs */
1000 u32 ignore
[8]; /* Bitfield of instance IDs matched in current area */
1001 struct ospf_area
*oa
; /* Current area */
1002 struct ospf_iface_patt
*ip
; /* Current iface pattern */
1003 struct iface
*iface
; /* Specified iface (input) */
1004 struct ifa
*a
; /* Specified ifa (input) */
1005 int warn
; /* Whether iface matched in multiple areas */
1009 ospf_walk_matching_iface_patts(struct ospf_proto
*p
, struct ospf_mip_walk
*s
)
1016 WALK_LIST(s
->oa
, p
->area_list
)
1021 WALK_LIST(s
->ip
, s
->oa
->ac
->patt_list
)
1023 id
= s
->ip
->instance_id
;
1024 if (BIT32_TEST(s
->ignore
, id
))
1027 if (iface_patt_match(&s
->ip
->i
, s
->iface
, s
->a
))
1029 /* Now we matched ifa/iface/instance_id for the first time in current area */
1030 BIT32_SET(s
->ignore
, id
);
1032 /* If we already found it in previous areas, ignore it and add warning */
1033 if (BIT32_TEST(s
->active
, id
))
1034 { s
->warn
= 1; continue; }
1036 BIT32_SET(s
->active
, id
);
1042 BIT32_ZERO(s
->ignore
, 256);
1046 log(L_WARN
"%s: Interface %s matches for multiple areas", p
->p
.name
, s
->iface
->name
);
1052 static struct ospf_iface
*
1053 ospf_iface_find_by_key(struct ospf_proto
*p
, struct ifa
*a
, int instance_id
)
1055 struct ospf_iface
*ifa
;
1057 WALK_LIST(ifa
, p
->iface_list
)
1058 if ((ifa
->addr
== a
) && (ifa
->instance_id
== instance_id
) &&
1059 (ifa
->type
!= OSPF_IT_VLINK
))
1067 ospf_ifa_notify2(struct proto
*P
, uint flags
, struct ifa
*a
)
1069 struct ospf_proto
*p
= (struct ospf_proto
*) P
;
1071 if (a
->flags
& IA_SECONDARY
)
1074 if (a
->scope
<= SCOPE_LINK
)
1077 /* In OSPFv2, we create OSPF iface for each address. */
1078 if (flags
& IF_CHANGE_UP
)
1080 struct ospf_mip_walk s
= { .iface
= a
->iface
, .a
= a
};
1081 while (ospf_walk_matching_iface_patts(p
, &s
))
1082 ospf_iface_new(s
.oa
, a
, s
.ip
);
1085 if (flags
& IF_CHANGE_DOWN
)
1087 struct ospf_iface
*ifa
, *ifx
;
1088 WALK_LIST_DELSAFE(ifa
, ifx
, p
->iface_list
)
1089 if ((ifa
->type
!= OSPF_IT_VLINK
) && (ifa
->addr
== a
))
1090 ospf_iface_remove(ifa
);
1091 /* See a note in ospf_iface_notify() */
1096 ospf_ifa_notify3(struct proto
*P
, uint flags
, struct ifa
*a
)
1098 struct ospf_proto
*p
= (struct ospf_proto
*) P
;
1100 if (a
->flags
& IA_SECONDARY
)
1103 if (a
->scope
< SCOPE_LINK
)
1106 /* In OSPFv3, we create OSPF iface for link-local address,
1107 other addresses are used for link-LSA. */
1108 if (a
->scope
== SCOPE_LINK
)
1110 if (flags
& IF_CHANGE_UP
)
1112 struct ospf_mip_walk s
= { .iface
= a
->iface
};
1113 while (ospf_walk_matching_iface_patts(p
, &s
))
1114 ospf_iface_new(s
.oa
, a
, s
.ip
);
1117 if (flags
& IF_CHANGE_DOWN
)
1119 struct ospf_iface
*ifa
, *ifx
;
1120 WALK_LIST_DELSAFE(ifa
, ifx
, p
->iface_list
)
1121 if ((ifa
->addr
== a
) && (ifa
->type
!= OSPF_IT_VLINK
))
1122 ospf_iface_remove(ifa
);
1127 struct ospf_iface
*ifa
;
1128 WALK_LIST(ifa
, p
->iface_list
)
1129 if (ifa
->iface
== a
->iface
)
1131 /* RFC 5340 4.4.3 Event 5 - prefix added/deleted */
1132 ospf_notify_link_lsa(ifa
);
1133 ospf_notify_rt_lsa(ifa
->oa
);
1140 ospf_reconfigure_ifaces2(struct ospf_proto
*p
)
1142 struct iface
*iface
;
1145 WALK_LIST(iface
, iface_list
)
1147 if (! (iface
->flags
& IF_UP
))
1150 WALK_LIST(a
, iface
->addrs
)
1152 if (a
->flags
& IA_SECONDARY
)
1155 if (a
->scope
<= SCOPE_LINK
)
1158 struct ospf_mip_walk s
= { .iface
= iface
, .a
= a
};
1159 while (ospf_walk_matching_iface_patts(p
, &s
))
1161 /* Main inner loop */
1162 struct ospf_iface
*ifa
= ospf_iface_find_by_key(p
, a
, s
.ip
->instance_id
);
1165 if ((ifa
->oa
== s
.oa
) && (ifa
->marked
< 2) &&
1166 ospf_iface_reconfigure(ifa
, s
.ip
))
1170 log(L_INFO
"%s: Restarting interface %s (%I/%d) in area %R",
1171 p
->p
.name
, ifa
->ifname
, a
->prefix
, a
->pxlen
, s
.oa
->areaid
);
1172 ospf_iface_shutdown(ifa
);
1173 ospf_iface_remove(ifa
);
1176 ospf_iface_new(s
.oa
, a
, s
.ip
);
1183 ospf_reconfigure_ifaces3(struct ospf_proto
*p
)
1185 struct iface
*iface
;
1188 WALK_LIST(iface
, iface_list
)
1190 if (! (iface
->flags
& IF_UP
))
1193 WALK_LIST(a
, iface
->addrs
)
1195 if (a
->flags
& IA_SECONDARY
)
1198 if (a
->scope
!= SCOPE_LINK
)
1201 struct ospf_mip_walk s
= { .iface
= iface
};
1202 while (ospf_walk_matching_iface_patts(p
, &s
))
1204 /* Main inner loop */
1205 struct ospf_iface
*ifa
= ospf_iface_find_by_key(p
, a
, s
.ip
->instance_id
);
1208 if ((ifa
->oa
== s
.oa
) && (ifa
->marked
< 2) &&
1209 ospf_iface_reconfigure(ifa
, s
.ip
))
1213 log(L_INFO
"%s: Restarting interface %s (IID %d) in area %R",
1214 p
->p
.name
, ifa
->ifname
, ifa
->instance_id
, s
.oa
->areaid
);
1215 ospf_iface_shutdown(ifa
);
1216 ospf_iface_remove(ifa
);
1219 ospf_iface_new(s
.oa
, a
, s
.ip
);
1226 ospf_reconfigure_ifaces(struct ospf_proto
*p
)
1229 ospf_reconfigure_ifaces2(p
);
1231 ospf_reconfigure_ifaces3(p
);
1236 ospf_iface_change_mtu(struct ospf_proto
*p
, struct ospf_iface
*ifa
)
1238 /* ifa is not vlink */
1240 OSPF_TRACE(D_EVENTS
, "Interface %s changed MTU to %d", ifa
->iface
->mtu
);
1242 ifa
->tx_length
= ifa_tx_length(ifa
);
1247 /* We do not shrink dynamic buffers */
1248 uint bsize
= ifa_bufsize(ifa
);
1249 if (bsize
> ifa
->sk
->rbsize
)
1250 sk_set_rbsize(ifa
->sk
, bsize
);
1251 if (bsize
> ifa
->sk
->tbsize
)
1252 sk_set_tbsize(ifa
->sk
, bsize
);
1255 ospf_iface_update_flood_queue_size(ifa
);
1259 ospf_iface_notify(struct ospf_proto
*p
, uint flags
, struct ospf_iface
*ifa
)
1261 /* ifa is not vlink */
1263 if (flags
& IF_CHANGE_DOWN
)
1265 ospf_iface_remove(ifa
);
1269 if (flags
& IF_CHANGE_LINK
)
1270 ospf_iface_sm(ifa
, (ifa
->iface
->flags
& IF_LINK_UP
) ? ISM_UNLOOP
: ISM_LOOP
);
1272 if (flags
& IF_CHANGE_MTU
)
1273 ospf_iface_change_mtu(p
, ifa
);
1277 ospf_if_notify(struct proto
*P
, uint flags
, struct iface
*iface
)
1279 struct ospf_proto
*p
= (struct ospf_proto
*) P
;
1282 if (iface->flags & IF_IGNORE)
1286 /* Going up means that there are no such ifaces yet */
1287 if (flags
& IF_CHANGE_UP
)
1290 struct ospf_iface
*ifa
, *ifx
;
1291 WALK_LIST_DELSAFE(ifa
, ifx
, p
->iface_list
)
1292 if (ifa
->iface
== iface
)
1293 ospf_iface_notify(p
, flags
, ifa
);
1295 /* We use here that even shutting down iface also shuts down
1296 the vlinks, but vlinks are not freed and stays in the
1297 iface_list even when down */
1301 ospf_iface_info(struct ospf_iface
*ifa
)
1305 if (ifa
->strictnbma
&&
1306 ((ifa
->type
== OSPF_IT_NBMA
) || (ifa
->type
== OSPF_IT_PTMP
)))
1309 if (ifa
->cf
->real_bcast
&&
1310 ((ifa
->type
== OSPF_IT_BCAST
) || (ifa
->type
== OSPF_IT_PTP
)))
1313 if (ifa
->type
== OSPF_IT_VLINK
)
1315 cli_msg(-1015, "Virtual link %s to %R", ifa
->ifname
, ifa
->vid
);
1316 cli_msg(-1015, "\tPeer IP: %I", ifa
->vip
);
1317 cli_msg(-1015, "\tTransit area: %R (%u)", ifa
->voa
->areaid
, ifa
->voa
->areaid
);
1321 if (ospf_is_v3(ifa
->oa
->po
))
1322 cli_msg(-1015, "Interface %s (IID %d)", ifa
->ifname
, ifa
->instance_id
);
1323 else if (ifa
->addr
->flags
& IA_PEER
)
1324 cli_msg(-1015, "Interface %s (peer %I)", ifa
->ifname
, ifa
->addr
->opposite
);
1326 cli_msg(-1015, "Interface %s (%I/%d)", ifa
->ifname
, ifa
->addr
->prefix
, ifa
->addr
->pxlen
);
1328 cli_msg(-1015, "\tType: %s%s", ospf_it
[ifa
->type
], more
);
1329 cli_msg(-1015, "\tArea: %R (%u)", ifa
->oa
->areaid
, ifa
->oa
->areaid
);
1331 cli_msg(-1015, "\tState: %s%s", ospf_is_names
[ifa
->state
], ifa
->stub
? " (stub)" : "");
1332 cli_msg(-1015, "\tPriority: %u", ifa
->priority
);
1333 cli_msg(-1015, "\tCost: %u", ifa
->cost
);
1334 if (ifa
->oa
->po
->ecmp
)
1335 cli_msg(-1015, "\tECMP weight: %d", ((int) ifa
->ecmp_weight
) + 1);
1336 cli_msg(-1015, "\tHello timer: %u", ifa
->helloint
);
1338 if (ifa
->type
== OSPF_IT_NBMA
)
1340 cli_msg(-1015, "\tPoll timer: %u", ifa
->pollint
);
1342 cli_msg(-1015, "\tWait timer: %u", ifa
->waitint
);
1343 cli_msg(-1015, "\tDead timer: %u", ifa
->deadint
);
1344 cli_msg(-1015, "\tRetransmit timer: %u", ifa
->rxmtint
);
1345 if ((ifa
->type
== OSPF_IT_BCAST
) || (ifa
->type
== OSPF_IT_NBMA
))
1347 cli_msg(-1015, "\tDesigned router (ID): %R", ifa
->drid
);
1348 cli_msg(-1015, "\tDesigned router (IP): %I", ifa
->drip
);
1349 cli_msg(-1015, "\tBackup designed router (ID): %R", ifa
->bdrid
);
1350 cli_msg(-1015, "\tBackup designed router (IP): %I", ifa
->bdrip
);