mirror of
https://github.com/rtbrick/bngblaster.git
synced 2024-05-06 15:54:57 +00:00
add config for LDP TOS / BGP TOS & TTL
This commit is contained in:
@@ -1302,7 +1302,7 @@ json_parse_bgp_config(json_t *bgp, bgp_config_s *bgp_config)
|
||||
|
||||
const char *schema[] = {
|
||||
"network-interface", "local-ipv4-address", "peer-ipv4-address",
|
||||
"local-as", "peer-as", "hold-time",
|
||||
"local-as", "peer-as", "hold-time", "tos", "ttl",
|
||||
"id", "reconnect", "start-traffic",
|
||||
"teardown-time", "raw-update-file"
|
||||
};
|
||||
@@ -1354,6 +1354,16 @@ json_parse_bgp_config(json_t *bgp, bgp_config_s *bgp_config)
|
||||
bgp_config->hold_time = BGP_DEFAULT_HOLD_TIME;
|
||||
}
|
||||
|
||||
value = json_object_get(bgp, "tos");
|
||||
if(json_is_number(value)) {
|
||||
bgp_config->tos = json_number_value(value);
|
||||
}
|
||||
|
||||
value = json_object_get(bgp, "ttl");
|
||||
if(json_is_number(value)) {
|
||||
bgp_config->ttl = json_number_value(value);
|
||||
}
|
||||
|
||||
bgp_config->id = htobe32(0x01020304);
|
||||
if(json_unpack(bgp, "{s:s}", "id", &s) == 0) {
|
||||
if(!inet_pton(AF_INET, s, &bgp_config->id)) {
|
||||
@@ -1999,7 +2009,7 @@ json_parse_ldp_config(json_t *ldp, ldp_config_s *ldp_config)
|
||||
|
||||
const char *schema[] = {
|
||||
"instance-id", "keepalive-time", "hold-time",
|
||||
"teardown-time", "hostname", "lsr-id",
|
||||
"teardown-time", "hostname", "lsr-id", "tos",
|
||||
"ipv6-transport-address", "ipv4-transport-address",
|
||||
"no-ipv4-transport", "prefer-ipv4-transport",
|
||||
"raw-update-file"
|
||||
@@ -2086,6 +2096,12 @@ json_parse_ldp_config(json_t *ldp, ldp_config_s *ldp_config)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
value = json_object_get(ldp, "tos");
|
||||
if(json_is_number(value)) {
|
||||
ldp_config->tos = json_number_value(value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -99,12 +99,12 @@ bbl_http_server_start(bbl_network_interface_s *network_interface,
|
||||
server->listen_tcpc = bbl_tcp_ipv4_listen(
|
||||
network_interface,
|
||||
&config->ipv4_address,
|
||||
config->port);
|
||||
config->port, 0, 0);
|
||||
} else {
|
||||
server->listen_tcpc = bbl_tcp_ipv6_listen(
|
||||
network_interface,
|
||||
&config->ipv6_address,
|
||||
config->port);
|
||||
config->port, 0, 0);
|
||||
}
|
||||
if(!server->listen_tcpc) {
|
||||
free(server);
|
||||
|
||||
@@ -340,6 +340,14 @@ bbl_tcp_listen_accepted(void *arg, struct tcp_pcb *tpcb, err_t err)
|
||||
tcpc->poll_interval = listen->poll_interval;
|
||||
tcpc->arg = listen->arg;
|
||||
|
||||
/* Copy TTL and TOS from listen socket. */
|
||||
if(listen->pcb) {
|
||||
if(listen->pcb->ttl) {
|
||||
tpcb->ttl = listen->pcb->ttl;
|
||||
}
|
||||
tpcb->tos = listen->pcb->tos;
|
||||
}
|
||||
|
||||
tcpc->pcb = tpcb;
|
||||
tcp_arg(tpcb, tcpc);
|
||||
|
||||
@@ -391,10 +399,13 @@ bbl_tcp_listen_accepted(void *arg, struct tcp_pcb *tpcb, err_t err)
|
||||
* @param interface interface
|
||||
* @param address local address
|
||||
* @param port local port
|
||||
* @param ttl TTL
|
||||
* @param tos TOS
|
||||
* @return TCP context
|
||||
*/
|
||||
bbl_tcp_ctx_s *
|
||||
bbl_tcp_ipv4_listen(bbl_network_interface_s *interface, ipv4addr_t *address, uint16_t port)
|
||||
bbl_tcp_ipv4_listen(bbl_network_interface_s *interface, ipv4addr_t *address,
|
||||
uint16_t port, uint8_t ttl, uint8_t tos)
|
||||
{
|
||||
bbl_tcp_ctx_s *tcpc;
|
||||
|
||||
@@ -428,6 +439,10 @@ bbl_tcp_ipv4_listen(bbl_network_interface_s *interface, ipv4addr_t *address, uin
|
||||
tcpc->local_port = port;
|
||||
tcpc->pcb->local_ip.type = IPADDR_TYPE_V4;
|
||||
tcpc->pcb->remote_ip.type = IPADDR_TYPE_V4;
|
||||
if(ttl) {
|
||||
tcpc->pcb->ttl = ttl;
|
||||
}
|
||||
tcpc->pcb->tos = tos;
|
||||
tcpc->state = BBL_TCP_STATE_LISTEN;
|
||||
LOG(TCP, "TCP (%s %s:%u) listen\n",
|
||||
tcpc->ifname,
|
||||
@@ -443,10 +458,13 @@ bbl_tcp_ipv4_listen(bbl_network_interface_s *interface, ipv4addr_t *address, uin
|
||||
* @param interface interface
|
||||
* @param address local address
|
||||
* @param port local port
|
||||
* @param ttl TTL
|
||||
* @param tos TOS
|
||||
* @return TCP context
|
||||
*/
|
||||
bbl_tcp_ctx_s *
|
||||
bbl_tcp_ipv6_listen(bbl_network_interface_s *interface, ipv6addr_t *address, uint16_t port)
|
||||
bbl_tcp_ipv6_listen(bbl_network_interface_s *interface, ipv6addr_t *address,
|
||||
uint16_t port, uint8_t ttl, uint8_t tos)
|
||||
{
|
||||
bbl_tcp_ctx_s *tcpc;
|
||||
|
||||
@@ -482,6 +500,10 @@ bbl_tcp_ipv6_listen(bbl_network_interface_s *interface, ipv6addr_t *address, uin
|
||||
tcpc->remote_addr.type = IPADDR_TYPE_V6;
|
||||
tcpc->pcb->local_ip.type = IPADDR_TYPE_V6;
|
||||
tcpc->pcb->remote_ip.type = IPADDR_TYPE_V6;
|
||||
if(ttl) {
|
||||
tcpc->pcb->ttl = ttl;
|
||||
}
|
||||
tcpc->pcb->tos = tos;
|
||||
tcpc->state = BBL_TCP_STATE_LISTEN;
|
||||
LOG(TCP, "TCP (%s %s:%u) listen\n",
|
||||
tcpc->ifname,
|
||||
@@ -498,10 +520,13 @@ bbl_tcp_ipv6_listen(bbl_network_interface_s *interface, ipv6addr_t *address, uin
|
||||
* @param src source address
|
||||
* @param dst destination address
|
||||
* @param port destination port
|
||||
* @param ttl TTL
|
||||
* @param tos TOS
|
||||
* @return TCP context
|
||||
*/
|
||||
bbl_tcp_ctx_s *
|
||||
bbl_tcp_ipv4_connect(bbl_network_interface_s *interface, ipv4addr_t *src, ipv4addr_t *dst, uint16_t port)
|
||||
bbl_tcp_ipv4_connect(bbl_network_interface_s *interface, ipv4addr_t *src, ipv4addr_t *dst,
|
||||
uint16_t port, uint8_t ttl, uint8_t tos)
|
||||
{
|
||||
bbl_tcp_ctx_s *tcpc;
|
||||
|
||||
@@ -522,6 +547,12 @@ bbl_tcp_ipv4_connect(bbl_network_interface_s *interface, ipv4addr_t *src, ipv4ad
|
||||
/* Disable nagle algorithm */
|
||||
tcp_nagle_disable(tcpc->pcb);
|
||||
|
||||
/* Set TTL and TOS */
|
||||
if(ttl) {
|
||||
tcpc->pcb->ttl = ttl;
|
||||
}
|
||||
tcpc->pcb->tos = tos;
|
||||
|
||||
/* Connect session */
|
||||
tcpc->remote_addr.u_addr.ip4.addr = *dst;
|
||||
if(tcp_connect(tcpc->pcb, &tcpc->remote_addr, port, bbl_tcp_connected) != ERR_OK) {
|
||||
@@ -556,7 +587,8 @@ bbl_tcp_ipv4_connect(bbl_network_interface_s *interface, ipv4addr_t *src, ipv4ad
|
||||
* @return TCP context
|
||||
*/
|
||||
bbl_tcp_ctx_s *
|
||||
bbl_tcp_ipv4_connect_session(bbl_session_s *session, ipv4addr_t *src, ipv4addr_t *dst, uint16_t port)
|
||||
bbl_tcp_ipv4_connect_session(bbl_session_s *session, ipv4addr_t *src, ipv4addr_t *dst,
|
||||
uint16_t port)
|
||||
{
|
||||
bbl_tcp_ctx_s *tcpc;
|
||||
|
||||
@@ -612,10 +644,13 @@ bbl_tcp_ipv4_connect_session(bbl_session_s *session, ipv4addr_t *src, ipv4addr_t
|
||||
* @param src source address
|
||||
* @param dst destination address
|
||||
* @param port destination port
|
||||
* @param ttl TTL
|
||||
* @param tos TOS
|
||||
* @return TCP context
|
||||
*/
|
||||
bbl_tcp_ctx_s *
|
||||
bbl_tcp_ipv6_connect(bbl_network_interface_s *interface, ipv6addr_t *src, ipv6addr_t *dst, uint16_t port)
|
||||
bbl_tcp_ipv6_connect(bbl_network_interface_s *interface, ipv6addr_t *src, ipv6addr_t *dst,
|
||||
uint16_t port, uint8_t ttl, uint8_t tos)
|
||||
{
|
||||
bbl_tcp_ctx_s *tcpc;
|
||||
|
||||
@@ -637,6 +672,12 @@ bbl_tcp_ipv6_connect(bbl_network_interface_s *interface, ipv6addr_t *src, ipv6ad
|
||||
/* Disable nagle algorithm */
|
||||
tcp_nagle_disable(tcpc->pcb);
|
||||
|
||||
/* Set TTL and TOS */
|
||||
if(ttl) {
|
||||
tcpc->pcb->ttl = ttl;
|
||||
}
|
||||
tcpc->pcb->tos = tos;
|
||||
|
||||
/* Connect session */
|
||||
memcpy(&tcpc->remote_addr.u_addr.ip6.addr, dst, sizeof(ip6_addr_t));
|
||||
tcpc->remote_addr.type = IPADDR_TYPE_V6;
|
||||
@@ -672,7 +713,8 @@ bbl_tcp_ipv6_connect(bbl_network_interface_s *interface, ipv6addr_t *src, ipv6ad
|
||||
* @return TCP context
|
||||
*/
|
||||
bbl_tcp_ctx_s *
|
||||
bbl_tcp_ipv6_connect_session(bbl_session_s *session, ipv6addr_t *src, ipv6addr_t *dst, uint16_t port)
|
||||
bbl_tcp_ipv6_connect_session(bbl_session_s *session, ipv6addr_t *src, ipv6addr_t *dst,
|
||||
uint16_t port)
|
||||
{
|
||||
bbl_tcp_ctx_s *tcpc;
|
||||
|
||||
|
||||
@@ -88,22 +88,28 @@ void
|
||||
bbl_tcp_ctx_free(bbl_tcp_ctx_s *tcpc);
|
||||
|
||||
bbl_tcp_ctx_s *
|
||||
bbl_tcp_ipv4_listen(bbl_network_interface_s *interface, ipv4addr_t *address, uint16_t port);
|
||||
bbl_tcp_ipv4_listen(bbl_network_interface_s *interface, ipv4addr_t *address,
|
||||
uint16_t port, uint8_t ttl, uint8_t tos);
|
||||
|
||||
bbl_tcp_ctx_s *
|
||||
bbl_tcp_ipv6_listen(bbl_network_interface_s *interface, ipv6addr_t *address, uint16_t port);
|
||||
bbl_tcp_ipv6_listen(bbl_network_interface_s *interface, ipv6addr_t *address,
|
||||
uint16_t port, uint8_t ttl, uint8_t tos);
|
||||
|
||||
bbl_tcp_ctx_s *
|
||||
bbl_tcp_ipv4_connect(bbl_network_interface_s *interface, ipv4addr_t *src, ipv4addr_t *dst, uint16_t port);
|
||||
bbl_tcp_ipv4_connect(bbl_network_interface_s *interface, ipv4addr_t *src, ipv4addr_t *dst,
|
||||
uint16_t port, uint8_t ttl, uint8_t tos);
|
||||
|
||||
bbl_tcp_ctx_s *
|
||||
bbl_tcp_ipv4_connect_session(bbl_session_s *session, ipv4addr_t *src, ipv4addr_t *dst, uint16_t port);
|
||||
bbl_tcp_ipv4_connect_session(bbl_session_s *session, ipv4addr_t *src, ipv4addr_t *dst,
|
||||
uint16_t port);
|
||||
|
||||
bbl_tcp_ctx_s *
|
||||
bbl_tcp_ipv6_connect(bbl_network_interface_s *interface, ipv6addr_t *src, ipv6addr_t *dst, uint16_t port);
|
||||
bbl_tcp_ipv6_connect(bbl_network_interface_s *interface, ipv6addr_t *src, ipv6addr_t *dst,
|
||||
uint16_t port, uint8_t ttl, uint8_t tos);
|
||||
|
||||
bbl_tcp_ctx_s *
|
||||
bbl_tcp_ipv6_connect_session(bbl_session_s *session, ipv6addr_t *src, ipv6addr_t *dst, uint16_t port);
|
||||
bbl_tcp_ipv6_connect_session(bbl_session_s *session, ipv6addr_t *src, ipv6addr_t *dst,
|
||||
uint16_t port);
|
||||
|
||||
void
|
||||
bbl_tcp_ipv4_rx(bbl_network_interface_s *interface, bbl_ethernet_header_s *eth, bbl_ipv4_s *ipv4);
|
||||
|
||||
@@ -60,6 +60,8 @@ typedef struct bgp_config_ {
|
||||
uint32_t peer_as;
|
||||
uint16_t hold_time;
|
||||
uint16_t teardown_time;
|
||||
uint8_t tos; /* IPv4 TOS or IPv6 TC */
|
||||
uint8_t ttl; /* IPv4 TOS or IPv6 TC */
|
||||
|
||||
bool reconnect;
|
||||
bool start_traffic;
|
||||
|
||||
@@ -271,7 +271,9 @@ bgp_session_connect_job(timer_s *timer)
|
||||
session->interface,
|
||||
&session->ipv4_local_address,
|
||||
&session->ipv4_peer_address,
|
||||
BGP_PORT);
|
||||
BGP_PORT,
|
||||
session->config->ttl,
|
||||
session->config->tos);
|
||||
|
||||
if(session->tcpc) {
|
||||
session->tcpc->arg = session;
|
||||
|
||||
@@ -156,6 +156,7 @@ typedef struct ldp_config_ {
|
||||
uint16_t keepalive_time;
|
||||
uint16_t hold_time;
|
||||
uint16_t teardown_time;
|
||||
uint8_t tos; /* IPv4 TOS or IPv6 TC */
|
||||
|
||||
char *raw_update_file;
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ ldp_hello_ipv4_encode(bbl_network_interface_s *interface,
|
||||
ipv4.dst = IPV4_MC_ALL_ROUTERS;
|
||||
ipv4.src = interface->ip.address;
|
||||
ipv4.ttl = 1;
|
||||
ipv4.tos = config->tos;
|
||||
ipv4.protocol = PROTOCOL_IPV4_UDP;
|
||||
ipv4.next = &udp;
|
||||
udp.src = LDP_PORT;
|
||||
@@ -89,6 +90,7 @@ ldp_hello_ipv6_encode(bbl_network_interface_s *interface,
|
||||
ipv6.protocol = IPV6_NEXT_HEADER_UDP;
|
||||
ipv6.next = &udp;
|
||||
ipv6.ttl = 255;
|
||||
ipv6.tos = config->tos;
|
||||
udp.src = LDP_PORT;
|
||||
udp.dst = LDP_PORT;
|
||||
udp.protocol = UDP_PROTOCOL_LDP;
|
||||
|
||||
@@ -322,13 +322,15 @@ ldp_session_connect_job(timer_s *timer)
|
||||
session->interface,
|
||||
&session->local.ipv6_address,
|
||||
&session->peer.ipv6_address,
|
||||
LDP_PORT);
|
||||
LDP_PORT,
|
||||
0, session->instance->config->tos);
|
||||
} else {
|
||||
session->tcpc = bbl_tcp_ipv4_connect(
|
||||
session->interface,
|
||||
&session->local.ipv4_address,
|
||||
&session->peer.ipv4_address,
|
||||
LDP_PORT);
|
||||
LDP_PORT,
|
||||
0, session->instance->config->tos);
|
||||
}
|
||||
|
||||
if(session->tcpc) {
|
||||
@@ -370,12 +372,14 @@ ldp_session_listen(ldp_session_s *session)
|
||||
session->listen_tcpc = bbl_tcp_ipv6_listen(
|
||||
session->interface,
|
||||
&session->local.ipv6_address,
|
||||
LDP_PORT);
|
||||
LDP_PORT,
|
||||
0, session->instance->config->tos);
|
||||
} else {
|
||||
session->listen_tcpc = bbl_tcp_ipv4_listen(
|
||||
session->interface,
|
||||
&session->local.ipv4_address,
|
||||
LDP_PORT);
|
||||
LDP_PORT,
|
||||
0, session->instance->config->tos);
|
||||
}
|
||||
|
||||
if(session->listen_tcpc) {
|
||||
@@ -384,7 +388,6 @@ ldp_session_listen(ldp_session_s *session)
|
||||
session->listen_tcpc->connected_cb = ldp_connected_cb;
|
||||
session->listen_tcpc->receive_cb = ldp_receive_cb;
|
||||
session->listen_tcpc->error_cb = ldp_error_cb;
|
||||
|
||||
ldp_session_state_change(session, LDP_LISTEN);
|
||||
timer_add_periodic(&g_ctx->timer_root, &session->connect_timer,
|
||||
"LDP CONNECT", 60, 0, session,
|
||||
|
||||
Reference in New Issue
Block a user