]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_opaque.h
*: auto-convert to SPDX License IDs
[mirror_frr.git] / ospfd / ospf_opaque.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
718e3744 2/*
3 * This is an implementation of rfc2370.
4 * Copyright (C) 2001 KDD R&D Laboratories, Inc.
5 * http://www.kddlabs.co.jp/
718e3744 6 */
7
8#ifndef _ZEBRA_OSPF_OPAQUE_H
9#define _ZEBRA_OSPF_OPAQUE_H
10
4dadc291 11#include "vty.h"
f328dc60 12#include <lib/json.h>
4dadc291 13
d62a17ae 14#define IS_OPAQUE_LSA(type) \
15 ((type) == OSPF_OPAQUE_LINK_LSA || (type) == OSPF_OPAQUE_AREA_LSA \
16 || (type) == OSPF_OPAQUE_AS_LSA)
718e3744 17
718e3744 18/*
19 * Opaque LSA's link state ID is redefined as follows.
20 *
21 * 24 16 8 0
22 * +--------+--------+--------+--------+
23 * |tttttttt|........|........|........|
24 * +--------+--------+--------+--------+
25 * |<-Type->|<------- Opaque ID ------>|
26 */
27#define LSID_OPAQUE_TYPE_MASK 0xff000000 /* 8 bits */
28#define LSID_OPAQUE_ID_MASK 0x00ffffff /* 24 bits */
29
d7c0a89a 30#define GET_OPAQUE_TYPE(lsid) (((uint32_t)(lsid)&LSID_OPAQUE_TYPE_MASK) >> 24)
718e3744 31
d7c0a89a 32#define GET_OPAQUE_ID(lsid) ((uint32_t)(lsid)&LSID_OPAQUE_ID_MASK)
718e3744 33
d62a17ae 34#define SET_OPAQUE_LSID(type, id) \
937652c6 35 ((((unsigned)(type) << 24) & LSID_OPAQUE_TYPE_MASK) \
996c9314 36 | ((id)&LSID_OPAQUE_ID_MASK))
718e3744 37
38/*
39 * Opaque LSA types will be assigned by IANA.
40 * <http://www.iana.org/assignments/ospf-opaque-types>
41 */
42#define OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA 1
43#define OPAQUE_TYPE_SYCAMORE_OPTICAL_TOPOLOGY_DESC 2
44#define OPAQUE_TYPE_GRACE_LSA 3
16f1b9ee
OD
45#define OPAQUE_TYPE_L1VPN_LSA 5
46#define OPAQUE_TYPE_ROUTER_INFORMATION_LSA 4
47#define OPAQUE_TYPE_INTER_AS_LSA 6
cf9b9f77
OD
48#define OPAQUE_TYPE_EXTENDED_PREFIX_LSA 7
49#define OPAQUE_TYPE_EXTENDED_LINK_LSA 8
50#define OPAQUE_TYPE_MAX 8
718e3744 51
78dfa0c7 52/* Following types are proposed in internet-draft documents. */
718e3744 53#define OPAQUE_TYPE_8021_QOSPF 129
54#define OPAQUE_TYPE_SECONDARY_NEIGHBOR_DISCOVERY 224
55#define OPAQUE_TYPE_FLOODGATE 225
56
57/* Ugly hack to make use of an unallocated value for wildcard matching! */
58#define OPAQUE_TYPE_WILDCARD 0
59
d62a17ae 60#define OPAQUE_TYPE_RANGE_UNASSIGNED(type) \
61 (OPAQUE_TYPE_MAX <= (type) && (type) <= 127)
718e3744 62
d62a17ae 63#define OPAQUE_TYPE_RANGE_RESERVED(type) (127 < (type) && (type) <= 255)
718e3744 64
0b91fce7 65#define OSPF_OPAQUE_LSA_MIN_SIZE 0 /* RFC5250 imposes no minimum */
cf680c38 66
d62a17ae 67#define VALID_OPAQUE_INFO_LEN(lsahdr) \
68 ((ntohs((lsahdr)->length) >= sizeof(struct lsa_header)) \
8db278b5 69 && ((ntohs((lsahdr)->length) < OSPF_MAX_LSA_SIZE)) \
d7c0a89a 70 && ((ntohs((lsahdr)->length) % sizeof(uint32_t)) == 0))
718e3744 71
ead99d5f
OD
72/*
73 * Following section defines generic TLV (type, length, value) macros,
74 * used for various LSA opaque usage e.g. Traffic Engineering.
75 */
2a39170c 76struct tlv_header {
d7c0a89a
QY
77 uint16_t type; /* Type of Value */
78 uint16_t length; /* Length of Value portion only, in bytes */
ead99d5f
OD
79};
80
a6df2b80 81#define TLV_HDR_SIZE (sizeof(struct tlv_header))
ead99d5f 82
d7c0a89a 83#define TLV_BODY_SIZE(tlvh) (ROUNDUP(ntohs((tlvh)->length), sizeof(uint32_t)))
ead99d5f 84
72327cf3 85#define TLV_SIZE(tlvh) (uint32_t)(TLV_HDR_SIZE + TLV_BODY_SIZE(tlvh))
ead99d5f 86
996c9314 87#define TLV_HDR_TOP(lsah) \
a6df2b80 88 (struct tlv_header *)((char *)(lsah) + OSPF_LSA_HEADER_SIZE)
ead99d5f 89
996c9314 90#define TLV_HDR_NEXT(tlvh) \
a6df2b80 91 (struct tlv_header *)((char *)(tlvh) + TLV_SIZE(tlvh))
ead99d5f 92
996c9314 93#define TLV_HDR_SUBTLV(tlvh) \
a6df2b80 94 (struct tlv_header *)((char *)(tlvh) + TLV_HDR_SIZE)
ead99d5f 95
a6df2b80 96#define TLV_DATA(tlvh) (void *)((char *)(tlvh) + TLV_HDR_SIZE)
ead99d5f 97
a6df2b80
OD
98#define TLV_TYPE(tlvh) tlvh.header.type
99#define TLV_LEN(tlvh) tlvh.header.length
100#define TLV_HDR(tlvh) tlvh.header
ead99d5f
OD
101
102/* Following declaration concerns the Opaque LSA management */
996c9314 103enum lsa_opcode { REORIGINATE_THIS_LSA, REFRESH_THIS_LSA, FLUSH_THIS_LSA };
ead99d5f 104
718e3744 105/* Prototypes. */
718e3744 106
d62a17ae 107extern void ospf_opaque_init(void);
108extern void ospf_opaque_term(void);
bcf4475e 109extern void ospf_opaque_finish(void);
d62a17ae 110extern int ospf_opaque_type9_lsa_init(struct ospf_interface *oi);
111extern void ospf_opaque_type9_lsa_term(struct ospf_interface *oi);
112extern int ospf_opaque_type10_lsa_init(struct ospf_area *area);
113extern void ospf_opaque_type10_lsa_term(struct ospf_area *area);
114extern int ospf_opaque_type11_lsa_init(struct ospf *ospf);
115extern void ospf_opaque_type11_lsa_term(struct ospf *ospf);
116
117extern int ospf_register_opaque_functab(
d7c0a89a 118 uint8_t lsa_type, uint8_t opaque_type,
d62a17ae 119 int (*new_if_hook)(struct interface *ifp),
120 int (*del_if_hook)(struct interface *ifp),
121 void (*ism_change_hook)(struct ospf_interface *oi, int old_status),
122 void (*nsm_change_hook)(struct ospf_neighbor *nbr, int old_status),
123 void (*config_write_router)(struct vty *vty),
124 void (*config_write_if)(struct vty *vty, struct interface *ifp),
125 void (*config_write_debug)(struct vty *vty),
3e63092b
RW
126 void (*show_opaque_info)(struct vty *vty, struct json_object *json,
127 struct ospf_lsa *lsa),
d62a17ae 128 int (*lsa_originator)(void *arg),
129 struct ospf_lsa *(*lsa_refresher)(struct ospf_lsa *lsa),
130 int (*new_lsa_hook)(struct ospf_lsa *lsa),
131 int (*del_lsa_hook)(struct ospf_lsa *lsa));
d7c0a89a 132extern void ospf_delete_opaque_functab(uint8_t lsa_type, uint8_t opaque_type);
d62a17ae 133
134extern int ospf_opaque_new_if(struct interface *ifp);
135extern int ospf_opaque_del_if(struct interface *ifp);
136extern void ospf_opaque_ism_change(struct ospf_interface *oi, int old_status);
137extern void ospf_opaque_nsm_change(struct ospf_neighbor *nbr, int old_status);
a6df2b80 138extern void ospf_opaque_config_write_router(struct vty *vty, struct ospf *ospf);
d62a17ae 139extern void ospf_opaque_config_write_if(struct vty *vty, struct interface *ifp);
140extern void ospf_opaque_config_write_debug(struct vty *vty);
f328dc60 141extern void show_opaque_info_detail(struct vty *vty, struct ospf_lsa *lsa,
142 json_object *json);
d7c0a89a 143extern void ospf_opaque_lsa_dump(struct stream *s, uint16_t length);
d62a17ae 144
145extern void ospf_opaque_lsa_originate_schedule(struct ospf_interface *oi,
146 int *init_delay);
a6df2b80 147extern struct ospf_lsa *ospf_opaque_lsa_install(struct ospf_lsa *lsa,
d62a17ae 148 int rt_recalc);
149extern struct ospf_lsa *ospf_opaque_lsa_refresh(struct ospf_lsa *lsa);
150
151extern void ospf_opaque_lsa_reoriginate_schedule(void *lsa_type_dependent,
d7c0a89a
QY
152 uint8_t lsa_type,
153 uint8_t opaque_type);
d62a17ae 154extern void ospf_opaque_lsa_refresh_schedule(struct ospf_lsa *lsa);
155extern void ospf_opaque_lsa_flush_schedule(struct ospf_lsa *lsa);
156
157extern void ospf_opaque_self_originated_lsa_received(struct ospf_neighbor *nbr,
158 struct ospf_lsa *lsa);
159extern struct ospf *oi_to_top(struct ospf_interface *oi);
718e3744 160
5349121b
CH
161extern int ospf_opaque_is_owned(struct ospf_lsa *lsa);
162
718e3744 163#endif /* _ZEBRA_OSPF_OPAQUE_H */