-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #974 from enesoztrk/chromecast
Chromecast support
- Loading branch information
Showing
11 changed files
with
443 additions
and
70 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
31 changes: 31 additions & 0 deletions
31
modules/reference/services/chromecast/chromecast-config.nix
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,31 @@ | ||
# Copyright 2024 TII (SSRC) and the Ghaf contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
{ config, lib, ... }: | ||
{ | ||
config.ghaf.reference.services.chromecast = | ||
let | ||
externalNic = | ||
let | ||
firstPciWifiDevice = lib.head config.ghaf.hardware.definition.network.pciDevices; | ||
in | ||
"${firstPciWifiDevice.name}"; | ||
|
||
internalNic = | ||
let | ||
vmNetworking = import ../../../microvm/virtualization/microvm/common/vm-networking.nix { | ||
inherit config; | ||
inherit lib; | ||
vmName = "net-vm"; | ||
inherit (config.microvm.net-vm) macAddress; | ||
internalIP = 1; | ||
}; | ||
in | ||
"${lib.head vmNetworking.networking.nat.internalInterfaces}"; | ||
|
||
in | ||
{ | ||
enable = lib.mkDefault false; | ||
inherit externalNic; | ||
inherit internalNic; | ||
}; | ||
} |
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,118 @@ | ||
# Copyright 2024 TII (SSRC) and the Ghaf contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
{ | ||
config, | ||
lib, | ||
... | ||
}: | ||
let | ||
cfg = config.ghaf.reference.services.chromecast; | ||
inherit (config.ghaf.reference) services; | ||
inherit (lib) | ||
mkEnableOption | ||
mkOption | ||
mkIf | ||
types | ||
; | ||
tcpChromeCastPort1 = 8008; | ||
tcpChromeCastPort2 = 8009; | ||
|
||
ssdpMcastPort = 1900; | ||
mdnsMcastPort = 5353; | ||
ssdpMcastIp = "239.255.255.250"; | ||
in | ||
{ | ||
options.ghaf.reference.services.chromecast = { | ||
enable = mkEnableOption "Enable chromecast service"; | ||
|
||
externalNic = mkOption { | ||
type = types.str; | ||
default = ""; | ||
description = '' | ||
External network interface | ||
''; | ||
}; | ||
internalNic = mkOption { | ||
type = types.str; | ||
default = ""; | ||
description = '' | ||
Internal network interface | ||
''; | ||
}; | ||
|
||
tcpPorts = mkOption { | ||
type = lib.types.listOf lib.types.port; | ||
readOnly = true; | ||
|
||
default = [ | ||
tcpChromeCastPort1 | ||
tcpChromeCastPort2 | ||
]; | ||
description = '' | ||
Chromecast tcp ports | ||
''; | ||
}; | ||
udpPorts = mkOption { | ||
type = lib.types.listOf lib.types.port; | ||
readOnly = true; | ||
default = [ | ||
ssdpMcastPort | ||
mdnsMcastPort | ||
]; | ||
description = '' | ||
Chromecast udp ports | ||
''; | ||
}; | ||
}; | ||
|
||
config = mkIf cfg.enable { | ||
assertions = [ | ||
{ | ||
assertion = cfg.externalNic != ""; | ||
message = "External Nic must be set"; | ||
} | ||
{ | ||
assertion = cfg.internalNic != ""; | ||
message = "Internal Nic must be set"; | ||
} | ||
]; | ||
|
||
services.nw-packet-forwarder = { | ||
enable = true; | ||
inherit (cfg) externalNic; | ||
inherit (cfg) internalNic; | ||
chromecast = true; | ||
}; | ||
|
||
services.smcroute = { | ||
enable = true; | ||
bindingNic = "${cfg.externalNic}"; | ||
rules = '' | ||
mgroup from ${cfg.externalNic} group ${ssdpMcastIp} | ||
mgroup from ${cfg.internalNic} group ${ssdpMcastIp} | ||
mroute from ${cfg.externalNic} group ${ssdpMcastIp} to ${cfg.internalNic} | ||
mroute from ${cfg.internalNic} group ${ssdpMcastIp} to ${cfg.externalNic} | ||
''; | ||
}; | ||
networking = { | ||
firewall.enable = true; | ||
firewall.extraCommands = " | ||
# Forward incoming TCP traffic on ports 8008 and 8009 to the internal NIC | ||
iptables -I FORWARD -i ${cfg.externalNic} -o ${cfg.internalNic} -p tcp --sport ${toString tcpChromeCastPort1} -j ACCEPT | ||
iptables -I FORWARD -i ${cfg.externalNic} -o ${cfg.internalNic} -p tcp --sport ${toString tcpChromeCastPort2} -j ACCEPT | ||
# Enable NAT for outgoing 8008 and 8009 Chromecast traffic | ||
iptables -t nat -I POSTROUTING -o ${cfg.externalNic} -p tcp --dport ${toString tcpChromeCastPort1} -j MASQUERADE | ||
iptables -t nat -I POSTROUTING -o ${cfg.externalNic} -p tcp --dport ${toString tcpChromeCastPort2} -j MASQUERADE | ||
# TTL adjustments to avoid multicast loops | ||
iptables -t mangle -I PREROUTING -i ${cfg.externalNic} -d ${ssdpMcastIp} -j TTL --ttl-set 1 | ||
iptables -t mangle -I PREROUTING -i ${cfg.internalNic} -d ${ssdpMcastIp} -j TTL --ttl-inc 1 | ||
# Enable NAT for outgoing udp multicast traffic | ||
iptables -t nat -I POSTROUTING -o ${cfg.externalNic} -p udp -d ${ssdpMcastIp} --dport ${toString ssdpMcastPort} -j MASQUERADE | ||
"; | ||
|
||
}; | ||
}; | ||
} |
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
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
Oops, something went wrong.