static int ospf6_unknown_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
{
- u_char *start, *end, *current;
+ uint8_t *start, *end, *current;
char byte[4];
- start = (u_char *)lsa->header + sizeof(struct ospf6_lsa_header);
- end = (u_char *)lsa->header + ntohs(lsa->header->length);
+ start = (uint8_t *)lsa->header + sizeof(struct ospf6_lsa_header);
+ end = (uint8_t *)lsa->header + ntohs(lsa->header->length);
vty_out(vty, " Unknown contents:\n");
for (current = start; current < end; current++) {
return 0;
}
-struct ospf6_lsa_handler unknown_handler = {
- OSPF6_LSTYPE_UNKNOWN, "Unknown", "Unk", ospf6_unknown_lsa_show, NULL};
+static struct ospf6_lsa_handler unknown_handler = {
+ .lh_type = OSPF6_LSTYPE_UNKNOWN,
+ .lh_name = "Unknown",
+ .lh_short_name = "Unk",
+ .lh_show = ospf6_unknown_lsa_show,
+ .lh_get_prefix_str = NULL,
+ .lh_debug = 0 /* No default debug */
+};
-void ospf6_install_lsa_handler(struct ospf6_lsa_handler *handler)
+void ospf6_install_lsa_handler(const struct ospf6_lsa_handler *handler)
{
/* type in handler is host byte order */
- int index = handler->type & OSPF6_LSTYPE_FCODE_MASK;
- vector_set_index(ospf6_lsa_handler_vector, index, handler);
+ int index = handler->lh_type & OSPF6_LSTYPE_FCODE_MASK;
+ vector_set_index(ospf6_lsa_handler_vector, index, (void *)handler);
}
-struct ospf6_lsa_handler *ospf6_get_lsa_handler(u_int16_t type)
+const struct ospf6_lsa_handler *ospf6_get_lsa_handler(uint16_t type)
{
- struct ospf6_lsa_handler *handler = NULL;
+ const struct ospf6_lsa_handler *handler = NULL;
unsigned int index = ntohs(type) & OSPF6_LSTYPE_FCODE_MASK;
if (index >= vector_active(ospf6_lsa_handler_vector))
return handler;
}
-const char *ospf6_lstype_name(u_int16_t type)
+const char *ospf6_lstype_name(uint16_t type)
{
static char buf[8];
- struct ospf6_lsa_handler *handler;
+ const struct ospf6_lsa_handler *handler;
handler = ospf6_get_lsa_handler(type);
if (handler && handler != &unknown_handler)
- return handler->name;
+ return handler->lh_name;
snprintf(buf, sizeof(buf), "0x%04hx", ntohs(type));
return buf;
}
-const char *ospf6_lstype_short_name(u_int16_t type)
+const char *ospf6_lstype_short_name(uint16_t type)
{
static char buf[8];
- struct ospf6_lsa_handler *handler;
+ const struct ospf6_lsa_handler *handler;
handler = ospf6_get_lsa_handler(type);
if (handler && handler != &unknown_handler)
- return handler->short_name;
+ return handler->lh_short_name;
snprintf(buf, sizeof(buf), "0x%04hx", ntohs(type));
return buf;
}
-u_char ospf6_lstype_debug(u_int16_t type)
+uint8_t ospf6_lstype_debug(uint16_t type)
{
- struct ospf6_lsa_handler *handler;
+ const struct ospf6_lsa_handler *handler;
handler = ospf6_get_lsa_handler(type);
- return handler->debug;
+ return handler->lh_debug;
}
/* RFC2328: Section 13.2 */
/* ospf6 age functions */
/* calculate birth */
-static void ospf6_lsa_age_set(struct ospf6_lsa *lsa)
+void ospf6_lsa_age_set(struct ospf6_lsa *lsa)
{
struct timeval now;
/* this function calculates current age from its birth,
then update age field of LSA header. return value is current age */
-u_int16_t ospf6_lsa_age_current(struct ospf6_lsa *lsa)
+uint16_t ospf6_lsa_age_current(struct ospf6_lsa *lsa)
{
struct timeval now;
- u_int32_t ulage;
- u_int16_t age;
+ uint32_t ulage;
+ uint16_t age;
assert(lsa);
assert(lsa->header);
}
/* update age field of LSA header with adding InfTransDelay */
-void ospf6_lsa_age_update_to_send(struct ospf6_lsa *lsa, u_int32_t transdelay)
+void ospf6_lsa_age_update_to_send(struct ospf6_lsa *lsa, uint32_t transdelay)
{
unsigned short age;
int ospf6_lsa_compare(struct ospf6_lsa *a, struct ospf6_lsa *b)
{
int32_t seqnuma, seqnumb;
- u_int16_t cksuma, cksumb;
- u_int16_t agea, ageb;
+ uint16_t cksuma, cksumb;
+ uint16_t agea, ageb;
assert(a && a->header);
assert(b && b->header);
zlog_debug(" [%s Id:%s Adv:%s]", ospf6_lstype_name(header->type), id,
adv_router);
zlog_debug(" Age: %4hu SeqNum: %#08lx Cksum: %04hx Len: %d",
- ntohs(header->age), (u_long)ntohl(header->seqnum),
+ ntohs(header->age), (unsigned long)ntohl(header->seqnum),
ntohs(header->checksum), ntohs(header->length));
}
{
char adv_router[16], id[16];
int type;
- struct ospf6_lsa_handler *handler;
+ const struct ospf6_lsa_handler *handler;
char buf[64], tmpbuf[80];
int cnt = 0;
vty_out(vty, "%-4s %-15s%-15s%4hu %8lx %30s\n",
ospf6_lstype_short_name(lsa->header->type), id,
adv_router, ospf6_lsa_age_current(lsa),
- (u_long)ntohl(lsa->header->seqnum),
- handler->get_prefix_str(lsa, buf, sizeof(buf), 0));
+ (unsigned long)ntohl(lsa->header->seqnum),
+ handler->lh_get_prefix_str(lsa, buf, sizeof(buf), 0));
} else if (type != OSPF6_LSTYPE_UNKNOWN) {
sprintf(tmpbuf, "%-4s %-15s%-15s%4hu %8lx",
ospf6_lstype_short_name(lsa->header->type), id,
adv_router, ospf6_lsa_age_current(lsa),
- (u_long)ntohl(lsa->header->seqnum));
+ (unsigned long)ntohl(lsa->header->seqnum));
- while (handler->get_prefix_str(lsa, buf, sizeof(buf), cnt)
+ while (handler->lh_get_prefix_str(lsa, buf, sizeof(buf), cnt)
!= NULL) {
vty_out(vty, "%s %30s\n", tmpbuf, buf);
cnt++;
vty_out(vty, "%-4s %-15s%-15s%4hu %8lx\n",
ospf6_lstype_short_name(lsa->header->type), id,
adv_router, ospf6_lsa_age_current(lsa),
- (u_long)ntohl(lsa->header->seqnum));
+ (unsigned long)ntohl(lsa->header->seqnum));
}
}
void ospf6_lsa_show_dump(struct vty *vty, struct ospf6_lsa *lsa)
{
- u_char *start, *end, *current;
+ uint8_t *start, *end, *current;
char byte[4];
- start = (u_char *)lsa->header;
- end = (u_char *)lsa->header + ntohs(lsa->header->length);
+ start = (uint8_t *)lsa->header;
+ end = (uint8_t *)lsa->header + ntohs(lsa->header->length);
vty_out(vty, "\n");
vty_out(vty, "%s:\n", lsa->name);
vty_out(vty, "Link State ID: %s\n", id);
vty_out(vty, "Advertising Router: %s\n", adv_router);
vty_out(vty, "LS Sequence Number: %#010lx\n",
- (u_long)ntohl(lsa->header->seqnum));
+ (unsigned long)ntohl(lsa->header->seqnum));
vty_out(vty, "CheckSum: %#06hx Length: %hu\n",
ntohs(lsa->header->checksum), ntohs(lsa->header->length));
vty_out(vty, "Flag: %x \n", lsa->flag);
void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
{
char adv_router[64], id[64];
- struct ospf6_lsa_handler *handler;
+ const struct ospf6_lsa_handler *handler;
struct timeval now, res;
char duration[64];
vty_out(vty, "Link State ID: %s\n", id);
vty_out(vty, "Advertising Router: %s\n", adv_router);
vty_out(vty, "LS Sequence Number: %#010lx\n",
- (u_long)ntohl(lsa->header->seqnum));
+ (unsigned long)ntohl(lsa->header->seqnum));
vty_out(vty, "CheckSum: %#06hx Length: %hu\n",
ntohs(lsa->header->checksum), ntohs(lsa->header->length));
vty_out(vty, "Duration: %s\n", duration);
handler = ospf6_get_lsa_handler(lsa->header->type);
- if (handler->show == NULL)
- handler = &unknown_handler;
- (*handler->show)(vty, lsa);
+
+ if (handler->lh_show != NULL)
+ handler->lh_show(vty, lsa);
+ else {
+ assert(unknown_handler.lh_show != NULL);
+ unknown_handler.lh_show(vty, lsa);
+ }
vty_out(vty, "\n");
}
{
struct ospf6_lsa *lsa = NULL;
struct ospf6_lsa_header *new_header = NULL;
- u_int16_t lsa_size = 0;
+ uint16_t lsa_size = 0;
/* size of the entire LSA */
lsa_size = ntohs(header->length); /* XXX vulnerable */
/* allocate memory for this LSA */
- new_header =
- (struct ospf6_lsa_header *)XMALLOC(MTYPE_OSPF6_LSA_HEADER,
- lsa_size);
+ new_header = (struct ospf6_lsa_header *)XMALLOC(MTYPE_OSPF6_LSA_HEADER,
+ lsa_size);
/* copy LSA from original header */
memcpy(new_header, header, lsa_size);
return 0;
}
+void ospf6_flush_self_originated_lsas_now(void)
+{
+ struct listnode *node;
+ struct ospf6_area *oa;
+ struct ospf6_lsa *lsa;
+ const struct route_node *end = NULL;
+ uint32_t type, adv_router;
+
+ ospf6->inst_shutdown = 1;
+
+ for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, node, oa)) {
+ end = ospf6_lsdb_head(oa->lsdb_self, 0, 0, ospf6->router_id,
+ &lsa);
+ while (lsa) {
+ /* RFC 2328 (14.1): Set MAXAGE */
+ lsa->header->age = htons(OSPF_LSA_MAXAGE);
+ /* Flood MAXAGE LSA*/
+ ospf6_flood(NULL, lsa);
+
+ lsa = ospf6_lsdb_next(end, lsa);
+ }
+ }
+
+ type = htons(OSPF6_LSTYPE_AS_EXTERNAL);
+ adv_router = ospf6->router_id;
+ for (ALL_LSDB_TYPED_ADVRTR(ospf6->lsdb, type, adv_router, lsa)) {
+ /* RFC 2328 (14.1): Set MAXAGE */
+ lsa->header->age = htons(OSPF_LSA_MAXAGE);
+ ospf6_flood(NULL, lsa);
+ }
+}
/* Fletcher Checksum -- Refer to RFC1008. */
one-based. */
unsigned short ospf6_lsa_checksum(struct ospf6_lsa_header *lsa_header)
{
- u_char *buffer = (u_char *)&lsa_header->type;
- int type_offset = buffer - (u_char *)&lsa_header->age; /* should be 2 */
+ uint8_t *buffer = (uint8_t *)&lsa_header->type;
+ int type_offset =
+ buffer - (uint8_t *)&lsa_header->age; /* should be 2 */
/* Skip the AGE field */
- u_int16_t len = ntohs(lsa_header->length) - type_offset;
+ uint16_t len = ntohs(lsa_header->length) - type_offset;
/* Checksum offset starts from "type" field, not the beginning of the
lsa_header struct. The offset is 14, rather than 16. */
- int checksum_offset = (u_char *)&lsa_header->checksum - buffer;
+ int checksum_offset = (uint8_t *)&lsa_header->checksum - buffer;
return (unsigned short)fletcher_checksum(buffer, len, checksum_offset);
}
int ospf6_lsa_checksum_valid(struct ospf6_lsa_header *lsa_header)
{
- u_char *buffer = (u_char *)&lsa_header->type;
- int type_offset = buffer - (u_char *)&lsa_header->age; /* should be 2 */
+ uint8_t *buffer = (uint8_t *)&lsa_header->type;
+ int type_offset =
+ buffer - (uint8_t *)&lsa_header->age; /* should be 2 */
/* Skip the AGE field */
- u_int16_t len = ntohs(lsa_header->length) - type_offset;
+ uint16_t len = ntohs(lsa_header->length) - type_offset;
return (fletcher_checksum(buffer, len, FLETCHER_CHECKSUM_VALIDATE)
== 0);
vector_free(ospf6_lsa_handler_vector);
}
-static char *ospf6_lsa_handler_name(struct ospf6_lsa_handler *h)
+static char *ospf6_lsa_handler_name(const struct ospf6_lsa_handler *h)
{
static char buf[64];
unsigned int i;
- unsigned int size = strlen(h->name);
+ unsigned int size = strlen(h->lh_name);
- if (!strcmp(h->name, "unknown") && h->type != OSPF6_LSTYPE_UNKNOWN) {
- snprintf(buf, sizeof(buf), "%#04hx", h->type);
+ if (!strcmp(h->lh_name, "unknown")
+ && h->lh_type != OSPF6_LSTYPE_UNKNOWN) {
+ snprintf(buf, sizeof(buf), "%#04hx", h->lh_type);
return buf;
}
for (i = 0; i < MIN(size, sizeof(buf)); i++) {
- if (!islower((unsigned char)h->name[i]))
- buf[i] = tolower((unsigned char)h->name[i]);
+ if (!islower((unsigned char)h->lh_name[i]))
+ buf[i] = tolower((unsigned char)h->lh_name[i]);
else
- buf[i] = h->name[i];
+ buf[i] = h->lh_name[i];
}
buf[size] = '\0';
return buf;
strlen(argv[idx_lsa]->arg))
== 0)
break;
- if (!strcasecmp(argv[idx_lsa]->arg, handler->name))
+ if (!strcasecmp(argv[idx_lsa]->arg, handler->lh_name))
break;
handler = NULL;
}
if (argc == 5) {
if (strmatch(argv[idx_type]->text, "originate"))
- SET_FLAG(handler->debug, OSPF6_LSA_DEBUG_ORIGINATE);
+ SET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_ORIGINATE);
else if (strmatch(argv[idx_type]->text, "examine"))
- SET_FLAG(handler->debug, OSPF6_LSA_DEBUG_EXAMIN);
+ SET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_EXAMIN);
else if (strmatch(argv[idx_type]->text, "flooding"))
- SET_FLAG(handler->debug, OSPF6_LSA_DEBUG_FLOOD);
+ SET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_FLOOD);
} else
- SET_FLAG(handler->debug, OSPF6_LSA_DEBUG);
+ SET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG);
return CMD_SUCCESS;
}
{
int idx_lsa = 4;
int idx_type = 5;
- u_int i;
+ unsigned int i;
struct ospf6_lsa_handler *handler = NULL;
for (i = 0; i < vector_active(ospf6_lsa_handler_vector); i++) {
strlen(argv[idx_lsa]->arg))
== 0)
break;
- if (!strcasecmp(argv[idx_lsa]->arg, handler->name))
+ if (!strcasecmp(argv[idx_lsa]->arg, handler->lh_name))
break;
}
if (argc == 6) {
if (strmatch(argv[idx_type]->text, "originate"))
- UNSET_FLAG(handler->debug, OSPF6_LSA_DEBUG_ORIGINATE);
+ UNSET_FLAG(handler->lh_debug,
+ OSPF6_LSA_DEBUG_ORIGINATE);
if (strmatch(argv[idx_type]->text, "examine"))
- UNSET_FLAG(handler->debug, OSPF6_LSA_DEBUG_EXAMIN);
+ UNSET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_EXAMIN);
if (strmatch(argv[idx_type]->text, "flooding"))
- UNSET_FLAG(handler->debug, OSPF6_LSA_DEBUG_FLOOD);
+ UNSET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_FLOOD);
} else
- UNSET_FLAG(handler->debug, OSPF6_LSA_DEBUG);
+ UNSET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG);
return CMD_SUCCESS;
}
int config_write_ospf6_debug_lsa(struct vty *vty)
{
- u_int i;
- struct ospf6_lsa_handler *handler;
+ unsigned int i;
+ const struct ospf6_lsa_handler *handler;
for (i = 0; i < vector_active(ospf6_lsa_handler_vector); i++) {
handler = vector_slot(ospf6_lsa_handler_vector, i);
if (handler == NULL)
continue;
- if (CHECK_FLAG(handler->debug, OSPF6_LSA_DEBUG))
+ if (CHECK_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG))
vty_out(vty, "debug ospf6 lsa %s\n",
ospf6_lsa_handler_name(handler));
- if (CHECK_FLAG(handler->debug, OSPF6_LSA_DEBUG_ORIGINATE))
+ if (CHECK_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_ORIGINATE))
vty_out(vty, "debug ospf6 lsa %s originate\n",
ospf6_lsa_handler_name(handler));
- if (CHECK_FLAG(handler->debug, OSPF6_LSA_DEBUG_EXAMIN))
+ if (CHECK_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_EXAMIN))
vty_out(vty, "debug ospf6 lsa %s examine\n",
ospf6_lsa_handler_name(handler));
- if (CHECK_FLAG(handler->debug, OSPF6_LSA_DEBUG_FLOOD))
+ if (CHECK_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_FLOOD))
vty_out(vty, "debug ospf6 lsa %s flooding\n",
ospf6_lsa_handler_name(handler));
}