Skip to content

Commit

Permalink
Merge branch 'dev' into ospf_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannes Gredler committed Sep 20, 2023
2 parents 6d18e28 + 48eac1d commit f47538a
Show file tree
Hide file tree
Showing 84 changed files with 3,174 additions and 3,030 deletions.
27 changes: 24 additions & 3 deletions code/bngblaster/src/bbl_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1647,13 +1647,22 @@ json_parse_isis_config(json_t *isis, isis_config_s *isis_config)
if(json_is_object(sub)) {

const char *schema[] = {
"mrt-file", "connections"
"purge", "auto-refresh", "mrt-file", "connections"
};
if(!schema_validate(sub, "external", schema,
sizeof(schema)/sizeof(schema[0]))) {
return false;
}


JSON_OBJ_GET_BOOL(sub, value, "isis->external", "purge");
if(value) {
isis_config->external_purge = json_boolean_value(value);
}
JSON_OBJ_GET_BOOL(sub, value, "isis->external", "auto-refresh");
if(value) {
isis_config->external_auto_refresh = json_boolean_value(value);
}

if(json_unpack(sub, "{s:s}", "mrt-file", &s) == 0) {
isis_config->external_mrt_file = strdup(s);
}
Expand Down Expand Up @@ -1703,6 +1712,7 @@ json_parse_isis_config(json_t *isis, isis_config_s *isis_config)
}
}

/* Deprecated / Moved to external->auto-refresh ...*/
JSON_OBJ_GET_BOOL(isis, value, "isis", "external-auto-refresh");
if(value) {
isis_config->external_auto_refresh = json_boolean_value(value);
Expand Down Expand Up @@ -1832,17 +1842,28 @@ json_parse_ospf_config(json_t *ospf, ospf_config_s *ospf_config)
ospf_config->teardown_time = OSPF_DEFAULT_TEARDOWN_TIME;
}

ospf_config->external_purge = true;
sub = json_object_get(ospf, "external");
if(json_is_object(sub)) {

const char *schema[] = {
"mrt-file", "connections"
"purge", "auto-refresh", "mrt-file", "connections"
};
if(!schema_validate(sub, "external", schema,
sizeof(schema)/sizeof(schema[0]))) {
return false;
}

JSON_OBJ_GET_BOOL(sub, value, "ospf->external", "purge");
if(value) {
ospf_config->external_purge = json_boolean_value(value);
}
/* TODO: Currently not supported! */
JSON_OBJ_GET_BOOL(sub, value, "ospf->external", "auto-refresh");
if(value) {
ospf_config->external_auto_refresh = json_boolean_value(value);
}

if(json_unpack(sub, "{s:s}", "mrt-file", &s) == 0) {
ospf_config->external_mrt_file = strdup(s);
}
Expand Down
3 changes: 3 additions & 0 deletions code/bngblaster/src/bbl_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ bbl_ctrl_socket_init()
timer_add_periodic(&g_ctx->timer_root, &ctrl->main.timer, "CTRL Socket Main Timer", 0, 1000 * MSEC, ctrl, &bbl_ctrl_socket_main_job);

LOG(INFO, "Opened control socket %s\n", g_ctx->ctrl_socket_path);

/* Ignore SIGPIPE */
signal(SIGPIPE, SIG_IGN);
return true;
}

Expand Down
6 changes: 6 additions & 0 deletions code/bngblaster/src/bbl_lag.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ bbl_lag_interface_add(bbl_interface_s *interface, bbl_link_config_s *link_config
timer_sec, 0, interface, &bbl_lag_lacp_job);
} else {
member->lacp_state = LACP_DISABLED;
lag->interface->state = INTERFACE_UP;
lag->active_list[lag->active_count++] = member;
lag->select++;
if(CIRCLEQ_EMPTY(&lag->lag_member_qhead)) {
member->primary = true;
}
}

