-
Notifications
You must be signed in to change notification settings - Fork 94
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
RFC add babeld-auto-gw-mode #844
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1aa97c6
babeld-auto-gw-mode: add new package
spiccinini 8503f88
babeld-auto-gw-mode: add ipv6 support
spiccinini 50b7086
babeld-auto-gw-mode: improve Readme
spiccinini 55da336
Revert "babeld-auto-gw-mode: add ipv6 support"
spiccinini 77c4952
babeld-auto-gw-mode: fix Readme typo
spiccinini File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright (C) 2021 Santiago Piccinini <spiccinini@altermundi.net> | ||
# | ||
# This is free software, licensed under the GNU Affero General Public License v3. | ||
# | ||
|
||
include ../../libremesh.mk | ||
|
||
define Package/$(PKG_NAME) | ||
SECTION:=utils | ||
CATEGORY:=Utilities | ||
TITLE:=Babel auto Internet gateway module. | ||
MAINTAINER:=Santiago Piccinini <spiccinini@altermundi.net> | ||
DEPENDS:=+libubus-lua +watchping +lime-proto-babeld | ||
PKGARCH:=all | ||
endef | ||
|
||
|
||
define Package/$(PKG_NAME)/description | ||
Watchping hooks to set babeld Internet automatic announcements. | ||
endef | ||
|
||
$(eval $(call BuildPackage,$(PKG_NAME))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# babeld-auto-gw-mode | ||
|
||
By default babeld will redistribute all the routes installed even if they "don't work". For example | ||
when the internet provider use DHCP and the service is not working but interface is up, the route is | ||
installed but not working and babeld will anounce the non working route to the network and also | ||
this route will be used by this node to route the packets so also all its clients won't have internet. | ||
|
||
This package provides a solution using watchping hooks that: | ||
* on wan OK | ||
- adds a route with a special protocol number (7) | ||
* on wan FAIL | ||
- removes the default route with proto 7 | ||
- changes the metric of the default route to 84831. If other nodes are also gateways their babel | ||
redistributable routes will have priority over this route at this node and for that reason the | ||
default gateway won't be the local non working connection. | ||
|
11 changes: 11 additions & 0 deletions
11
packages/babeld-auto-gw-mode/files/etc/hotplug.d/lime-config/babeld-auto-gw.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/lua | ||
|
||
local config = require("lime.config") | ||
local uci = config.get_uci_cursor() | ||
|
||
-- Redistribute default routes only if they are of protocol 7. | ||
-- This routes are installed and removed using watchping. | ||
|
||
uci:set("babeld", "default4", "proto", "7") | ||
uci:set("babeld", "default6", "proto", "7") | ||
uci:commit("babeld") |
30 changes: 30 additions & 0 deletions
30
packages/babeld-auto-gw-mode/files/etc/watchping/wan-fail.d/babeld-gw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/lua | ||
--! Copyright (C) 2021 Santiago Piccinini <spiccinini@altermundi.net> | ||
--! | ||
--! This is free software, licensed under the GNU Affero General Public License v3. | ||
|
||
local ubus = require "ubus" | ||
local utils = require "lime.utils" | ||
|
||
local NONWORKING_ROUTE_METRIC = 84831 | ||
|
||
local conn = ubus.connect() | ||
if not conn then | ||
error("Failed to connect to ubus") | ||
end | ||
|
||
local wan4_status = conn:call("network.interface.wan", "status", {}) | ||
local wan_ifc = wan4_status.device | ||
|
||
--! Do our best to select only the "original" default route installed. Using grep because | ||
--! using the dev argument removes the dev part of the ip route output. | ||
local route = utils.unsafe_shell("ip route show default metric 0 | grep " .. wan_ifc):gsub("\n","") | ||
|
||
--! replace the default route with one that has metric NONWORKING_ROUTE_METRIC | ||
if route ~= '' then | ||
os.execute("ip r add " .. route .. " metric " .. tonumber(NONWORKING_ROUTE_METRIC)) | ||
os.execute("ip r del " .. route) | ||
end | ||
|
||
--! remove the babel redistributable route | ||
os.execute("ip r del default proto 7") |
30 changes: 30 additions & 0 deletions
30
packages/babeld-auto-gw-mode/files/etc/watchping/wan-ok.d/babeld-gw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/lua | ||
--! Copyright (C) 2021 Santiago Piccinini <spiccinini@altermundi.net> | ||
--! | ||
--! This is free software, licensed under the GNU Affero General Public License v3. | ||
|
||
local ubus = require "ubus" | ||
local utils = require "lime.utils" | ||
|
||
local conn = ubus.connect() | ||
if not conn then | ||
error("Failed to connect to ubus") | ||
end | ||
|
||
local wan4_status = conn:call("network.interface.wan", "status", {}) | ||
local wan_ifc = wan4_status.device | ||
|
||
--! change the default route from the nonworking metric value to the working metric value | ||
local nonworking_route = utils.unsafe_shell("ip route show default metric 84831 | grep " .. wan_ifc):gsub("\n","") | ||
if nonworking_route ~= '' then | ||
os.execute("ip r add " .. nonworking_route .. " metric 0") | ||
os.execute("ip r del " .. nonworking_route .. " metric 84831") | ||
end | ||
|
||
--! install a route with proto value 7 that will be redistributed by babeld | ||
for _, route4 in ipairs(wan4_status.route) do | ||
if route4.target == "0.0.0.0" and route4.mask == 0 then | ||
local r = ("ip r add default via " .. route4.nexthop .. " dev " .. wan4_status.device .. " proto 7 metric 10") | ||
os.execute(r) | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any concrete use of the
lime-config
hotplug.d subdirectory?It looks like a grouping that is not documented, and it is not clear for me if it should be there or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed lime-config hotplug.d documentation is missing, it was introduced in early 2019.
hotplug.d for lime-config is similar to having a generic
run_asset
configured withATCONFIG
but it is enabled just by puting the script in the directory.