Compare commits
8 Commits
aecbe08f08
...
44c1fb7632
Author | SHA1 | Date | |
---|---|---|---|
44c1fb7632 | |||
e577caa15f | |||
7faf620c0b | |||
b094220466 | |||
f1dfb1f976 | |||
333327be75 | |||
efa1919e04 | |||
de77635490 |
@ -204,8 +204,6 @@
|
|||||||
|
|
||||||
PARTITION_ADVANCED = "y";
|
PARTITION_ADVANCED = "y";
|
||||||
PRINTK_TIME = "y";
|
PRINTK_TIME = "y";
|
||||||
SQUASHFS = "y";
|
|
||||||
SQUASHFS_XZ = "y";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -55,25 +55,38 @@
|
|||||||
"${openwrt.src}/target/linux/ramips/dts"
|
"${openwrt.src}/target/linux/ramips/dts"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
networkInterfaces = rec {
|
networkInterfaces =
|
||||||
|
let
|
||||||
|
inherit (config.system.service.network) link;
|
||||||
|
inherit (config.system.service) vlan;
|
||||||
|
inherit (pkgs.liminix.services) oneshot;
|
||||||
|
swconfig = oneshot {
|
||||||
|
name = "swconfig";
|
||||||
|
up = ''
|
||||||
|
PATH=${pkgs.swconfig}/bin:$PATH
|
||||||
|
swconfig dev switch0 set reset
|
||||||
|
swconfig dev switch0 set enable_vlan 1
|
||||||
|
swconfig dev switch0 vlan 1 set ports '1 2 3 4 6t'
|
||||||
|
swconfig dev switch0 vlan 2 set ports '0 6t'
|
||||||
|
swconfig dev switch0 set apply
|
||||||
|
'';
|
||||||
|
down = "swconfig dev switch0 set reset";
|
||||||
|
};
|
||||||
|
in rec {
|
||||||
|
eth = link.build { ifname = "eth0"; dependencies = [swconfig]; };
|
||||||
# lan and wan ports are both behind a switch on eth0
|
# lan and wan ports are both behind a switch on eth0
|
||||||
eth = interface { device = "eth0"; };
|
lan = vlan.build {
|
||||||
lan = interface {
|
ifname = "eth0.1";
|
||||||
type = "vlan";
|
primary = eth;
|
||||||
device = "eth0.1";
|
vid = "1";
|
||||||
link = "eth0";
|
|
||||||
id = "1";
|
|
||||||
dependencies = [eth];
|
|
||||||
};
|
};
|
||||||
wan = interface {
|
wan = vlan.build {
|
||||||
type = "vlan";
|
ifname = "eth0.2";
|
||||||
device = "eth0.2";
|
primary = eth;
|
||||||
id = "2";
|
vid = "2";
|
||||||
link = "eth0";
|
|
||||||
dependencies = [eth];
|
|
||||||
};
|
};
|
||||||
wlan = interface {
|
wlan = link.build {
|
||||||
device = "wlan0";
|
ifname = "wlan0";
|
||||||
dependencies = [ mac80211 ];
|
dependencies = [ mac80211 ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -115,6 +128,7 @@
|
|||||||
NET_RALINK_MDIO = "y";
|
NET_RALINK_MDIO = "y";
|
||||||
NET_RALINK_MDIO_MT7620 = "y";
|
NET_RALINK_MDIO_MT7620 = "y";
|
||||||
NET_RALINK_MT7620 = "y";
|
NET_RALINK_MT7620 = "y";
|
||||||
|
SWPHY = "y";
|
||||||
|
|
||||||
SPI = "y";
|
SPI = "y";
|
||||||
MTD_SPI_NOR = "y";
|
MTD_SPI_NOR = "y";
|
||||||
@ -123,18 +137,6 @@
|
|||||||
SPI_MASTER= "y";
|
SPI_MASTER= "y";
|
||||||
SPI_MEM= "y";
|
SPI_MEM= "y";
|
||||||
|
|
||||||
# both the ethernet ports on this device (lan and wan)
|
|
||||||
# are behind a switch, so we need VLANs to do anything
|
|
||||||
# useful with them
|
|
||||||
|
|
||||||
VLAN_8021Q = "y";
|
|
||||||
SWCONFIG = "y";
|
|
||||||
SWPHY = "y";
|
|
||||||
|
|
||||||
BRIDGE = "y";
|
|
||||||
BRIDGE_VLAN_FILTERING = "y";
|
|
||||||
BRIDGE_IGMP_SNOOPING = "y";
|
|
||||||
|
|
||||||
MTD = "y";
|
MTD = "y";
|
||||||
MTD_CMDLINE_PARTS = "y";
|
MTD_CMDLINE_PARTS = "y";
|
||||||
MTD_BLOCK = "y"; # fix undefined ref to register_mtd_blktrans_devs
|
MTD_BLOCK = "y"; # fix undefined ref to register_mtd_blktrans_devs
|
||||||
@ -149,8 +151,6 @@
|
|||||||
|
|
||||||
PARTITION_ADVANCED = "y";
|
PARTITION_ADVANCED = "y";
|
||||||
PRINTK_TIME = "y";
|
PRINTK_TIME = "y";
|
||||||
SQUASHFS = "y";
|
|
||||||
SQUASHFS_XZ = "y";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -52,10 +52,11 @@
|
|||||||
"${openwrt.src}/target/linux/ramips/dts"
|
"${openwrt.src}/target/linux/ramips/dts"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
networkInterfaces = rec {
|
networkInterfaces =
|
||||||
# lan and wan ports are both behind a switch on eth0
|
let
|
||||||
eth =
|
inherit (config.system.service.network) link;
|
||||||
let swconfig = oneshot {
|
inherit (config.system.service) vlan;
|
||||||
|
swconfig = oneshot {
|
||||||
name = "swconfig";
|
name = "swconfig";
|
||||||
up = ''
|
up = ''
|
||||||
PATH=${pkgs.swconfig}/bin:$PATH
|
PATH=${pkgs.swconfig}/bin:$PATH
|
||||||
@ -67,26 +68,21 @@
|
|||||||
'';
|
'';
|
||||||
down = "swconfig dev switch0 set reset";
|
down = "swconfig dev switch0 set reset";
|
||||||
};
|
};
|
||||||
in interface {
|
in rec {
|
||||||
device = "eth0";
|
eth = link.build { ifname = "eth0"; dependencies = [swconfig]; };
|
||||||
dependencies = [swconfig];
|
# lan and wan ports are both behind a switch on eth0
|
||||||
|
lan = vlan.build {
|
||||||
|
ifname = "eth0.1";
|
||||||
|
primary = eth;
|
||||||
|
vid = "1";
|
||||||
};
|
};
|
||||||
lan = interface {
|
wan = vlan.build {
|
||||||
type = "vlan";
|
ifname = "eth0.2";
|
||||||
device = "eth0.1";
|
primary = eth;
|
||||||
link = "eth0";
|
vid = "2";
|
||||||
id = "1";
|
|
||||||
dependencies = [eth];
|
|
||||||
};
|
};
|
||||||
wan = interface {
|
wlan = link.build {
|
||||||
type = "vlan";
|
ifname = "wlan0";
|
||||||
device = "eth0.2";
|
|
||||||
id = "2";
|
|
||||||
link = "eth0";
|
|
||||||
dependencies = [eth];
|
|
||||||
};
|
|
||||||
wlan = interface {
|
|
||||||
device = "wlan0";
|
|
||||||
dependencies = [ mac80211 ];
|
dependencies = [ mac80211 ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -148,19 +144,8 @@
|
|||||||
NET_VENDOR_RALINK = "y";
|
NET_VENDOR_RALINK = "y";
|
||||||
NET_RALINK_RT3050 = "y";
|
NET_RALINK_RT3050 = "y";
|
||||||
NET_RALINK_SOC="y";
|
NET_RALINK_SOC="y";
|
||||||
|
|
||||||
# both the ethernet ports on this device (lan and wan)
|
|
||||||
# are behind a switch, so we need VLANs to do anything
|
|
||||||
# useful with them
|
|
||||||
|
|
||||||
VLAN_8021Q = "y";
|
|
||||||
SWCONFIG = "y";
|
|
||||||
SWPHY = "y";
|
SWPHY = "y";
|
||||||
|
|
||||||
BRIDGE = "y";
|
|
||||||
BRIDGE_VLAN_FILTERING = "y";
|
|
||||||
BRIDGE_IGMP_SNOOPING = "y";
|
|
||||||
|
|
||||||
WATCHDOG = "y";
|
WATCHDOG = "y";
|
||||||
RALINK_WDT = "y"; # watchdog
|
RALINK_WDT = "y"; # watchdog
|
||||||
MT7621_WDT = "y"; # or it might be this one
|
MT7621_WDT = "y"; # or it might be this one
|
||||||
@ -175,8 +160,6 @@
|
|||||||
|
|
||||||
PARTITION_ADVANCED = "y";
|
PARTITION_ADVANCED = "y";
|
||||||
PRINTK_TIME = "y";
|
PRINTK_TIME = "y";
|
||||||
SQUASHFS = "y";
|
|
||||||
SQUASHFS_XZ = "y";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -30,9 +30,6 @@
|
|||||||
MTD_BLKDEVS = "y";
|
MTD_BLKDEVS = "y";
|
||||||
MTD_BLOCK = "y";
|
MTD_BLOCK = "y";
|
||||||
|
|
||||||
SQUASHFS = "y";
|
|
||||||
SQUASHFS_XZ = "y";
|
|
||||||
|
|
||||||
VIRTIO_MENU = "y";
|
VIRTIO_MENU = "y";
|
||||||
PCI = "y";
|
PCI = "y";
|
||||||
VIRTIO_PCI = "y";
|
VIRTIO_PCI = "y";
|
||||||
|
@ -31,6 +31,7 @@ in rec {
|
|||||||
../modules/standard.nix
|
../modules/standard.nix
|
||||||
../modules/wlan.nix
|
../modules/wlan.nix
|
||||||
../modules/network
|
../modules/network
|
||||||
|
../modules/vlan
|
||||||
];
|
];
|
||||||
|
|
||||||
hostname = "arhcive";
|
hostname = "arhcive";
|
||||||
|
@ -31,6 +31,7 @@ in rec {
|
|||||||
|
|
||||||
imports = [
|
imports = [
|
||||||
../modules/wlan.nix
|
../modules/wlan.nix
|
||||||
|
../modules/vlan
|
||||||
../modules/network
|
../modules/network
|
||||||
../modules/hostapd
|
../modules/hostapd
|
||||||
../modules/bridge
|
../modules/bridge
|
||||||
@ -88,9 +89,8 @@ in rec {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
services.int = interface {
|
services.int = svc.bridge.primary.build {
|
||||||
type = "bridge";
|
ifname = "int";
|
||||||
device = "int";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
services.dhcpc = svc.network.dhcp.client.build {
|
services.dhcpc = svc.network.dhcp.client.build {
|
||||||
|
@ -80,18 +80,6 @@ in {
|
|||||||
defaultProfile.packages = with pkgs;
|
defaultProfile.packages = with pkgs;
|
||||||
[ s6 s6-init-bin execline s6-linux-init s6-rc ];
|
[ s6 s6-init-bin execline s6-linux-init s6-rc ];
|
||||||
|
|
||||||
hardware.networkInterfaces = {
|
|
||||||
lo =
|
|
||||||
let iface = interface { type = "loopback"; device = "lo";};
|
|
||||||
in bundle {
|
|
||||||
name = "loopback";
|
|
||||||
contents = [
|
|
||||||
(address iface { family = "inet4"; address ="127.0.0.1"; prefixLength = 8;})
|
|
||||||
(address iface { family = "inet6"; address ="::1"; prefixLength = 128;})
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
boot.commandLine = [
|
boot.commandLine = [
|
||||||
"console=ttyS0,115200 panic=10 oops=panic init=/bin/init loglevel=8"
|
"console=ttyS0,115200 panic=10 oops=panic init=/bin/init loglevel=8"
|
||||||
"root=${config.hardware.rootDevice}"
|
"root=${config.hardware.rootDevice}"
|
||||||
|
@ -39,5 +39,13 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
config.kernel.config.BRIDGE = "y";
|
config.kernel.config = {
|
||||||
|
BRIDGE = "y";
|
||||||
|
BRIDGE_IGMP_SNOOPING = "y";
|
||||||
|
} // lib.optionalAttrs (config.system.service ? vlan) {
|
||||||
|
# depends on bridge _and_ vlan. I would like there to be
|
||||||
|
# a better way to test for the existence of vlan config:
|
||||||
|
# maybe the module should set an `enabled` attribute?
|
||||||
|
BRIDGE_VLAN_FILTERING = "y";
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
}:
|
}:
|
||||||
{ ifname } :
|
{ ifname } :
|
||||||
let
|
let
|
||||||
inherit (liminix.networking) interface;
|
|
||||||
inherit (liminix.services) bundle oneshot;
|
inherit (liminix.services) bundle oneshot;
|
||||||
inherit (lib) mkOption types;
|
inherit (lib) mkOption types;
|
||||||
in oneshot rec {
|
in oneshot rec {
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
let
|
let
|
||||||
inherit (lib) mkOption types;
|
inherit (lib) mkOption types;
|
||||||
inherit (pkgs) liminix;
|
inherit (pkgs) liminix;
|
||||||
|
inherit (pkgs.liminix.services) bundle;
|
||||||
in {
|
in {
|
||||||
options = {
|
options = {
|
||||||
system.service.network = {
|
system.service.network = {
|
||||||
@ -31,6 +32,30 @@ in {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
config = {
|
config = {
|
||||||
|
hardware.networkInterfaces = {
|
||||||
|
lo =
|
||||||
|
let
|
||||||
|
net = config.system.service.network;
|
||||||
|
iface = net.link.build { ifname = "lo";};
|
||||||
|
in bundle {
|
||||||
|
name = "loopback";
|
||||||
|
contents = [
|
||||||
|
( net.address.build {
|
||||||
|
interface = iface;
|
||||||
|
family = "inet";
|
||||||
|
address ="127.0.0.1";
|
||||||
|
prefixLength = 8;
|
||||||
|
})
|
||||||
|
( net.address.build {
|
||||||
|
interface = iface;
|
||||||
|
family = "inet6";
|
||||||
|
address = "::1";
|
||||||
|
prefixLength = 128;
|
||||||
|
})
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
system.service.network = {
|
system.service.network = {
|
||||||
link = liminix.callService ./link.nix {
|
link = liminix.callService ./link.nix {
|
||||||
ifname = mkOption {
|
ifname = mkOption {
|
||||||
|
@ -12,5 +12,9 @@ in
|
|||||||
config = mkIf (config.rootfsType == "squashfs") {
|
config = mkIf (config.rootfsType == "squashfs") {
|
||||||
system.outputs.rootfs =
|
system.outputs.rootfs =
|
||||||
liminix.builders.squashfs config.filesystem.contents;
|
liminix.builders.squashfs config.filesystem.contents;
|
||||||
|
kernel.config = {
|
||||||
|
SQUASHFS = "y";
|
||||||
|
SQUASHFS_XZ = "y";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
41
modules/vlan/default.nix
Normal file
41
modules/vlan/default.nix
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
## VLAN
|
||||||
|
## ====
|
||||||
|
##
|
||||||
|
## Virtual LANs give you the ability to sub-divide a LAN. Linux can
|
||||||
|
## accept VLAN tagged traffic and presents each VLAN ID as a
|
||||||
|
## different network interface (eg: eth0.100 for VLAN ID 100)
|
||||||
|
##
|
||||||
|
## Some Liminix devices with multiple ethernet ports are implemented
|
||||||
|
## using a network switch connecting the physical ports to the CPU,
|
||||||
|
## and require using VLAN in order to send different traffic to
|
||||||
|
## different ports (e.g. LAN vs WAN)
|
||||||
|
|
||||||
|
{ lib, pkgs, config, ...}:
|
||||||
|
let
|
||||||
|
inherit (lib) mkOption types;
|
||||||
|
inherit (pkgs.liminix.services) oneshot;
|
||||||
|
inherit (pkgs) liminix;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
system.service.vlan = mkOption { type = liminix.lib.types.serviceDefn; };
|
||||||
|
};
|
||||||
|
config.system.service.vlan = liminix.callService ./service.nix {
|
||||||
|
ifname = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "interface name to create";
|
||||||
|
};
|
||||||
|
primary = mkOption {
|
||||||
|
description = "existing physical interface";
|
||||||
|
type = liminix.lib.types.interface;
|
||||||
|
};
|
||||||
|
vid = mkOption {
|
||||||
|
description = "VLAN identifier (VID) in range 1-4094";
|
||||||
|
type = types.str;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
config.kernel.config = {
|
||||||
|
VLAN_8021Q = "y";
|
||||||
|
SWCONFIG = "y"; # not always appropriate, some devices will use DSA
|
||||||
|
};
|
||||||
|
}
|
15
modules/vlan/service.nix
Normal file
15
modules/vlan/service.nix
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
liminix
|
||||||
|
, lib
|
||||||
|
}:
|
||||||
|
{ ifname, primary, vid } :
|
||||||
|
let
|
||||||
|
inherit (liminix.services) oneshot;
|
||||||
|
in oneshot rec {
|
||||||
|
name = "${ifname}.link";
|
||||||
|
up = ''
|
||||||
|
ip link add link $(output ${primary} ifname) name ${ifname} type vlan id ${vid}
|
||||||
|
${liminix.networking.ifup name ifname}
|
||||||
|
'';
|
||||||
|
down = "ip link set down dev ${ifname}";
|
||||||
|
}
|
@ -18,32 +18,8 @@ let
|
|||||||
'';
|
'';
|
||||||
|
|
||||||
in {
|
in {
|
||||||
interface = { type ? "hardware", device, link ? null, primary ? null, id ? null, dependencies ? [] } @ args:
|
|
||||||
let name = "${device}.link";
|
|
||||||
ups =
|
|
||||||
[]
|
|
||||||
++ optional (type == "bridge")
|
|
||||||
"ip link add name ${device} type bridge"
|
|
||||||
++ optional (type == "vlan")
|
|
||||||
"ip link add link ${link} name ${device} type vlan id ${id}"
|
|
||||||
++ [(ifup name device)]
|
|
||||||
++ optional (primary != null)
|
|
||||||
"ip link set dev ${device} master ${primary.device}";
|
|
||||||
in oneshot {
|
|
||||||
inherit name;
|
|
||||||
up = lib.concatStringsSep "\n" ups;
|
|
||||||
down = "ip link set down dev ${device}";
|
|
||||||
dependencies = dependencies ++ lib.optional (primary != null) primary;
|
|
||||||
};
|
|
||||||
inherit ifup;
|
inherit ifup;
|
||||||
address = interface: { family, dependencies ? [], prefixLength, address } @ args:
|
|
||||||
let inherit (builtins) toString;
|
|
||||||
in oneshot {
|
|
||||||
dependencies = [ interface ] ++ dependencies;
|
|
||||||
name = "${interface.name}.addr.${address}";
|
|
||||||
up = "ip address add ${address}/${toString prefixLength} dev $(output ${interface} ifname)";
|
|
||||||
down = "ip address del ${address}/${toString prefixLength} dev $(output ${interface} ifname)";
|
|
||||||
};
|
|
||||||
route = { name, target, via, dependencies, dev ? null }:
|
route = { name, target, via, dependencies, dev ? null }:
|
||||||
let with_dev = if dev != null then "dev ${dev}" else "";
|
let with_dev = if dev != null then "dev ${dev}" else "";
|
||||||
in oneshot {
|
in oneshot {
|
||||||
|
Loading…
Reference in New Issue
Block a user