[PATCH v3] netifd: add devtype to ubus call

Hans Dedecker dedeckeh at gmail.com
Mon Jan 10 11:29:46 PST 2022


On Mon, Jan 10, 2022 at 4:55 PM Florian Eckert <fe at dev.tdt.de> wrote:
>
> Hello Hans,
>
> thanks for you review.
>
> >> +--- a/system.h
> >> ++++ b/system.h
> >> +@@ -23,6 +23,42 @@
> >> + #include "iprule.h"
> >> + #include "utils.h"
> >> +
> >> ++static const unsigned short netdev_type_number[] = {
> >> ++      ARPHRD_NETROM, ARPHRD_ETHER, ARPHRD_EETHER, ARPHRD_AX25,
> >> ++      ARPHRD_PRONET, ARPHRD_CHAOS, ARPHRD_IEEE802, ARPHRD_ARCNET,
> >> ++      ARPHRD_APPLETLK, ARPHRD_DLCI, ARPHRD_ATM, ARPHRD_METRICOM,
> >> ++      ARPHRD_IEEE1394, ARPHRD_EUI64, ARPHRD_INFINIBAND, ARPHRD_SLIP,
> >> ++      ARPHRD_CSLIP, ARPHRD_SLIP6, ARPHRD_CSLIP6, ARPHRD_RSRVD,
> >> ++      ARPHRD_ADAPT, ARPHRD_ROSE, ARPHRD_X25, ARPHRD_HWX25,
> >> ++      ARPHRD_PPP, ARPHRD_CISCO, ARPHRD_LAPB, ARPHRD_DDCMP,
> >> ++      ARPHRD_RAWHDLC, ARPHRD_TUNNEL, ARPHRD_TUNNEL6, ARPHRD_FRAD,
> >> ++      ARPHRD_SKIP, ARPHRD_LOOPBACK, ARPHRD_LOCALTLK, ARPHRD_FDDI,
> >> ++      ARPHRD_BIF, ARPHRD_SIT, ARPHRD_IPDDP, ARPHRD_IPGRE,
> >> ++      ARPHRD_PIMREG, ARPHRD_HIPPI, ARPHRD_ASH, ARPHRD_ECONET,
> >> ++      ARPHRD_IRDA, ARPHRD_FCPP, ARPHRD_FCAL, ARPHRD_FCPL,
> >> ++      ARPHRD_FCFABRIC, ARPHRD_IEEE80211, ARPHRD_IEEE80211_PRISM,
> >> ++      ARPHRD_IEEE80211_RADIOTAP, ARPHRD_PHONET, ARPHRD_PHONET_PIPE,
> >> ++      ARPHRD_IEEE802154, ARPHRD_VOID, ARPHRD_NONE
> >> ++};
> >> ++
> >> ++static const char *const netdev_type_name[] = {
> >> ++      "netrom", "ethernet", "eethernet", "ax25",
> >> ++      "pronet", "chaos", "ieee802", "arcnet",
> >> ++      "appletlk", "dlci", "atm", "metricom",
> >> ++      "ieee1394", "eui64", "infiniband", "slip",
> >> ++      "cslip", "slip6", "cslip6", "rsrvd",
> >> ++      "adapt", "rose", "x25", "hwx25",
> >> ++      "ppp", "cisco", "lapb", "ddcmp",
> >> ++      "rawhdlc", "tunnel", "tunnel6", "frad",
> >> ++      "skip", "loopback", "localtlk", "fddi",
> >> ++      "bif", "sit", "ipddp", "ipgre",
> >> ++      "pimreg", "hippi", "ash", "econet",
> >> ++      "irda", "fcpp", "fcal", "fcpl",
> >> ++      "fcfabric", "ieee80211", "ie80211-prism",
> >> ++      "ieee80211-radiotap", "phonet", "phonet-pipe",
> >> ++      "ieee802154", "void", "none"
> >> ++};
> > Merge these two arrays into one array, each entry having the netdev
> > type number and the corresponding string.
> > Implement a function which uses the array and takes as argument the
> > netdev type number and returns the corresponding string
>
> I am not quite sure if I have understood this correctly.
> If you take a look at the include where the ARPHRD are defined.
> https://elixir.bootlin.com/linux/v5.16-rc1/source/include/uapi/linux/if_arp.h
> Then the array must have 65535 entries ARPHRD_VOID is at position
> 0xFFFF.
> That's quite a lot for the fact that there are 58 ids.
>
> This is the code I would use?
>
> static const char * const netdev_type[] = {
>   [ARPHRD_NETROM] = "netrom",
>   [ARPHRD_ETHER] = "ethernet",
> ...
> ...
> };
>
> Or should I define an array of netdev_type structs?
This is indeed what I had in mind

Hans
>
> struct netdev_type {
>    const char *name;
>    unsigned short number;
> };
>
> #define DEV_TYPE(_name, _number) \
> {                                \
>    .name = _name,                 \
>    .number = _number              \
> }                                \
>
>
> static const struct netdev_type netdev_types[] = {
> {
>    DEV_TYPE("netrom", ARPHRD_NETROM),
>    DEV_TYPE("ethernet", ARPHRD_ETHER),
> ...
> ...
> };
>
> Best Regards
> Florian



More information about the openwrt-devel mailing list