Re: How to tell if a network interface was renamed (and from what)

2023-11-18 Thread Zhenlei Huang


> On Nov 19, 2023, at 6:20 AM, Mina Galić  wrote:
> 
> Hi folks,
> 
> Linux has an "easy" way of telling if an interface has been renamed.
> See cloud-init's is_renamed function: 
> https://github.com/canonical/cloud-init/blob/5496745b394f9b7b9eaf57fd619330d484ce2da8/cloudinit/net/__init__.py#L338-L350
> This code reads /sys/class/net//name_assign_type and if that is 3 or 
> 4, it's been renamed.
> 
> I can't even think of an sensible way of replicating that.
> I can only think of terrible / wrong way of finding it out:
> 
> dmesg | grep "changing name to ''"
> 
> a less terrible method would be to check for, say:
> 
> sysctl dev..0.%driver
> 
> if that fails, we probably have a renamed interface… but we don't know what 
> it was renamed from, and this only works for *real* interfaces, not for 
> cloned devices, or epairs.
> 
> Now, ignoring my terrible hacky attempts at command line tooling, I would 
> also happily accept a solution in C, which is fairly easily accessible from 
> Python, and which we already use to figure out the uptime (or rather, the 
> boottime): 
> https://github.com/canonical/cloud-init/blob/5496745b394f9b7b9eaf57fd619330d484ce2da8/cloudinit/util.py#L2073-L2105
> 
> Looking forward to reading your ideas.

FreeBSD currently does not preserve the old ( original ) name of interfaces if 
it is renamed ( either physical or cloned ones ).
While there's an attempt https://reviews.freebsd.org/D28247 
  to get the device name (physical ones) 
but it is not perfect and not completed.

So may I ask why you need to know if a network interface was renamed ?

> 
> Kind regards,
> 
> Mina Galić
> 

Best regards,
Zhenlei



Re: How to tell if a network interface was renamed (and from what)

2023-11-18 Thread Kyle Evans

On 11/18/23 19:15, Zhenlei Huang wrote:



On Nov 19, 2023, at 6:20 AM, Mina Galić > wrote:


Hi folks,

Linux has an "easy" way of telling if an interface has been renamed.
See cloud-init's is_renamed function: 
https://github.com/canonical/cloud-init/blob/5496745b394f9b7b9eaf57fd619330d484ce2da8/cloudinit/net/__init__.py#L338-L350 
This code reads /sys/class/net//name_assign_type and if that is 
3 or 4, it's been renamed.


I can't even think of an sensible way of replicating that.
I can only think of terrible / wrong way of finding it out:

dmesg | grep "changing name to ''"

a less terrible method would be to check for, say:

sysctl dev..0.%driver

if that fails, we probably have a renamed interface… but we don't know 
what it was renamed from, and this only works for *real* interfaces, 
not for cloned devices, or epairs.


Now, ignoring my terrible hacky attempts at command line tooling, I 
would also happily accept a solution in C, which is fairly easily 
accessible from Python, and which we already use to figure out the 
uptime (or rather, the boottime): 
https://github.com/canonical/cloud-init/blob/5496745b394f9b7b9eaf57fd619330d484ce2da8/cloudinit/util.py#L2073-L2105 


Looking forward to reading your ideas.


FreeBSD currently does not preserve the old ( original ) name of 
interfaces if it is renamed ( either physical or cloned ones ).
While there's an attempt https://reviews.freebsd.org/D28247 
  to get the device name (physical 
ones) but it is not perfect and not completed.


So may I ask why you need to know if a network interface was renamed ?



Just last week I found this quite a pain as well; once an interface has 
been renamed, if it's not a pseudo-interface with an obvious group 
there's no clear way, AFAICT, to determine which driver created it 
without perusing pciconf output or whatnot and hopefully being able to 
associate the NICs listed with the new names (easier when there's only 
one NIC, of course).  Kind of a pain when you're working on a remote 
machine that you're not at all familiar with.


Thanks,

Kyle Evans



Re: How to tell if a network interface was renamed (and from what)

2023-11-19 Thread Özkan KIRIK
It would be better if FreeBSD could have "interface altname feature"
like Linux has.

