Discussion:
cloner interface handling in rc.d/network
(too old to reply)
Paul Goyette
2021-05-14 15:59:11 UTC
Permalink
4 I guess the ##*. (why ## and not #?) could better be spelled out as
"#/etc/ifconfig."
The ##* stuff is shell pattern substitution, not regex. See sh(1)
man page.


+--------------------+--------------------------+-----------------------+
| Paul Goyette | PGP Key fingerprint: | E-mail addresses: |
| (Retired) | FA29 0E3B 35AF E8AE 6651 | ***@whooppee.com |
| Software Developer | 0786 F758 55DE 53BA 7731 | ***@netbsd.org |
+--------------------+--------------------------+-----------------------+
Robert Elz
2021-05-14 16:35:02 UTC
Permalink
Date: Fri, 14 May 2021 17:17:32 +0200
From: Edgar =?iso-8859-1?B?RnXf?= <***@math.uni-bonn.de>
Message-ID: <***@trav.math.uni-bonn.de>


| 1. What the code is supposed to do (I think)
| is, with auto_ifconfig=YES, to add all "cloner" interfaces

Yes.

| 2. When run later (e.g. after going single user and back multi user),

I haven't really thought about that case, there should be something when
the net goes down to destroy added cloners, but there probably isn't.

| 3. The "[ ! -f $int ] && break" line completely confuses me
|
| 3a [ ! ... ]�should better be written ! [ ... ], no?

Probably yes, but it works either way.
|
| 3b ! [ ... ]�&& foo could be written [ ... ] ||�foo

It could, but that would alter the semantic slightly.

| 3c What is this trying to catch? Directories called /etc/ifconfig.tun0?

Cloner interfaces that exist but have no /etc/ifconfig.* files at all.

| 3d Why break and not continue (or && tmp=)? Why exit on the first non-file
| entry?

Non-file isn't really it (-e would work) - but an /etc/ifconfig.* which isn't
a file isn't very likely, and certainly isn't likely to work.

The idea is to simply stop if the file doesn't exist. Since the file comes
from a glob expansion, the only way it can not exist is if the pattern didn't
match, and so what "int" was set to is the pattern, ie, literally
just like int='/etc/ifconfig.${cloner}[0-9]*'

There will be only one iteration of the loop when that happens, so whether
the code used break or continue (or even your 3b variation above) makes no
real difference - but using "break" makes it clearer that in this case, the
loop is immediately done.

| 4 I guess the ##*. (why ## and not #?) could better be spelled out as
| "#/etc/ifconfig."

It could, probably, but that's more characters for the shell to parse,
and builds the "/etc/ifconfig" string into two places in the loop instead
of just one.

Not sure why ## rather than # - in the case where an interface was
named foo3.7 or something the ## variant is likely to fail. This bit
should probably be changed (but then again, I don't think we have any
cloner interfaces with names like that, and because of the way cloners
are generated, I don't think we ever can, so it really doesn't matter).

kre



--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Robert Elz
2021-05-14 21:05:21 UTC
Permalink
Date: Fri, 14 May 2021 14:01:13 -0400 (EDT)
From: Mouse <***@Rodents-Montreal.ORG>
Message-ID: <***@Stone.Rodents-Montreal.ORG>

| >> 3a [ ! ... ]�should better be written ! [ ... ], no?
| > Probably yes, but it works either way.
|
| I see no reason to prefer either over the other. What am I missing?

The rules for 3 arg test are that if the 2nd arg is a binary operator
then that wins, so should someone create a version of test where -f
(or whatever) is a binary operator (in addition to its unary operator
function) then the meaning would suddenly change. This is a very
remote possibility at best, but using the ! [ -f foo ] variant makes
sure that can never happen.

The ! as a test operator was created when sh had no ! function, and
when people were used to using test with many args (with -a, -o,
parentheses, etc) where it made sense - assuming you could cope with
the heuristic way that test guessed what was intended. If we were
defining it now there would be no ! operator in test, it simply isn't needed.

| >> 3b ! [ ... ]�&& foo could be written [ ... ] ||�foo
| > It could, but that would alter the semantic slightly.
|
| How would it alter the semantics? The only way I can see is that it
| would alter the status returned from the construct in the case where it
| doesn't run foo.

Yes. The point was that this kind of De-Morgan transformation isn't
always safe to do with sh code, the minor variations in the results can
sometimes be important. Not here, which is why the "It could".

| Does -f accept a symlink to a plain file?

Yes.

| The presence of -h argues
| that it uses lstat(), but it might do so only for -h.

It does (only for -h and -L).

| In theory, there's also the question of what happens if there is a file
| called, say, /etc/ifconfig.tun0* (the * being part of the name).

If you have an interface called tun0* then it will configure it, as
it should. Otherwise it will attempt to, and fail.

| As another possible issue, consider a cloner interface called, say,
| tun0foo, whose unit 1 would be tun0foo1, whose file would match the
| tun0* pattern. (Obviously, not a concern with the current crop of
| cloners, but nothing prevents someone from implementing one, right?)

Just common sense. Interface names don't contain digits generally,
just the unit number part. You might be surprised just how much
would break if that assumption is no longer maintained.

| More serious, to me, is that it pays attention to only files, ignoring
| any possible ifconfig_$int$num variables.

I didn't write the code, so I'm not sure if any attempt was made to
allow those things (personally I don't like them, I prefer the files,
though I'd prefer they not live directly in /etc).

| > Not sure why ## rather than # - in the case where an interface was
| > named foo3.7 or something the ## variant is likely to fail.
|
| Possibility: maybe it was adapted from something that gathered files
| from subdirectories, many of which might have dots in their names, and
| that particular bit of syntax was never updated?

Perhaps. I have no idea.

| I'm not sure whether I think it's more likely that the /etc/ifconfig.
| prefix would be changed to grow another dot or that a cloner interface
| with a dot in its name would appear. Neither feels very likely to me.

Nor me, but a change to the /etc/ifconfig part (though probably not by
inserting dots) seems the more likely of those possibilities.

| Um? What prevents a cloner from having a name like x.y.z? I haven't
| looked at the code, but that seems like a peculiar restriction.

It may be able to, I haven't checked that either. It isn't likely.

kre


--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Loading...