Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add next_hop for dump_route_attrs. #2

Open
wants to merge 1 commit into
base: yanet
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions proto/export/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "lib/lists.h"

#include "proto/bgp/bgp.h"
#include "proto/static/static.h"

#include <stdio.h>
#include <fcntl.h>
Expand Down Expand Up @@ -84,6 +85,19 @@ dump_route_attrs(char *wptr, rte *route)
{
char *attr_start = wptr;
wptr += 4;

struct eattr attr;
attr.id = EA_CODE(PROTOCOL_BGP, BA_NEXT_HOP);

struct {
uint length;
ip_addr addr;
} data;
data.length = sizeof(ip_addr);
data.addr = route->attrs->nh.gw;
attr.u.ptr = (const struct adata *)&data;
wptr = dump_attr_plain_data(wptr, &attr);

struct ea_list *ea = route->attrs->eattrs;
while (ea) {
for (int idx = 0; idx < ea->count; ++idx) {
Expand All @@ -110,7 +124,8 @@ dump_route_attrs(char *wptr, rte *route)
}
ea = ea->next;
}
*(uint32_t *)attr_start = (uint32_t)(wptr - attr_start);

*(uint32_t *)attr_start = (uint32_t)(wptr - attr_start) - 4;
return wptr;
}

Expand Down Expand Up @@ -148,6 +163,13 @@ export_route_size(rte *route)
ea = ea->next;
}

if (route->sender->proto != NULL &&
route->sender->proto->proto != NULL &&
route->sender->proto->proto->class == PROTOCOL_STATIC) {

size += 4 + 4 + sizeof(ip_addr);
}

return size;
}

Expand Down Expand Up @@ -181,7 +203,7 @@ export_rt_notify(struct proto *P, struct channel *src_ch UNUSED,
route->sender->proto->proto->class == PROTOCOL_BGP) {
struct bgp_proto *peer = (struct bgp_proto *)route->sender->proto;
peer_addr = peer->remote_ip;
}
} // TODO: maybe check other protocols for peer_addr

if (write_buf->tpos + export_route_size(route) > write_buf->tbuf + write_buf->size) {
struct export_buf *sock_buf = p->send_buf + (1 - p->send_buf_index);
Expand Down Expand Up @@ -211,7 +233,7 @@ export_rt_notify(struct proto *P, struct channel *src_ch UNUSED,

wptr = dump_route_attrs(wptr, route);

*(uint32_t *)write_buf->tpos = wptr - write_buf->tpos;
*(uint32_t *)write_buf->tpos = wptr - write_buf->tpos - 4;
write_buf->tpos = wptr;

struct export_buf *sock_buf = p->send_buf + (1 - p->send_buf_index);
Expand Down