Kyle Evans , 19 Kas 2023 Paz, 07:50 tarihinde şunu yazdı:
>
> On 11/18/23 19:15, Zhenlei Huang wrote:
> >
> >
> >> On Nov 19, 2023, at 6:20 AM, Mina Galić  >> > wrote:
> >>
> >> Hi folks,
> >>
> >> Linux has an "easy" way of telling if an interface has been renamed.
> >> See cloud-init's is_renamed function:
> >> https://github.com/canonical/cloud-init/blob/5496745b394f9b7b9eaf57fd619330d484ce2da8/cloudinit/net/__init__.py#L338-L350
> >>  
> >> 
> >> This code reads /sys/class/net//name_assign_type and if that is
> >> 3 or 4, it's been renamed.
> >>
> >> I can't even think of an sensible way of replicating that.
> >> I can only think of terrible / wrong way of finding it out:
> >>
> >> dmesg | grep "changing name to ''"
> >>
> >> a less terrible method would be to check for, say:
> >>
> >> sysctl dev..0.%driver
> >>
> >> if that fails, we probably have a renamed interface… but we don't know
> >> what it was renamed from, and this only works for *real* interfaces,
> >> not for cloned devices, or epairs.
> >>
> >> Now, ignoring my terrible hacky attempts at command line tooling, I
> >> would also happily accept a solution in C, which is fairly easily
> >> accessible from Python, and which we already use to figure out the
> >> uptime (or rather, the boottime):
> >> https://github.com/canonical/cloud-init/blob/5496745b394f9b7b9eaf57fd619330d484ce2da8/cloudinit/util.py#L2073-L2105
> >>  
> >> 
> >>
> >> Looking forward to reading your ideas.
> >
> > FreeBSD currently does not preserve the old ( original ) name of
> > interfaces if it is renamed ( either physical or cloned ones ).
> > While there's an attempt https://reviews.freebsd.org/D28247
> >   to get the device name (physical
> > ones) but it is not perfect and not completed.
> >
> > So may I ask why you need to know if a network interface was renamed ?
> >
>
> Just last week I found this quite a pain as well; once an interface has
> been renamed, if it's not a pseudo-interface with an obvious group
> there's no clear way, AFAICT, to determine which driver created it
> without perusing pciconf output or whatnot and hopefully being able to
> associate the NICs listed with the new names (easier when there's only
> one NIC, of course).  Kind of a pain when you're working on a remote
> machine that you're not at all familiar with.
>
> Thanks,
>
> Kyle Evans
>



Re: How to tell if a network interface was renamed (and from what)

2023-11-19 Thread Mina Galić



> > FreeBSD currently does not preserve the old ( original ) name of
> > interfaces if it is renamed ( either physical or cloned ones ).
> > While there's an attempt https://reviews.freebsd.org/D28247
> > to get the device name (physical
> > ones) but it is not perfect and not completed.
> > 
> > So may I ask why you need to know if a network interface was renamed ?
> 
> 
> Just last week I found this quite a pain as well; once an interface has
> been renamed, if it's not a pseudo-interface with an obvious group
> there's no clear way, AFAICT, to determine which driver created it

I think the main reason that we need to know if and from what an interface has 
been renamed is if we need to know what driver we're working with.

But given that a rename doesn't change — or even just *alias*
the sysctl dev hierarchy, where a %driver is recorded, we can't
track it back.

(but again, that's just for physical devices, then again virtual devices record 
what type of device they are in their group which
is essentially the same thing)

As soon as we have more than one interface with different drivers
it's impossible to parse out what we're dealing with without
parsing rc.conf, logs, or worse things I can't think of right now.







Re: How to tell if a network interface was renamed (and from what)

2023-11-19 Thread Mina Galić


Hi Özkan,

> It would be better if FreeBSD could have "interface altname feature"
> like Linux has.

even tho I'm writing this email from a Linux laptop, and often
have to understand Linux specific code to see how I can (or if I
need to) replicate that on FreeBSD, I'm not familiar enough
with Linux.

Can you describe the altname feature, and how it works?

Kind regards,

Mina



Re: How to tell if a network interface was renamed (and from what)

2023-11-19 Thread Mike Karels
On 19 Nov 2023, at 8:34, Mina Galić wrote:

>>> FreeBSD currently does not preserve the old ( original ) name of
>>> interfaces if it is renamed ( either physical or cloned ones ).
>>> While there's an attempt https://reviews.freebsd.org/D28247
>>> to get the device name (physical
>>> ones) but it is not perfect and not completed.
>>>
>>> So may I ask why you need to know if a network interface was renamed ?
>>
>>
>> Just last week I found this quite a pain as well; once an interface has
>> been renamed, if it's not a pseudo-interface with an obvious group
>> there's no clear way, AFAICT, to determine which driver created it
>
> I think the main reason that we need to know if and from what an interface 
> has been renamed is if we need to know what driver we're working with.
>
> But given that a rename doesn't change — or even just *alias*
> the sysctl dev hierarchy, where a %driver is recorded, we can't
> track it back.
>
> (but again, that's just for physical devices, then again virtual devices 
> record what type of device they are in their group which
> is essentially the same thing)
>
> As soon as we have more than one interface with different drivers
> it's impossible to parse out what we're dealing with without
> parsing rc.conf, logs, or worse things I can't think of right now.

The kernel has a driver name for each interface, which looks like it
doesn't change currently in most cases.  There is a kernel accessor
function, but I don't think it is exported to user space now.  It could
be, though.  Would this be sufficient for your purposes?  There is also
a unit number, which could also be exported.

Mike



Re: How to tell if a network interface was renamed (and from what)

2023-11-19 Thread Özkan KIRIK
Hi Mina,

Let's explain with a small example:
In this scenario, we are going to add two alternate names for the "lo"
interface. And then we can access to the interface using all of the
names: lo, test1, test2

# ip link show lo
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN
mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

