The branch main has been updated by melifaro:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=f414f37e38614daabc1d10e37efec9ef7fa620f3

commit f414f37e38614daabc1d10e37efec9ef7fa620f3
Author:     Alexander V. Chernikov <melif...@freebsd.org>
AuthorDate: 2023-06-14 13:04:10 +0000
Commit:     Alexander V. Chernikov <melif...@freebsd.org>
CommitDate: 2023-06-16 07:19:21 +0000

    ifconfig: remove global 'ifr' usage from ifmedia.c & remove 'ifr'.
    
    Reviewed by:    kp
    Differential Revision: https://reviews.freebsd.org/D40535
    MFC after:      2 weeks
---
 sbin/ifconfig/ifconfig.c |  8 --------
 sbin/ifconfig/ifconfig.h |  1 -
 sbin/ifconfig/ifmedia.c  | 24 ++++++++----------------
 3 files changed, 8 insertions(+), 25 deletions(-)

diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index 5ac217858057..24462f76e96c 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -85,14 +85,6 @@ static const char rcsid[] =
 
 ifconfig_handle_t *lifh;
 
-/*
- * Since "struct ifreq" is composed of various union members, callers
- * should pay special attention to interpret the value.
- * (.e.g. little/big endian difference in the structure.)
- */
-struct ifreq ifr;
-
-//char name[IFNAMSIZ];
 #ifdef WITHOUT_NETLINK
 static char    *descr = NULL;
 static size_t  descrlen = 64;
diff --git a/sbin/ifconfig/ifconfig.h b/sbin/ifconfig/ifconfig.h
index 334027c36d89..49f907367b7a 100644
--- a/sbin/ifconfig/ifconfig.h
+++ b/sbin/ifconfig/ifconfig.h
@@ -251,7 +251,6 @@ struct option {
 void   opt_register(struct option *);
 
 extern ifconfig_handle_t *lifh;
-extern struct ifreq ifr;
 extern int allmedia;
 extern int exit_code;
 extern char *f_inet, *f_inet6, *f_ether, *f_addr;
diff --git a/sbin/ifconfig/ifmedia.c b/sbin/ifconfig/ifmedia.c
index 122756207d1b..395789916edb 100644
--- a/sbin/ifconfig/ifmedia.c
+++ b/sbin/ifconfig/ifmedia.c
@@ -179,10 +179,11 @@ setifmediacallback(if_ctx *ctx, void *arg)
 {
        struct ifmediareq *ifmr = (struct ifmediareq *)arg;
        static bool did_it = false;
+       struct ifreq ifr = {};
 
        if (!did_it) {
                ifr.ifr_media = ifmr->ifm_current;
-               if (ioctl_ctx(ctx, SIOCSIFMEDIA, (caddr_t)&ifr) < 0)
+               if (ioctl_ctx_ifr(ctx, SIOCSIFMEDIA, &ifr) < 0)
                        err(1, "SIOCSIFMEDIA (media)");
                free(ifmr);
                did_it = true;
@@ -208,11 +209,9 @@ setmedia(if_ctx *ctx, const char *val, int d __unused)
         */
        subtype = get_media_subtype(ifmr->ifm_ulist[0], val);
 
-       strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name));
-       ifr.ifr_media = (ifmr->ifm_current & IFM_IMASK) |
+       ifmr->ifm_current = (ifmr->ifm_current & IFM_IMASK) |
            IFM_TYPE(ifmr->ifm_ulist[0]) | subtype;
 
-       ifmr->ifm_current = ifr.ifr_media;
        callback_register(setifmediacallback, (void *)ifmr);
 }
 
@@ -240,18 +239,15 @@ domediaopt(if_ctx *ctx, const char *val, bool clear)
 
        options = get_media_options(ifmr->ifm_ulist[0], val);
 
-       strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name));
-       ifr.ifr_media = ifmr->ifm_current;
        if (clear)
-               ifr.ifr_media &= ~options;
+               ifmr->ifm_current &= ~options;
        else {
                if (options & IFM_HDX) {
-                       ifr.ifr_media &= ~IFM_FDX;
+                       ifmr->ifm_current &= ~IFM_FDX;
                        options &= ~IFM_HDX;
                }
-               ifr.ifr_media |= options;
+               ifmr->ifm_current |= options;
        }
-       ifmr->ifm_current = ifr.ifr_media;
        callback_register(setifmediacallback, (void *)ifmr);
 }
 
@@ -267,10 +263,8 @@ setmediainst(if_ctx *ctx, const char *val, int d __unused)
        if (inst < 0 || inst > (int)IFM_INST_MAX)
                errx(1, "invalid media instance: %s", val);
 
-       strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name));
-       ifr.ifr_media = (ifmr->ifm_current & ~IFM_IMASK) | inst << IFM_ISHIFT;
+       ifmr->ifm_current = (ifmr->ifm_current & ~IFM_IMASK) | inst << 
IFM_ISHIFT;
 
-       ifmr->ifm_current = ifr.ifr_media;
        callback_register(setifmediacallback, (void *)ifmr);
 }
 
@@ -284,10 +278,8 @@ setmediamode(if_ctx *ctx, const char *val, int d __unused)
 
        mode = get_media_mode(ifmr->ifm_ulist[0], val);
 
-       strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name));
-       ifr.ifr_media = (ifmr->ifm_current & ~IFM_MMASK) | mode;
+       ifmr->ifm_current = (ifmr->ifm_current & ~IFM_MMASK) | mode;
 
-       ifmr->ifm_current = ifr.ifr_media;
        callback_register(setifmediacallback, (void *)ifmr);
 }
 

Reply via email to