-
Notifications
You must be signed in to change notification settings - Fork 326
gluon-setup-mode: allow network-triggered activation #2778
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
blocktrron
wants to merge
4
commits into
freifunk-gluon:main
Choose a base branch
from
blocktrron:remote-setup-mode
base: main
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.
+395
−1
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7d4bb21
gluon-setup-mode: add remote setup-mode
blocktrron 19b4ca0
root: add rule for setup-mode-activation tool
blocktrron 69fadd1
docs: add networked Config-Mode activation process
blocktrron 8dc618f
gluon-autoupdater: add invocation flag
blocktrron 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
/output | ||
/site | ||
/tmp | ||
/tools | ||
/packages | ||
.bash_history | ||
.subversion | ||
|
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
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
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
10 changes: 10 additions & 0 deletions
10
package/gluon-autoupdater/files/lib/preinit/99_autoupdater_invocation
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,10 @@ | ||
#!/bin/sh | ||
|
||
. /lib/gluon/autoupdater/lib.sh | ||
|
||
|
||
autoupdater_invocation_remove() { | ||
# flag_invocation 0 | ||
} | ||
|
||
boot_hook_add preinit_main autoupdater_invocation_remove |
1 change: 1 addition & 0 deletions
1
package/gluon-autoupdater/files/lib/upgrade/keep.d/gluon-autoupdater
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 @@ | ||
/lib/gluon/autoupdater/upgrade-invocation |
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
. /lib/gluon/autoupdater/lib.sh | ||
|
||
flag_invocation 0 | ||
|
||
start_enabled cron | ||
start_enabled urngd | ||
|
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
. /lib/gluon/autoupdater/lib.sh | ||
|
||
flag_invocation 1 | ||
|
||
stop cron | ||
stop urngd | ||
|
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
55 changes: 55 additions & 0 deletions
55
package/gluon-setup-mode/files/lib/preinit/89_network_setup_mode
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,55 @@ | ||
#!/bin/sh | ||
|
||
. /lib/functions.sh | ||
|
||
device_supports_networked_setup_mode() { | ||
local is_networked="$(lua -e 'print(require("gluon.setup-mode").supports_networked_activation())')" | ||
|
||
if [ "${is_networked}" = "true" ]; then | ||
return 0 | ||
fi | ||
|
||
return 1 | ||
} | ||
|
||
should_activate_networked() { | ||
local setup_ifnames="$(lua -e 'print(require("gluon.sysconfig").setup_ifname)')" | ||
local should_start=1 | ||
|
||
if ! device_supports_networked_setup_mode; then | ||
return 1 | ||
fi | ||
|
||
for iface in $setup_ifnames | ||
do | ||
ip link set dev "${iface}" up | ||
done | ||
|
||
# shellcheck disable=SC2086 | ||
if /lib/gluon/setup-mode/wait-network-request ${setup_ifnames}; then | ||
should_start=0 | ||
fi | ||
|
||
for iface in $setup_ifnames | ||
do | ||
ip link set dev "${iface}" down | ||
done | ||
|
||
return $should_start | ||
} | ||
|
||
network_setup_mode_enable() { | ||
local enabled="$(uci -q get 'gluon-setup-mode.@setup_mode[0].enabled')" | ||
local configured="$(uci -q get 'gluon-setup-mode.@setup_mode[0].configured')" | ||
|
||
if [ "$enabled" = 1 ] || [ "$configured" != 1 ]; then | ||
return 0 | ||
fi | ||
|
||
if should_activate_networked; then | ||
uci -q set 'gluon-setup-mode.@setup_mode[0].enabled=1' | ||
fi | ||
return 0 | ||
} | ||
|
||
boot_hook_add preinit_main network_setup_mode_enable |
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
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
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,2 @@ | ||
enter-setup-mode | ||
check-setup-mode | ||
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,16 @@ | ||
CC:=gcc | ||
CFLAGS:= | ||
LDFLAGS:= | ||
|
||
all: wait-network-request send-network-request | ||
|
||
wait-network-request: | ||
$(CC) $(CFLAGS) $(LDFLAGS) -o wait-network-request wait-network-request.c | ||
|
||
send-network-request: | ||
$(CC) $(CFLAGS) $(LDFLAGS) -o send-network-request send-network-request.c | ||
|
||
clean: | ||
rm -rf send-network-request wait-network-request | ||
|
||
.PHONY: clean all |
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,18 @@ | ||
#pragma once | ||
|
||
/* Seconds*/ | ||
#define REMOTE_SETUP_MODE_RX_TIMEOUT 5 | ||
#define REMOTE_SETUP_MODE_TX_INTERVAL 1 | ||
|
||
#define REMOTE_SETUP_MODE_MAC_LEN 6 | ||
#define REMOTE_SETUP_MODE_DST_MAC_OFFSET 0 | ||
#define REMOTE_SETUP_MODE_DST_MAC 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e | ||
#define REMOTE_SETUP_MODE_SRC_MAC_OFFSET 6 | ||
#define REMOTE_SETUP_MODE_SRC_MAC 0xda, 0xec, 0xe5, 0x8f, 0x60, 0x14 | ||
|
||
#define REMOTE_SETUP_MODE_ETHERTYPE_OFFSET (REMOTE_SETUP_MODE_MAC_LEN + REMOTE_SETUP_MODE_MAC_LEN) | ||
#define REMOTE_SETUP_MODE_ETHERTYPE_LEN 2 | ||
#define REMOTE_SETUP_MODE_ETHERTYPE 0x23, 0x42 | ||
|
||
#define REMOTE_SETUP_MODE_DATA_CMD_OFFSET (REMOTE_SETUP_MODE_ETHERTYPE_OFFSET + REMOTE_SETUP_MODE_ETHERTYPE_LEN) | ||
#define REMOTE_SETUP_MODE_DATA_CMD_SETUP "SETUP" |
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,91 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-only */ | ||
|
||
/* | ||
* Utility for performing remote setup-mode activation | ||
* | ||
* Copyright (c) David Bauer <[email protected]> | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <sys/socket.h> | ||
#include <sys/types.h> | ||
#include <unistd.h> | ||
#include <arpa/inet.h> | ||
#include <linux/if_packet.h> | ||
#include <net/ethernet.h> | ||
#include <string.h> | ||
#include <net/if.h> | ||
#include <errno.h> | ||
#include <sys/ioctl.h> | ||
|
||
#include "gluon-remote-setup-mode.h" | ||
|
||
#define LLDP_DELAY (REMOTE_SETUP_MODE_TX_INTERVAL * 1000) | ||
|
||
char buf[] = { | ||
/* Destination - LLDP Multicast */ | ||
REMOTE_SETUP_MODE_DST_MAC, | ||
/* Source */ | ||
REMOTE_SETUP_MODE_SRC_MAC, | ||
/* Type */ | ||
REMOTE_SETUP_MODE_ETHERTYPE, | ||
/* Magic*/ | ||
'S', 'E', 'T', 'U', 'P', | ||
/* Trail */ | ||
0x00, | ||
}; | ||
|
||
int get_ifindex(int sock, const char *ifname) | ||
{ | ||
struct ifreq ifr; | ||
|
||
strncpy((char *)ifr.ifr_name, ifname, IFNAMSIZ); | ||
|
||
if (ioctl(sock, SIOCGIFINDEX, &ifr)) { | ||
printf("IOCTL error: %s\n", strerror(errno)); | ||
return -1; | ||
} | ||
|
||
return ifr.ifr_ifindex; | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
struct sockaddr_ll sll; | ||
int ifindex; | ||
int s_fd; | ||
|
||
if (argc < 2 || !strcmp("help", argv[1])) { | ||
printf("Usage: %s <ifname>\n", argv[0]); | ||
return 1; | ||
} | ||
|
||
s_fd = socket(AF_PACKET,SOCK_RAW,htons(ETH_P_ALL)); | ||
if (s_fd < 0) { | ||
printf("Socket error: %s\n", strerror(errno)); | ||
return 1; | ||
} | ||
|
||
ifindex = get_ifindex(s_fd, argv[1]); | ||
if (ifindex < 0) { | ||
return 1; | ||
} | ||
|
||
memset(&sll, 0, sizeof(sll)); | ||
sll.sll_family = AF_PACKET; | ||
sll.sll_ifindex = ifindex; | ||
|
||
printf("Sending Reset command\n"); | ||
while (1) { | ||
if (sendto(s_fd, buf, sizeof(buf), 0, (struct sockaddr *) &sll, sizeof(sll)) < 0) { | ||
printf("Error sending packet: %s\n", strerror(errno)); | ||
return 1; | ||
} | ||
|
||
usleep(LLDP_DELAY); | ||
} | ||
|
||
close(s_fd); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.
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.
Shouldn't it be
wait-network-request
andsend-network-request
?