# ip link property add dev lo altname test1
# ip link property add dev lo altname test2

# ip link show
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN
mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
altname test1
altname test2
2: enp4s0:  mtu 1500 qdisc fq_codel
state DOWN mode DEFAULT group default qlen 1000
link/ether b0:7b:25:31:6c:92 brd ff:ff:ff:ff:ff:ff

# ip link show lo
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN
mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
altname test1
altname test2

# ip link show test1
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN
mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
altname test1
altname test2

# ip link show test2
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN
mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
altname test1
altname test2

#  ping -I test2 127.0.0.1
ping: Warning: source address might be selected on device other than: test2
PING 127.0.0.1 (127.0.0.1) from 127.0.0.1 test2: 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.023 ms

By the altname feature, the interface name doesn't change, but you can
assign many altnames. So you can access them using these altnames.

Mina Galić , 19 Kas 2023 Paz, 17:36 tarihinde şunu yazdı:
>
>
> Hi Özkan,
>
> > It would be better if FreeBSD could have "interface altname feature"
> > like Linux has.
>
> even tho I'm writing this email from a Linux laptop, and often
> have to understand Linux specific code to see how I can (or if I
> need to) replicate that on FreeBSD, I'm not familiar enough
> with Linux.
>
> Can you describe the altname feature, and how it works?
>
> Kind regards,
>
> Mina



Re: How to tell if a network interface was renamed (and from what)

2023-11-19 Thread Zhenlei Huang



> On Nov 19, 2023, at 10:34 PM, Mina Galić  wrote:
> 
> 
> 
>>> FreeBSD currently does not preserve the old ( original ) name of
>>> interfaces if it is renamed ( either physical or cloned ones ).
>>> While there's an attempt https://reviews.freebsd.org/D28247
>>> to get the device name (physical
>>> ones) but it is not perfect and not completed.
>>> 
>>> So may I ask why you need to know if a network interface was renamed ?
>> 
>> 
>> Just last week I found this quite a pain as well; once an interface has
>> been renamed, if it's not a pseudo-interface with an obvious group
>> there's no clear way, AFAICT, to determine which driver created it
> 
> I think the main reason that we need to know if and from what an interface 
> has been renamed is if we need to know what driver we're working with.
> 
> But given that a rename doesn't change — or even just *alias*
> the sysctl dev hierarchy, where a %driver is recorded, we can't
> track it back.
> 
> (but again, that's just for physical devices, then again virtual devices 
> record what type of device they are in their group which
> is essentially the same thing)

Since it is just for physical devices, may I propose to have the driver name in 
their groups ?

So an if_ure interface ue0 will look like:

```
ue0: flags=1008843 metric 0 
mtu 1500

options=60009b
ether 00:e0:4c:xx:xx:xx
media: Ethernet autoselect (1000baseT )
status: active
+++ groups: ure
nd6 options=23
```

That does not include the unit number. But could be useful to quickly get the 
driver name of physical devices.

> 
> As soon as we have more than one interface with different drivers
> it's impossible to parse out what we're dealing with without
> parsing rc.conf, logs, or worse things I can't think of right now.
> 
> 
> 
> 
> 






Re: How to tell if a network interface was renamed (and from what)

2023-11-19 Thread Mina Galić
Hi Mike,

> The kernel has a driver name for each interface, which looks like it
> doesn't change currently in most cases. There is a kernel accessor
> function, but I don't think it is exported to user space now. It could
> be, though. Would this be sufficient for your purposes? There is also
> a unit number, which could also be exported.

As mentioned in my initial post, I'm happy to drop to C where alternatives are 
infeasible, slow, or otherwise cumbersome, or just plain don't exist.

Here's the code we use to determine boottime: 
https://github.com/canonical/cloud-init/blob/5496745b394f9b7b9eaf57fd619330d484ce2da8/cloudinit/util.py#L2073-L2105

> Mike

Mina

Re: How to tell if a network interface was renamed (and from what)

2023-11-19 Thread Mike Karels
On 19 Nov 2023, at 13:13, Mina Galić wrote:

> Hi Mike,
>
>> The kernel has a driver name for each interface, which looks like it
>> doesn't change currently in most cases. There is a kernel accessor
>> function, but I don't think it is exported to user space now. It could
>> be, though. Would this be sufficient for your purposes? There is also
>> a unit number, which could also be exported.
>
> As mentioned in my initial post, I'm happy to drop to C where alternatives 
> are infeasible, slow, or otherwise cumbersome, or just plain don't exist.
>
> Here's the code we use to determine boottime: 
> https://github.com/canonical/cloud-init/blob/5496745b394f9b7b9eaf57fd619330d484ce2da8/cloudinit/util.py#L2073-L2105

If I would design it right now, I'd add code to ifconfig to exercise the
new feature, and do something like this:

# ifconfig my-interfacename drivername
igb
#

Unit could be done similarly if needed, or ifconfig could have an
operand that caused both driver and unit to be printed, maybe as
two words (hopefully no spaces in driver names!).

Mike

>
> Mina



