<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, May 11, 2016 at 7:31 PM, Lennart Poettering <span dir="ltr"><<a href="mailto:lennart@poettering.net" target="_blank">lennart@poettering.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Wed, 11.05.16 11:32, Brian Kroth (<a href="mailto:bpkroth@gmail.com">bpkroth@gmail.com</a>) wrote:<br>
<br>
> Hi again all,<br>
><br>
> TL;DR: would it be possible (or make sense) to have systemd Match rules for<br>
> network units that could match on some artifact of the network the link is<br>
> attached to like vlan tag, router advertisement, wireless access point or<br>
> gateway mac, etc.?<br>
<br>
</span>Well, .network files contain the definition how to set up a network<br>
interface, i.e. how to place it into UP state so that packets can be<br>
received and how to configure IP routing so that communication further<br>
on works. Hence: it uses relatively static properties of the device<br>
that are already available when the device is offline, to find the<br>
right .network file to read the dynamic configuration to apply in<br>
order to put it online. The router advertisment info and things like<br>
the gateway mac are pieces of information that are only available when<br>
the network is already up, when the network configuration is already<br>
applied. Hence using that as match for the configuration can't work:<br>
at the time we could use that information we already would have had to<br>
apply it. And if we don't apply it, we would never get the information<br>
to acquire...<br>
<br>
The VLAN tag is a different case though: it's assigned when the<br>
VLAN networkd device is created, and configured in the .netdev<br>
configuration file for that. Thus, it's already set the moment the<br>
network device pops up, and it could be used nicely for the<br>
matching. So yupp, added a MatchVLANId= or so, might make<br>
sense. Please file an RFE issue on github about this, if you'd like to<br>
see this implemented.<br>
<br>
Matching by AP could work. Iirc today's WLAN drivers actually will<br>
create virtual links for the network you connect to, and the ESSID for<br>
each would be set before networkd would take notice of it, hence this<br>
is probably something we could do. Note however, that networkd does<br>
not interface with the WLAN stack at all at this point, a WLAN device<br>
is treated like any other Ethernet device atm</blockquote><div><br></div><div>It was always my intention to extend the Match logic to be able to do this kind of matching on the environment. But as Lennart says, it would have to be only based on things we can passively observe. I think it would possibly be acceptable to eagerly UP an interface if it matches all but the "environment" matches (and that is essentially how WLAN must work I guess, though the UP might in that case be done by someone other than us), thought that stuff definitely requires some thinking. I agree that VLANId is totally fine to match on, and that ESSID (and probably similar things for Bluetooth etc) would be fine if they are anyway available. But yeah, whether to match on things that requires us to UP the interface would need to be discussed some more.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
> However, the missing bit then would be network address assignment for the<br>
> various instances to the right interfaces.  Ideally, I'd just stamp out<br>
> network unit files and have the apache instance units depend upon that, but<br>
> the trouble is that traditionally NIC naming hasn't always been consistent<br>
> in the past.<br>
><br>
> I've read through [1], but it doesn't really provide what I'm looking for.<br>
> Physical layout of the nic-port-types is semi interesting and perhaps<br>
> consistent, but network operator error may result in a misassigned vlan<br>
> port, or simply the wrong cable to the wrong port (which can be true for<br>
> physical or virtual realms unfortunately), etc.<br>
><br>
> What I did in the past to work around that was to use ndisc6 or something<br>
> similar to verify that the expected interface had the expected network<br>
> properties - in this case a router advertisement.<br>
<br>
</span>Hmm, schemes like this sound a bit dangerous, no? I mean, if you base<br>
your decision whether to apply the relatively open "internal LAN"<br>
config to an interface or the restricted "internet" config on the<br>
traffic you see on the port, then you make yourself vulnerable to<br>
people sending you rogue IP packets...<br>
<br>
I see your usecase though, but I don't really have any good suggestion<br>
what to do in this case I must say...<br>
<br>
Maybe adding something like a RequireDHCPServer= setting or so, that<br>
allows configuration of a DHCP server address, and when set would<br>
result in logged warnings if DHCP leases are offered from other<br>
servers thatn the configured one, might be an option? i.e. so that you<br>
at least get a loggable event when some .network file is applied to<br>
the wrong iface?<br>
<br>
But dunno, maybe Tom has an idea about this? Tom?<br></blockquote><div><br></div><div>I'm very skeptical about these kind of schemes. We can really not promise anything about where DHCP/NDisc come form. If someone has access to the local lan, they can spoof absolutely anything, so we better not make the impression that we can guarantee anything we can't. If you want some sort of sanity checking, that might make sense, but probably as some external ad-hoc tool rather than inside networkd.<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class=""><br>
> [2] Sidenote: In the past I've used an old trick of setting the<br>
> preferred_lft to 0 for IPv6 addresses that I wanted to be available to<br>
> services, but not selected for outbound connections from the host.  This<br>
> was basically to help influence the usual source address selection criteria<br>
> which tries to avoid "deprecated" addresses.  I didn't see a way to specify<br>
> that in the systemd.network man page.  Is there one that I'm missing, or is<br>
> that another case for an Exec... statement?<br>
<br>
</span>This has been added very recently to systemd, see #3102, #2166,<br>
b5834a0b38c1aa7d6975d76971cd75c07455d129. It will be available with<br>
the next release.<br>
<span class="HOEnZb"><font color="#888888"><br>
Lennart<br>
<br>
--<br>
Lennart Poettering, Red Hat<br>
</font></span></blockquote></div><br></div></div>