-
-
Notifications
You must be signed in to change notification settings - Fork 114
odhcpd lease sharing via shared-state #1199
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
Open
AguTrachta
wants to merge
19
commits into
libremesh:master
Choose a base branch
from
matterod:feature/odhcpd-leases
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ec26665
feat: makefile for odhcpd leases package
AguTrachta e055f96
feat: uci defaults
AguTrachta 8d64b58
feat: added the hook that generates the /tmp/ethers.mesh for the data…
AguTrachta 7e0ec94
feat: created publisher that acts as the leasertrigger for odhcpd
AguTrachta 5abe425
chore: minimal correction in package's description
AguTrachta c34041d
Update from master
AguTrachta 6ced399
fix: structure changed for new shared state async
AguTrachta 2aa01ac
fix: updated names inside hook
AguTrachta c2b8d7c
chore: added uci-defaults registration
AguTrachta 91608bb
chore: granted execution permissions
AguTrachta b022801
chore: deleted redundant cron block
AguTrachta 7abf03c
test: add odhcpd-leases publisher unit tests
matterod 50b59d3
test: add odhcpd-leases publisher unit tests
matterod d3114d7
Test: deleted binary files
matterod 40c6825
docs: added README for guidance of testing this package
AguTrachta daca428
docs: update README
AguTrachta 33ee0f4
fix: set leasertrigger to absolute path
AguTrachta 81b6842
fix: replace existing /etc/ethers with symlink
AguTrachta 7428c1b
fix: typo error corrected from 'odchpd' to 'odhcpd'
AguTrachta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,17 @@ | ||
| include ../../libremesh.mk | ||
|
|
||
| define Package/$(PKG_NAME) | ||
| SECTION:=lime | ||
| CATEGORY:=LibreMesh | ||
| TITLE:=odhcpd leases module for shared-state | ||
| DEPENDS:=+lua +luci-lib-jsonc +shared-state-async +odhcpd | ||
| PKGARCH:=all | ||
| endef | ||
|
|
||
| define Package/$(PKG_NAME)/description | ||
| Synchronize external DHCP leases between LibreMesh nodes by | ||
| watching odhcpd’s lease file, publishing updates over shared-state-async | ||
| and injecting remote leases locally. | ||
| endef | ||
|
|
||
| $(eval $(call BuildPackage,$(PKG_NAME))) |
23 changes: 23 additions & 0 deletions
23
packages/shared-state-odhcpd_leases/files/etc/uci-defaults/90_odhcpd-lease-share
This file contains hidden or 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,23 @@ | ||
| #!/bin/sh | ||
| CRDT='odhcpd-leases' | ||
| LEASEFILE='/tmp/ethers.mesh' | ||
| TRIGGERFILE='usr/share/shared-state/publishers/shared-state-publish_odhcpd_leases' | ||
| mSc='odhcpd_leases' | ||
|
|
||
| uci -q set shared-state.$mSc=dataType | ||
| uci -q set shared-state.$mSc.name="$CRDT" | ||
| uci -q set shared-state.$mSc.scope='community' | ||
| uci -q set shared-state.$mSc.update_interval='120' | ||
| uci -q set shared-state.$mSc.ttl='1200' | ||
| uci commit shared-state | ||
|
|
||
| uci -q set dhcp.odhcpd.leasetrigger="$TRIGGERFILE" | ||
| uci -q set dhcp.odhcpd.maindhcp='1' | ||
| uci commit dhcp | ||
|
|
||
| [ -e /etc/ethers ] || ln -s "$LEASEFILE" /etc/ethers | ||
| grep -q 'sync odhcpd-leases' /etc/crontabs/root || \ | ||
| echo '*/5 * * * * shared-state-async sync odhcpd-leases >/dev/null 2>&1' >> /etc/crontabs/root | ||
|
|
||
| /etc/init.d/cron restart | ||
| /etc/init.d/odhcpd reload | ||
25 changes: 25 additions & 0 deletions
25
...ases/files/usr/share/shared-state/hooks/odhcpd-leases/shared-state-generate_odhcpd_leases
This file contains hidden or 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,25 @@ | ||
| #!/usr/bin/lua | ||
|
|
||
| local JSON = require('luci.jsonc') | ||
|
|
||
| local OUTPUT_FILE = '/tmp/ethers.mesh' | ||
| local TMP_FILE = OUTPUT_FILE .. '.new' | ||
|
|
||
| local leases = JSON.parse(io.stdin:read('*a')) or {} | ||
|
|
||
| local hostname_file = io.open('/proc/sys/kernel/hostname') | ||
| local node_hostname = hostname_file:read('*l') | ||
| hostname_file:close() | ||
|
|
||
| local out_handle = io.open(TMP_FILE, 'w') | ||
|
|
||
| for ip, data in pairs(leases) do | ||
|
|
||
| if data and data.mData and data.mData.mac and data.mAuthor ~= node_hostname then | ||
| out_handle:write(string.format('%s %s\n', data.mData.mac, ip)) -- Format: MAC IP | ||
| end | ||
| end | ||
| out_handle:close() | ||
| os.execute('mv "' .. TMP_FILE .. '" "' .. OUTPUT_FILE .. '"') | ||
|
|
||
| os.execute('/etc/init.d/odhcpd reload') |
47 changes: 47 additions & 0 deletions
47
...-odhcpd_leases/files/usr/share/shared-state/publishers/shared-state-publish_odhcpd_leases
This file contains hidden or 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,47 @@ | ||
| #!/usr/bin/lua | ||
|
|
||
| local JSON = require("luci.jsonc") | ||
| local CRDT = "odhcpd-leases" | ||
|
|
||
|
|
||
| local handle = io.popen("ubus call dhcp ipv4leases '{}' 2>/dev/null") | ||
| local ubus_output = handle:read("*a") | ||
| handle:close() | ||
|
|
||
|
|
||
| local ubus_data = JSON.parse(ubus_output or "{}") | ||
|
|
||
| local output_table = {} | ||
|
|
||
|
|
||
| if ubus_data and ubus_data.device then | ||
|
|
||
| for device_name, device_data in pairs(ubus_data.device) do | ||
| if device_data and device_data.leases then | ||
|
|
||
| for _, lease in ipairs(device_data.leases) do | ||
|
|
||
| if lease.address and lease.mac then | ||
|
|
||
| output_table[lease.address] = { | ||
| hostname = lease.hostname or "", | ||
| mac = lease.mac | ||
| } | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
|
|
||
| local final_json_string = JSON.stringify(output_table) | ||
|
|
||
|
|
||
| local pipe = io.popen("shared-state-async insert " .. CRDT, "w") | ||
| if pipe then | ||
| pipe:write(final_json_string) | ||
| pipe:close() | ||
| end | ||
|
|
||
|
|
||
| os.execute("/usr/sbin/odhcpd-update >/dev/null 2>&1") |
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.
Uh oh!
There was an error while loading. Please reload this page.