Re: How to tell if a network interface was renamed (and from what)

2023-11-19 Thread Mina Galić
Hi Zhenlei,


> Since it is just for physical devices, may I propose to have the driver name 
> in their groups ?
> 
> So an if_ure interface ue0 will look like:
> 
> ```
> ue0: flags=1008843 metric 0 
> mtu 1500
> 
> options=60009b
> 
> ether 00:e0:4c:xx:xx:xx
> media: Ethernet autoselect (1000baseT )
> 
> status: active
> +++ groups: ure
> nd6 options=23
> 
> ```
> 
> That does not include the unit number. But could be useful to quickly get the 
> driver name of physical devices.
>

Given that currently on FreeBSD the easiest way to tell if something
is a physical device is by checking the *absence* of groups, this
would only really be acceptable if we add an "egress" group like
OpenBSD does, in addition to the driver name.

If we can't do that, then I think Mike's solution with having the
driver (and unit) as a separate category would be preferable.

Unrelatedly, I don't see anything in ure(4) mentioning that if_ure
devices will be named "ue".
Don't we usually  document such deviation from the norm?


Kind regards,

Mina



Re: How to tell if a network interface was renamed (and from what)

2023-11-19 Thread Zhenlei Huang


> On Nov 20, 2023, at 5:35 AM, Mina Galić  wrote:
> 
> Hi Zhenlei,
> 
> 
>> Since it is just for physical devices, may I propose to have the driver name 
>> in their groups ?
>> 
>> So an if_ure interface ue0 will look like:
>> 
>> ```
>> ue0: flags=1008843 metric 0 
>> mtu 1500
>> 
>> options=60009b
>> 
>> ether 00:e0:4c:xx:xx:xx
>> media: Ethernet autoselect (1000baseT )
>> 
>> status: active
>> +++ groups: ure
>> nd6 options=23
>> 
>> ```
>> 
>> That does not include the unit number. But could be useful to quickly get 
>> the driver name of physical devices.
>> 
> 
> Given that currently on FreeBSD the easiest way to tell if something
> is a physical device is by checking the *absence* of groups,

Emm, that sounds more a HACK to test physical devices.

> this
> would only really be acceptable if we add an "egress" group like
> OpenBSD does, in addition to the driver name.
> 
> If we can't do that, then I think Mike's solution with having the
> driver (and unit) as a separate category would be preferable.

The interface group feature was imported from OpenBSD by 0dad3f0e1512 .

> Import interface groups from OpenBSD.  This allows to group interfaces in
> order to - for example - apply firewall rules to a whole group of
> interfaces.  This is required for importing pf from OpenBSD 3.9

Despite the purpose to get driver name, it seems not useful to have driver name 
in groups.

> 
> Unrelatedly, I don't see anything in ure(4) mentioning that if_ure
> devices will be named "ue".

Currently usb ethernet have interface named `ue%u` regardless  the actual 
device drivers.
See https://cgit.freebsd.org/src/tree/sys/dev/usb/net/usb_ethernet.c#n202 

```
static void
ue_attach_post_task(struct usb_proc_msg *_task)
{
...
if_initname(ifp, "ue", ue->ue_unit);
...
}
```

> Don't we usually  document such deviation from the norm?

I'm not familiar with usb protocols, I guess usb ethernet is sub device of usb 
controller.

```
smsc0 on uhub1
smsc0:  on usbus1
ue0:  on smsc0
```

Then `ue%u` for all usb ethernet make senses.

> 
> 
> Kind regards,
> 
> Mina





Re: How to tell if a network interface was renamed (and from what)

2023-11-20 Thread Mike Karels
On 19 Nov 2023, at 15:35, Mina Galić wrote:

> Hi Zhenlei,
>
>
>> Since it is just for physical devices, may I propose to have the driver name 
>> in their groups ?
>>
>> So an if_ure interface ue0 will look like:
>>
>> ```
>> ue0: flags=1008843 metric 0 
>> mtu 1500
>>
>> options=60009b
>>
>> ether 00:e0:4c:xx:xx:xx
>> media: Ethernet autoselect (1000baseT )
>>
>> status: active
>> +++ groups: ure
>> nd6 options=23
>>
>> ```
>>
>> That does not include the unit number. But could be useful to quickly get 
>> the driver name of physical devices.
>>
>
> Given that currently on FreeBSD the easiest way to tell if something
> is a physical device is by checking the *absence* of groups, this
> would only really be acceptable if we add an "egress" group like
> OpenBSD does, in addition to the driver name.
>
> If we can't do that, then I think Mike's solution with having the
> driver (and unit) as a separate category would be preferable.

I have a proof of concept that makes the presumed original name
(driver name + unit number) available to ifconfig, which prints
the string with everything else in the standard output format.
I don't think that is the right solution, but the other details
should be easy.  I'm tempted to print the driver name and unit
number separately, although possibly as two words using the same
option.  It should probably be an option rather than a keyword,
so something like this:

# ifconfig -N interface-name
igb 1
#

Or the unit number could be on a separate option.

