git: 9a7c520a7811 - main - ifp: add if_setdescr() / if_freedesrt() methods
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 24 Sep 2022 20:14:49 UTC
The branch main has been updated by melifaro:
URL: https://cgit.FreeBSD.org/src/commit/?id=9a7c520a7811a036a8140effb352f44ad5640c0e
commit 9a7c520a7811a036a8140effb352f44ad5640c0e
Author: Alexander V. Chernikov <melifaro@FreeBSD.org>
AuthorDate: 2022-09-24 19:37:29 +0000
Commit: Alexander V. Chernikov <melifaro@FreeBSD.org>
CommitDate: 2022-09-24 19:42:42 +0000
ifp: add if_setdescr() / if_freedesrt() methods
Add methods for setting and removing the description from the interface,
so the external users can manage it without using ioctl API.
MFC after: 2 weeks
---
sys/net/if.c | 30 +++++++++++++++++++++---------
sys/net/if_var.h | 2 ++
2 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/sys/net/if.c b/sys/net/if.c
index ffaf7d004511..7446fb492436 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -653,7 +653,7 @@ if_free_deferred(epoch_context_t ctx)
for (int i = 0; i < IFCOUNTERS; i++)
counter_u64_free(ifp->if_counters[i]);
- free(ifp->if_description, M_IFDESCR);
+ if_freedescr(ifp->if_description);
free(ifp->if_hw_addr, M_IFADDR);
free(ifp, M_IFNET);
}
@@ -2478,7 +2478,7 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data, struct thread *td)
int new_flags, temp_flags;
size_t namelen, onamelen;
size_t descrlen, nvbuflen;
- char *descrbuf, *odescrbuf;
+ char *descrbuf;
char new_name[IFNAMSIZ];
char old_name[IFNAMSIZ], strbuf[IFNAMSIZ + 8];
struct ifaddr *ifa;
@@ -2615,18 +2615,13 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data, struct thread *td)
error = copyin(ifr_buffer_get_buffer(ifr), descrbuf,
ifr_buffer_get_length(ifr) - 1);
if (error) {
- free(descrbuf, M_IFDESCR);
+ if_freedescr(descrbuf);
break;
}
}
- sx_xlock(&ifdescr_sx);
- odescrbuf = ifp->if_description;
- ifp->if_description = descrbuf;
- sx_xunlock(&ifdescr_sx);
-
+ if_setdescr(ifp, descrbuf);
getmicrotime(&ifp->if_lastchange);
- free(odescrbuf, M_IFDESCR);
break;
case SIOCGIFFIB:
@@ -4267,6 +4262,23 @@ if_getcapenable(if_t ifp)
return ((struct ifnet *)ifp)->if_capenable;
}
+void
+if_setdescr(if_t ifp, char *descrbuf)
+{
+ sx_xlock(&ifdescr_sx);
+ char *odescrbuf = ifp->if_description;
+ ifp->if_description = descrbuf;
+ sx_xunlock(&ifdescr_sx);
+
+ if_freedescr(odescrbuf);
+}
+
+void
+if_freedescr(char *descrbuf)
+{
+ free(descrbuf, M_IFDESCR);
+}
+
/*
* This is largely undesirable because it ties ifnet to a device, but does
* provide flexiblity for an embedded product vendor. Should be used with
diff --git a/sys/net/if_var.h b/sys/net/if_var.h
index 4f138f0368c0..ce36beadcfd5 100644
--- a/sys/net/if_var.h
+++ b/sys/net/if_var.h
@@ -739,6 +739,8 @@ int if_setcapenable(if_t ifp, int capenable);
int if_setcapenablebit(if_t ifp, int setcap, int clearcap);
int if_getcapenable(if_t ifp);
const char *if_getdname(if_t ifp);
+void if_setdescr(if_t ifp, char *descrbuf);
+void if_freedescr(char *descrbuf);
int if_setdev(if_t ifp, void *dev);
int if_setdrvflagbits(if_t ifp, int if_setflags, int clear_flags);
int if_getdrvflags(if_t ifp);