Skip to content

Commit

Permalink
bgpdisco: fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
spolack committed Nov 12, 2024
1 parent b66b6c9 commit 24c33e5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/bgpdisco/bgpdisco_nameservice.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ config general
option domain 'ff'
option hosts_file '/var/hosts/ffnameservice'
option cmd_on_update 'killall -SIGHUP dnsmasq'
# list exclude_interface_self '' # Interfaces to be excluded from being elligable for own hostname

#config static-entry
# option host 'sama-xyz'
Expand Down
6 changes: 3 additions & 3 deletions packages/bgpdisco/bird_config_template.ut
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ protocol static static_bgpdisco_v6 {
{% for (let neigh in neighbors): %}
protocol bgp bgpdisco_{{ i++ }}_{{ replace(replace(neigh.iface, '.', '_'), '-', '_') }} {
local as 65000;
debug {states,events};
debug { states };
interface "{{ neigh.iface }}";
neighbor {{ neigh.ip }} as 65000 internal;
rr client yes;
direct;
rr client yes;
ipv4 {
table v4_bgpdisco;
import all;
Expand All @@ -39,7 +39,7 @@ protocol bgp bgpdisco_{{ i++ }}_{{ replace(replace(neigh.iface, '.', '_'), '-',
import all;
export all;
gateway recursive;
next hop address 2001:db8::; # Safe some memory by using IPv4 NH
next hop address 2001:db8::; # TODO: Safe some memory by using IPv4 NH
};
}
{% endfor %}
36 changes: 26 additions & 10 deletions packages/bgpdisco/nameservice.uc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const PLUGIN_UID = 0;
let cfg = {
domain: 'ff',
hosts_file: '/var/hosts/ffnameservice',
cmd_on_update: null
cmd_on_update: null,
exclude_interface_self: []
};

let static_entries = [];
Expand Down Expand Up @@ -55,15 +56,7 @@ function get_local_hosts() {
let result = {};
for (let ip,dev in ips) {
result[ip] ??= [];

name = replace(dev, '.', '_') + '.' + hostname;

// Save first IP if for the case we've got no loopback
if (!first_v4 && is_v4(ip))
first_v4 = ip;

if (!first_v6 && !is_v4(ip))
first_v6 = ip;
let name = replace(dev, '.', '_') + '.' + hostname;

// Strip device from loopback interface first IP
if (dev == 'lo') {
Expand All @@ -74,6 +67,23 @@ function get_local_hosts() {
}

push(result[ip], name);

// Save first IP if for the case we've got no loopback
// while ommiting interfaces which are excluded

DBG('comparing dev=%s against exclude_interface_self=%s', dev, cfg.exclude_interface_self);
if (dev in cfg.exclude_interface_self) {
DBG('Excluding interface....');
continue;
}
if (!first_v4 && is_v4(ip)) {
first_v4 = ip;
DBG('Setting first IPv4: %s, Dev: %s', ip, dev);
}
if (!first_v6 && !is_v4(ip)) {
first_v6 = ip;
DBG('Setting first IPv6: %s, Dev: %s', ip, dev);
}
}

// Add records for the hostname
Expand Down Expand Up @@ -127,6 +137,12 @@ function uci_config() {
cfg.hosts_file = s.hosts_file;
if ('cmd_on_update' in s && s.cmd_on_update)
cfg.cmd_on_update = s.cmd_on_update;
if ('exclude_interface_self' in s)
if (type(s.exclude_interface_self) != 'array') {
ERR('Config exclude_interface_self is not a list - Ignore');
return;
}
cfg.exclude_interface_self = s.exclude_interface_self;
break;
case 'static-entry':
INFO('Loading static host entry - Host: %s, IPs: %s', s.host, s.ip);
Expand Down

0 comments on commit 24c33e5

Please sign in to comment.