Comments?

Mike

> Unrelatedly, I don't see anything in ure(4) mentioning that if_ure
> devices will be named "ue".
> Don't we usually  document such deviation from the norm?
>
>
> Kind regards,
>
> Mina



Re: How to tell if a network interface was renamed (and from what)

2023-11-20 Thread Mina Galić



> I have a proof of concept that makes the presumed original name
> (driver name + unit number) available to ifconfig, which prints
> the string with everything else in the standard output format.
> I don't think that is the right solution, but the other details
> should be easy. I'm tempted to print the driver name and unit
> number separately, although possibly as two words using the same
> option. It should probably be an option rather than a keyword,
> so something like this:
> 
> # ifconfig -N interface-name
> igb 1
> #
> 
> Or the unit number could be on a separate option.
> 
> Comments?

I like it!

> Mike

Mina



Re: How to tell if a network interface was renamed (and from what)

2023-11-20 Thread Kristof Provost
On 20 Nov 2023, at 21:29, Mike Karels wrote:
> On 19 Nov 2023, at 15:35, Mina Galić wrote:
>> Hi Zhenlei,
>>
>>
>>> Since it is just for physical devices, may I propose to have the driver 
>>> name in their groups ?
>>>
>>> So an if_ure interface ue0 will look like:
>>>
>>> ```
>>> ue0: flags=1008843 metric 
>>> 0 mtu 1500
>>>
>>> options=60009b
>>>
>>> ether 00:e0:4c:xx:xx:xx
>>> media: Ethernet autoselect (1000baseT )
>>>
>>> status: active
>>> +++ groups: ure
>>> nd6 options=23
>>>
>>> ```
>>>
>>> That does not include the unit number. But could be useful to quickly get 
>>> the driver name of physical devices.
>>>
>>
>> Given that currently on FreeBSD the easiest way to tell if something
>> is a physical device is by checking the *absence* of groups, this
>> would only really be acceptable if we add an "egress" group like
>> OpenBSD does, in addition to the driver name.
>>
>> If we can't do that, then I think Mike's solution with having the
>> driver (and unit) as a separate category would be preferable.
>
> I have a proof of concept that makes the presumed original name
> (driver name + unit number) available to ifconfig, which prints
> the string with everything else in the standard output format.
> I don't think that is the right solution,

I believe a similar solution has been proposed before, and it failed to cope 
with things like epair interfaces.

I’d look in the direction of just adding a field to struct ifnet with the 
original interface name (likely easily done in if_attach()), along with a new 
ioctl to retrieve that field.

Best regards,
Kristof



Re: How to tell if a network interface was renamed (and from what)

2023-11-20 Thread Franco Fichtner


> On 20. Nov 2023, at 21:56, Kristof Provost  wrote:
> 
> I’d look in the direction of just adding a field to struct ifnet with the 
> original interface name (likely easily done in if_attach()), along with a new 
> ioctl to retrieve that field.

ifconfig_get_orig_name() already exists, but apart from wlandebug
nothing is using it.

The internally used IFDATA_DRIVERNAME also appears in ifinfo
(not installed in base) and bsnmpd but that's it.

if_dname is the target and it exists in ifnet struct along with
a man page entry in inet(9).

All that is really missing is a way to print it via ifconfig command.


Cheers,
Franco


Re: How to tell if a network interface was renamed (and from what)

2023-11-20 Thread Franco Fichtner
FWIW, here is the relevant ifinfo output of a sample machine:

# ifinfo | grep ^Interface
Interface igb0 (igb0):
Interface igb1 (igb1):
Interface igb2 (igb2):
Interface igb3 (igb3):
Interface enc0 (enc0):
Interface lo0 (lo0):
Interface pflog0 (pflog0):
Interface pfsync0 (pfsync0):
Interface lagg0 (lagg0):
Interface igb2_vlan42 (vlan0):
Interface vlan0.1.23 (vlan1):
Interface vlan0.3 (vlan2):
Interface vlan0.5.6.7 (vlan3):
Interface vlan01. (vlan4):
Interface vlan06 (vlan5):
Interface vlan08 (vlan6):
Interface qinq0.123 (vlan7):
Interface gre2 (gre2):
Interface gre0 (gre0):
Interface gif4 (gif4):
Interface gif1 (gif1):
Interface gif0 (gif0):
Interface l2tp0 (ng0):
Interface bridge0 (bridge0):
Interface lo1 (lo1):
Interface lo2 (lo2):
Interface ovpns2 (tap2):
Interface ovpnc1 (tun1):
Interface ovpnc3 (tun3):
Interface ovpns4 (tun4):
Interface wg0 (wg0):
Interface wg1 (wg1):