bbl_lag_member_insert(lag, member);
Expand Down
4 changes: 2 additions & 2 deletions code/bngblaster/src/bbl_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ bbl_network_rx_handler(bbl_network_interface_s *interface,
}
bbl_tcp_ipv4_rx(interface, eth, ipv4);
return;
} else if(ipv4->protocol == PROTOCOL_IPV4_OSPF) {
} else if(ipv4->protocol == PROTOCOL_IPV4_OSPF && interface->ospf_interface) {
ospf_handler_rx_ipv4(interface, eth, ipv4);
return;
}
Expand All @@ -488,7 +488,7 @@ bbl_network_rx_handler(bbl_network_interface_s *interface,
}
bbl_tcp_ipv6_rx(interface, eth, ipv6);
return;
} else if(ipv6->protocol == IPV6_NEXT_HEADER_OSPF) {
} else if(ipv6->protocol == IPV6_NEXT_HEADER_OSPF && interface->ospf_interface) {
ospf_handler_rx_ipv6(interface, eth, ipv6);
return;
}
Expand Down
4 changes: 3 additions & 1 deletion code/bngblaster/src/isis/isis.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ isis_teardown()
for(int i=0; i<ISIS_LEVELS; i++) {
if(instance->level[i].adjacency) {
isis_lsp_self_update(instance, i+1);
isis_lsp_purge_all_external(instance, i+1);
if(instance->config->external_purge) {
isis_lsp_purge_all_external(instance, i+1);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions code/bngblaster/src/isis/isis_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ typedef struct isis_config_ {
uint32_t sr_range;
uint32_t sr_node_sid;

/* External */
bool external_purge;
bool external_auto_refresh;
char *external_mrt_file;
struct isis_external_connection_ *external_connection;
Expand Down
4 changes: 3 additions & 1 deletion code/bngblaster/src/ospf/ospf.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ ospf_teardown()
LOG(OSPF, "Teardown OSPFv%u instance %u\n", instance->config->version, instance->config->id);
instance->teardown = true;
ospf_lsa_self_update(instance);
ospf_lsa_purge_all_external(instance);
if(instance->config->external_purge) {
ospf_lsa_purge_all_external(instance);
}
timer_add(&g_ctx->timer_root, &instance->timer_teardown,
"OSPF TEARDOWN", instance->config->teardown_time, 0, instance,
&ospf_teardown_job);
Expand Down
3 changes: 3 additions & 0 deletions code/bngblaster/src/ospf/ospf_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ typedef struct ospf_config_ {

const char *hostname;

/* External */
bool external_purge;
bool external_auto_refresh;
char *external_mrt_file;
struct ospf_external_connection_ *external_connection;

Expand Down
70 changes: 48 additions & 22 deletions code/bngblaster/src/ospf/ospf_lsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,37 @@ ospf_lsa_self_update_request(ospf_instance_s *ospf_instance)
}
}

static protocol_error_t
ospf_lsa_update_pdu_tx(ospf_pdu_s *pdu, uint16_t lsa_count,
ospf_interface_s *ospf_interface,
ospf_neighbor_s *ospf_neighbor)
{
ospf_instance_s *ospf_instance = ospf_interface->instance;
ospf_config_s *config = ospf_instance->config;

if(lsa_count == 0) {
return EMPTY;
}

/* Update LSA count */
if(pdu->pdu_version == OSPF_VERSION_2) {
*(uint32_t*)OSPF_PDU_OFFSET(pdu, OSPFV2_OFFSET_LS_UPDATE_COUNT) = htobe32(lsa_count);
} else {
*(uint32_t*)OSPF_PDU_OFFSET(pdu, OSPFV3_OFFSET_LS_UPDATE_COUNT) = htobe32(lsa_count);
}

/* Update length, auth, checksum and send... */
ospf_pdu_update_len(pdu);
ospf_pdu_update_auth(pdu, config->auth_type, config->auth_key);
ospf_pdu_update_checksum(pdu);
if(ospf_pdu_tx(pdu, ospf_interface, ospf_neighbor) == PROTOCOL_SUCCESS) {
ospf_interface->stats.ls_upd_tx++;
return PROTOCOL_SUCCESS;
} else {
return SEND_ERROR;
}
}

protocol_error_t
ospf_lsa_update_tx(ospf_interface_s *ospf_interface,
ospf_neighbor_s *ospf_neighbor,
Expand All @@ -1031,6 +1062,9 @@ ospf_lsa_update_tx(ospf_interface_s *ospf_interface,
struct timespec ago;
clock_gettime(CLOCK_MONOTONIC, &now);

uint16_t lsa_start_cur;
uint16_t lsa_start_len;

ospf_pdu_s pdu;
ospf_pdu_init(&pdu, OSPF_PDU_LS_UPDATE, ospf_interface->version);

Expand All @@ -1053,6 +1087,8 @@ ospf_lsa_update_tx(ospf_interface_s *ospf_interface,
}
ospf_pdu_add_u32(&pdu, 0); /* skip lsa_count */

lsa_start_cur = pdu.cur;
lsa_start_len = pdu.pdu_len;
for(type=OSPF_LSA_TYPE_1; type < OSPF_LSA_TYPE_MAX; type++) {
if(ospf_neighbor && retry) {
/* Retry. */
Expand All @@ -1069,7 +1105,10 @@ ospf_lsa_update_tx(ospf_interface_s *ospf_interface,
lsa = entry->lsa;
if(lsa && lsa->lsa_len >= OSPF_LSA_HDR_LEN) {
if(lsa_count > 0 && (overhead + pdu.pdu_len + lsa->lsa_len) > interface->mtu) {
break;
ospf_lsa_update_pdu_tx(&pdu, lsa_count, ospf_interface, ospf_neighbor);
pdu.cur = lsa_start_cur;
pdu.pdu_len = lsa_start_len;
lsa_count = 0;
}
ospf_lsa_update_age(entry->lsa, &now);
ospf_pdu_add_bytes(&pdu, lsa->lsa, lsa->lsa_len);
Expand All @@ -1092,7 +1131,10 @@ ospf_lsa_update_tx(ospf_interface_s *ospf_interface,
lsa = entry->lsa;
if(lsa && lsa->lsa_len >= OSPF_LSA_HDR_LEN) {
if(lsa_count > 0 && (overhead + pdu.pdu_len + lsa->lsa_len) > interface->mtu) {
break;
ospf_lsa_update_pdu_tx(&pdu, lsa_count, ospf_interface, ospf_neighbor);
pdu.cur = lsa_start_cur;
pdu.pdu_len = lsa_start_cur;
lsa_count = 0;
}
ospf_lsa_update_age(entry->lsa, &now);
ospf_pdu_add_bytes(&pdu, lsa->lsa, lsa->lsa_len);
Expand All @@ -1103,29 +1145,11 @@ ospf_lsa_update_tx(ospf_interface_s *ospf_interface,
}
}
}
if(lsa_count == 0) {
return EMPTY;
}

/* Update LSA count */
if(ospf_interface->version == OSPF_VERSION_2) {
*(uint32_t*)OSPF_PDU_OFFSET(&pdu, OSPFV2_OFFSET_LS_UPDATE_COUNT) = htobe32(lsa_count);
} else {
*(uint32_t*)OSPF_PDU_OFFSET(&pdu, OSPFV3_OFFSET_LS_UPDATE_COUNT) = htobe32(lsa_count);
}

/* Update length, auth, checksum and send... */
ospf_pdu_update_len(&pdu);
ospf_pdu_update_auth(&pdu, config->auth_type, config->auth_key);
ospf_pdu_update_checksum(&pdu);
if(ospf_pdu_tx(&pdu, ospf_interface, ospf_neighbor) == PROTOCOL_SUCCESS) {
ospf_interface->stats.ls_upd_tx++;
return PROTOCOL_SUCCESS;
} else {
return SEND_ERROR;
}
return ospf_lsa_update_pdu_tx(&pdu, lsa_count, ospf_interface, ospf_neighbor);
}


protocol_error_t
ospf_lsa_req_tx(ospf_interface_s *ospf_interface, ospf_neighbor_s *ospf_neighbor)
{
Expand Down Expand Up @@ -1447,6 +1471,7 @@ ospf_lsa_update_handler_rx(ospf_interface_s *ospf_interface,
lsa->age = be16toh(hdr->age)+1;
lsa->timestamp.tv_sec = now.tv_sec;
lsa->timestamp.tv_nsec = now.tv_sec;
lsa->expired = false;
ospf_lsa_update_age(lsa, &now);
ospf_lsa_flood(lsa);
ospf_lsa_tree_add(lsa, NULL, ospf_interface->lsa_ack_tree[lsa->type]);
Expand Down Expand Up @@ -1693,6 +1718,7 @@ ospf_lsa_load_external(ospf_instance_s *ospf_instance, uint16_t lsa_count, uint8
lsa->age = be16toh(hdr->age);
lsa->timestamp.tv_sec = now.tv_sec;
lsa->timestamp.tv_nsec = now.tv_sec;
lsa->expired = false;
ospf_lsa_update_age(lsa, &now);
ospf_lsa_flood(lsa);
ospf_lsa_lifetime(lsa);
Expand Down
14 changes: 10 additions & 4 deletions code/bngblaster/src/ospf/ospf_neighbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,16 @@ ospf_neighbor_dbd_tx(ospf_neighbor_s *ospf_neighbor)
flags |= OSPF_DBD_FLAG_I;
} else {
/* Add LSA header */
ospf_neighbor->dbd_more = false;
for(type = ospf_neighbor->dbd_lsa_type_start; type < OSPF_LSA_TYPE_MAX; type++) {
itor = hb_itor_new(ospf_instance->lsdb[type]);
next = hb_itor_search_ge(itor, &ospf_neighbor->dbd_lsa_start);
if(type == ospf_neighbor->dbd_lsa_type_start) {
next = hb_itor_search_ge(itor, &ospf_neighbor->dbd_lsa_start);
} else {
next = hb_itor_search_ge(itor, &g_lsa_key_zero);
}
while(true) {
if(!next) {
ospf_neighbor->dbd_more = false;
break;
}
lsa = *hb_itor_datum(itor);
Expand All @@ -98,6 +102,7 @@ ospf_neighbor_dbd_tx(ospf_neighbor_s *ospf_neighbor)
if((overhead + pdu.pdu_len + OSPF_LLS_HDR_LEN + OSPF_LSA_HDR_LEN) > interface->mtu) {
memcpy(&ospf_neighbor->dbd_lsa_next, &lsa->key, sizeof(ospf_lsa_key_s));
ospf_neighbor->dbd_lsa_type_next = type;
ospf_neighbor->dbd_more = true;
break;
}

Expand All @@ -107,7 +112,7 @@ ospf_neighbor_dbd_tx(ospf_neighbor_s *ospf_neighbor)
next = hb_itor_next(itor);
}
hb_itor_free(itor);

if(ospf_neighbor->dbd_more) break;
}
}

Expand Down Expand Up @@ -496,7 +501,6 @@ ospf_neighbor_dbd_rx(ospf_interface_s *ospf_interface,
ospf_neighbor->dbd_lsa_type_start = ospf_neighbor->dbd_lsa_type_next;
memset(&ospf_neighbor->dbd_lsa_next, UINT8_MAX, sizeof(ospf_lsa_key_s));
ospf_neighbor->dbd_lsa_type_next = OSPF_LSA_TYPE_MAX;

ospf_neighbor_dbd_tx(ospf_neighbor);
}
} else {
Expand All @@ -512,7 +516,9 @@ ospf_neighbor_dbd_rx(ospf_interface_s *ospf_interface,
/* Next */
ospf_neighbor->dd = dd;
memcpy(&ospf_neighbor->dbd_lsa_start, &ospf_neighbor->dbd_lsa_next, sizeof(ospf_lsa_key_s));
ospf_neighbor->dbd_lsa_type_start = ospf_neighbor->dbd_lsa_type_next;
memset(&ospf_neighbor->dbd_lsa_next, UINT8_MAX, sizeof(ospf_lsa_key_s));
ospf_neighbor->dbd_lsa_type_next = OSPF_LSA_TYPE_MAX;
ospf_neighbor_dbd_tx(ospf_neighbor);
} else {
ospf_rx_error(interface, pdu, "DD sequence");
Expand Down
38 changes: 22 additions & 16 deletions code/common/src/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,29 @@ timer_set_expire(timer_s *timer, time_t sec, long nsec)
static int
timespec_compare(struct timespec *ts1, struct timespec *ts2)
{
if(ts1->tv_sec < ts2->tv_sec) {
return -1;
}

if(ts1->tv_sec > ts2->tv_sec) {
return +1;
}

if(ts1->tv_nsec < ts2->tv_nsec) {
return -1;
}

if(ts1->tv_nsec > ts2->tv_nsec) {
return +1;
/*
* gcc -O2 does a lot of clever things using setg and setl instructions
* if the hierarchical comparison is done like this:
*
* timespec_compare:
* mov rax, QWORD PTR [rsi]
* cmp QWORD PTR [rdi], rax
* jne .L2
* mov rax, QWORD PTR [rsi+8]
* cmp QWORD PTR [rdi+8], rax
* .L2:
* setg al
* setl dl
* movzx edx, dl
* movzx eax, al
* sub eax, edx
* ret
*/
if (ts1->tv_sec == ts2->tv_sec) {
return (ts1->tv_nsec > ts2->tv_nsec) - (ts1->tv_nsec < ts2->tv_nsec);
} else {
return (ts1->tv_sec > ts2->tv_sec) - (ts1->tv_sec < ts2->tv_sec);
}

return 0;
}

/**
Expand Down
Loading

0 comments on commit f47538a

Please sign in to comment.