> On 20. Nov 2023, at 22:16, Franco Fichtner  wrote:
> 
> 
>> On 20. Nov 2023, at 21:56, Kristof Provost  wrote:
>> 
>> I’d look in the direction of just adding a field to struct ifnet with the 
>> original interface name (likely easily done in if_attach()), along with a 
>> new ioctl to retrieve that field.
> 
> ifconfig_get_orig_name() already exists, but apart from wlandebug
> nothing is using it.
> 
> The internally used IFDATA_DRIVERNAME also appears in ifinfo
> (not installed in base) and bsnmpd but that's it.
> 
> if_dname is the target and it exists in ifnet struct along with
> a man page entry in inet(9).
> 
> All that is really missing is a way to print it via ifconfig command.
> 
> 
> Cheers,
> Franco




Re: How to tell if a network interface was renamed (and from what)

2023-11-20 Thread Mike Karels
On 20 Nov 2023, at 14:56, Kristof Provost wrote:

> On 20 Nov 2023, at 21:29, Mike Karels wrote:
>> On 19 Nov 2023, at 15:35, Mina Galić wrote:
>>> Hi Zhenlei,
>>>
>>>
 Since it is just for physical devices, may I propose to have the driver 
 name in their groups ?

 So an if_ure interface ue0 will look like:

 ```
 ue0: flags=1008843 metric 
 0 mtu 1500

 options=60009b

 ether 00:e0:4c:xx:xx:xx
 media: Ethernet autoselect (1000baseT )

 status: active
 +++ groups: ure
 nd6 options=23

 ```

 That does not include the unit number. But could be useful to quickly get 
 the driver name of physical devices.

>>>
>>> Given that currently on FreeBSD the easiest way to tell if something
>>> is a physical device is by checking the *absence* of groups, this
>>> would only really be acceptable if we add an "egress" group like
>>> OpenBSD does, in addition to the driver name.
>>>
>>> If we can't do that, then I think Mike's solution with having the
>>> driver (and unit) as a separate category would be preferable.
>>
>> I have a proof of concept that makes the presumed original name
>> (driver name + unit number) available to ifconfig, which prints
>> the string with everything else in the standard output format.
>> I don't think that is the right solution,
>
> I believe a similar solution has been proposed before, and it failed to cope 
> with things like epair interfaces.

Hmm, epair certainly breaks the rules (well, conventions).  My current
code sees "epair0" for both halves, which may not be what is desired.
epair does some of this by hand, so could have more custom code.

> I’d look in the direction of just adding a field to struct ifnet with the 
> original interface name (likely easily done in if_attach()), along with a new 
> ioctl to retrieve that field.

That may be as good as we can do, although I'm working with netlink
rather than ioctls.

But see the next message...

Mike

> Best regards,
> Kristof



Re: How to tell if a network interface was renamed (and from what)

2023-11-20 Thread Mike Karels
On 20 Nov 2023, at 15:16, Franco Fichtner wrote:

>> On 20. Nov 2023, at 21:56, Kristof Provost  wrote:
>>
>> I’d look in the direction of just adding a field to struct ifnet with the 
>> original interface name (likely easily done in if_attach()), along with a 
>> new ioctl to retrieve that field.
>
> ifconfig_get_orig_name() already exists, but apart from wlandebug
> nothing is using it.

Thanks for pointing that out!  I hadn't noticed it.  I also hadn't thought
of that way to fetch the driver name and unit.

> The internally used IFDATA_DRIVERNAME also appears in ifinfo
> (not installed in base) and bsnmpd but that's it.
>
> if_dname is the target and it exists in ifnet struct along with
> a man page entry in inet(9).
>
> All that is really missing is a way to print it via ifconfig command.

That is trivial to add; I just tested it.  It also has problems with
epair.  Maybe that isn't an issue for this purpose.  I hate to invent
something new when there is something already existing that solves
most of the problem.

Mike

> Cheers,
> Franco



Re: How to tell if a network interface was renamed (and from what)

2023-11-20 Thread Franco Fichtner


> On 20. Nov 2023, at 23:06, Mike Karels  wrote:
> 
> On 20 Nov 2023, at 15:16, Franco Fichtner wrote:
> 
>> All that is really missing is a way to print it via ifconfig command.
> 
> That is trivial to add; I just tested it.  It also has problems with
> epair.  Maybe that isn't an issue for this purpose.

Two things to consider:

Does epair do it the "right way"?  And does it even matter given that this
behaviour hasn't had any exposure and is likely ever going to be used
as input for another tool?

I mean it still tracks the origin in the driver.  This way you can even find
the epair belonging together.  It looks like it should given the design
choices.


Cheers,
Franco



Re: How to tell if a network interface was renamed (and from what)

2023-11-21 Thread Ronald Klop

Interesting.

Is this: /usr/src/tools/tools/ifinfo ?

Regards,
Ronald.

Van: Franco Fichtner 
Datum: maandag, 20 november 2023 22:23
Aan: Kristof Provost 
CC: Mike Karels , "Mina Galic" , Zhenlei Huang 
, Kyle Evans , freebsd-net@freebsd.org
Onderwerp: Re: How to tell if a network interface was renamed (and from what)


FWIW, here is the relevant ifinfo output of a sample machine:

# ifinfo | grep ^Interface
Interface igb0 (igb0):
Interface igb1 (igb1):
Interface igb2 (igb2):
Interface igb3 (igb3):
Interface enc0 (enc0):
Interface lo0 (lo0):
Interface pflog0 (pflog0):
Interface pfsync0 (pfsync0):
Interface lagg0 (lagg0):
Interface igb2_vlan42 (vlan0):
Interface vlan0.1.23 (vlan1):
Interface vlan0.3 (vlan2):
Interface vlan0.5.6.7 (vlan3):
Interface vlan01. (vlan4):
Interface vlan06 (vlan5):
Interface vlan08 (vlan6):
Interface qinq0.123 (vlan7):
Interface gre2 (gre2):
Interface gre0 (gre0):
Interface gif4 (gif4):
Interface gif1 (gif1):
Interface gif0 (gif0):
Interface l2tp0 (ng0):
Interface bridge0 (bridge0):
Interface lo1 (lo1):
Interface lo2 (lo2):
Interface ovpns2 (tap2):
Interface ovpnc1 (tun1):
Interface ovpnc3 (tun3):
Interface ovpns4 (tun4):
Interface wg0 (wg0):
Interface wg1 (wg1):

> On 20. Nov 2023, at 22:16, Franco Fichtner  wrote:
>
>
>> On 20. Nov 2023, at 21:56, Kristof Provost  wrote:
>>
>> I’d look in the direction of just adding a field to struct ifnet with the 
original interface name (likely easily done in if_attach()), along with a new ioctl 
to retrieve that field.
>
> ifconfig_get_orig_name() already exists, but apart from wlandebug
> nothing is using it.
>
> The internally used IFDATA_DRIVERNAME also appears in ifinfo
> (not installed in base) and bsnmpd but that's it.
>
> if_dname is the target and it exists in ifnet struct along with
> a man page entry in inet(9).
>
> All that is really missing is a way to print it via ifconfig command.
>
>
> Cheers,
> Franco

 








Re: How to tell if a network interface was renamed (and from what)

2023-11-21 Thread Franco Fichtner


> On 21. Nov 2023, at 10:51, Ronald Klop  wrote:
> 
> Interesting.
> 
> Is this: /usr/src/tools/tools/ifinfo ?

Yes.



Re: How to tell if a network interface was renamed (and from what)

2023-11-21 Thread Mike Karels
On 21 Nov 2023, at 0:43, Franco Fichtner wrote:

>> On 20. Nov 2023, at 23:06, Mike Karels  wrote:
>>
>> On 20 Nov 2023, at 15:16, Franco Fichtner wrote:
>>
>>> All that is really missing is a way to print it via ifconfig command.
>>
>> That is trivial to add; I just tested it.  It also has problems with
>> epair.  Maybe that isn't an issue for this purpose.
>
> Two things to consider:
>
> Does epair do it the "right way"?  And does it even matter given that this
> behaviour hasn't had any exposure and is likely ever going to be used
> as input for another tool?

epair arguably does it wrong; it doesn't follow the convention of using the
driver name followed by an integer.  However, what it does is practical, and
clearly we don't want to change it now.  Using the driver name as returned
by ifconfig_get_orig_addr displays "epair0" for two interfaces.  If they have
been renamed, the new names will hopefully be suggestive of which is which.

Mina, do you care about epair, or is the behavior I described sufficient
for your purposes?

Mike

> I mean it still tracks the origin in the driver.  This way you can even find
> the epair belonging together.  It looks like it should given the design
> choices.
>
>
> Cheers,
> Franco



Re: How to tell if a network interface was renamed (and from what)

2023-11-21 Thread Mina Galić
Hi Mike,

> Mina, do you care about epair, or is the behavior I described sufficient
> for your purposes? 

I do deeply care about epair, but for me, ifinfo does the
right thing for me:

root@irc:~ # ifinfo | grep Interface
Interface vnet0 (epair30):
Interface lo0 (lo0):

for one. For the other. For the main purpose, figuring out
in cloud-init what the driver of an interface is / if the
interface has been renamed, this is more than sufficient.

> Mike

Thank you very much,

Mina



Re: How to tell if a network interface was renamed (and from what)

2023-11-21 Thread Mike Karels
On 21 Nov 2023, at 12:16, Mina Galić wrote:

> Hi Mike,
>
>> Mina, do you care about epair, or is the behavior I described sufficient
>> for your purposes?
>
> I do deeply care about epair, but for me, ifinfo does the
> right thing for me:
>
> root@irc:~ # ifinfo | grep Interface
> Interface vnet0 (epair30):
> Interface lo0 (lo0):

That's not the whole story for epair.  For example, I get this:

Interface bhyve (vtnet0):
Interface lo0 (lo0):
Interface lo1 (lo1):
Interface foo0a (epair0):
Interface foo0b (epair0):

But if you only need the driver name, it will do.

A problem with ifinfo is that it is not normally installed.
I think it is worth adding a similar feature for the driver name
to ifconfig.

> for one. For the other. For the main purpose, figuring out
> in cloud-init what the driver of an interface is / if the
> interface has been renamed, this is more than sufficient.

Currently I have this for ifconfig -D:

bhyve: flags=1008843 metric 0 
mtu 1500
options=80028
ether 58:9c:fc:0b:0c:10
inet 10.0.3.1 netmask 0xff00 broadcast 10.0.3.255
inet6 fe80::5a9c:fcff:fe0b:c10%bhyve prefixlen 64 scopeid 0x1
inet6 2001:470:c202:3::1 prefixlen 64
media: Ethernet autoselect (10Gbase-T )
status: active
nd6 options=21
drivername: vtnet0

It's a little more work to parse, but I decided that it was useful
for humans, and works with -a.

Mike
>
> Thank you very much,
>
> Mina



Re: How to tell if a network interface was renamed (and from what)

2023-11-21 Thread Jamie Landeg-Jones
Mike Karels  wrote:

> I have a proof of concept that makes the presumed original name
> (driver name + unit number) available to ifconfig, which prints
> the string with everything else in the standard output format.
> I don't think that is the right solution, but the other details
> should be easy.  I'm tempted to print the driver name and unit
> number separately, although possibly as two words using the same
> option.  It should probably be an option rather than a keyword,
> so something like this:
>
> # ifconfig -N interface-name
> igb 1
> #
>
> Or the unit number could be on a separate option.
>
> Comments?

I prefer that idea to the use of "groups" (which can be modified anyway),
though in your example, that should be documented as "driver name" not
"interface name", seeing that the returned value is not actually now
the interface name!

(Similary, if a keyword is decided upon, it should be "driver-name"
not "interface-name")

I realise that writing "interface-name" was probably just muscle-memory,
but just wanted clarification.

No opinion on where to display the unit number - whatever works out
better for you.

Cheers, Jamie




Re: How to tell if a network interface was renamed (and from what)

2023-11-21 Thread Jamie Landeg-Jones
Kristof Provost  wrote:
>
> I believe a similar solution has been proposed before, and it failed to cope 
> with things like epair interfaces.
>
> I’d look in the direction of just adding a field to struct ifnet with the 
> original interface name (likely easily done in if_attach()), along with a new 
> ioctl to retrieve that field.

Not knowing the intricacies of coding that, from an end user point of view,
that method would be perfectly fine too (and does seem a little cleaner,
even if a bit more disruptive codewise)

In other words, I'd be grateful for this functionality - As an end-user,
whilst my individual opinion doesn't really matter, I have no negative
opinion on the various ways of achieving it - whatever works out best for
you guys, and I'll be happy!

Cheers!



Re: How to tell if a network interface was renamed (and from what)

2023-11-21 Thread Mike Karels
On 21 Nov 2023, at 19:35, Jamie Landeg-Jones wrote:

> Mike Karels  wrote:
>
>> I have a proof of concept that makes the presumed original name
>> (driver name + unit number) available to ifconfig, which prints
>> the string with everything else in the standard output format.
>> I don't think that is the right solution, but the other details
>> should be easy.  I'm tempted to print the driver name and unit
>> number separately, although possibly as two words using the same
>> option.  It should probably be an option rather than a keyword,
>> so something like this:
>>
>> # ifconfig -N interface-name
>> igb 1
>> #
>>
>> Or the unit number could be on a separate option.
>>
>> Comments?
>
> I prefer that idea to the use of "groups" (which can be modified anyway),
> though in your example, that should be documented as "driver name" not
> "interface name", seeing that the returned value is not actually now
> the interface name!

Here, interface-name was a placeholder for the current name of the
interface.  My newer code prints "drivername: igb1" at the end of
the list of values for "ifconfig $interface-name" or "ifconfig -a"
if the -D option is given.  I decided that it was better to be able
to get all the translations at once (for humans, anyway).

Mike

> (Similary, if a keyword is decided upon, it should be "driver-name"
> not "interface-name")
>
> I realise that writing "interface-name" was probably just muscle-memory,
> but just wanted clarification.
>
> No opinion on where to display the unit number - whatever works out
> better for you.
>
> Cheers, Jamie



Re: How to tell if a network interface was renamed (and from what)

2023-11-21 Thread Jamie Landeg-Jones
Mike Karels  wrote:

> Here, interface-name was a placeholder for the current name of the
> interface.  My newer code prints "drivername: igb1" at the end of
> the list of values for "ifconfig $interface-name" or "ifconfig -a"
> if the -D option is given.  I decided that it was better to be able
> to get all the translations at once (for humans, anyway).

Ahhh, I get you. Sorry for the confusion.

I think your solution is perfect.

Cheers, Jamie




Re: How to tell if a network interface was renamed (and from what)

2023-11-22 Thread Mike Karels
On 21 Nov 2023, at 19:57, Mike Karels wrote:

> ...  My newer code prints "drivername: igb1" at the end of
> the list of values for "ifconfig $interface-name" or "ifconfig -a"
> if the -D option is given.  I decided that it was better to be able
> to get all the translations at once (for humans, anyway).
>

See https://reviews.freebsd.org/D42721 for the ifconfig change.

Mike