git: a9dcee4334b2 - stable/13 - ifp: add if_setdescr() / if_freedesrt() methods
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 23 Jan 2023 22:12:28 UTC
The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=a9dcee4334b26c41ee3ce78ccb48d61ce21bc4f4 commit a9dcee4334b26c41ee3ce78ccb48d61ce21bc4f4 Author: Alexander V. Chernikov <melifaro@FreeBSD.org> AuthorDate: 2022-09-24 19:37:29 +0000 Commit: Alexander V. Chernikov <melifaro@FreeBSD.org> CommitDate: 2023-01-23 22:10:07 +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 (cherry picked from commit 9a7c520a7811a036a8140effb352f44ad5640c0e) --- 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 7423c4963f57..813525c2e7bd 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -703,7 +703,7 @@ if_free_internal(struct ifnet *ifp) 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); } @@ -2486,7 +2486,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; - char *descrbuf, *odescrbuf; + char *descrbuf; char new_name[IFNAMSIZ]; struct ifaddr *ifa; struct sockaddr_dl *sdl; @@ -2578,18 +2578,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: @@ -4157,6 +4152,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 48da169fd1d6..6738f00a4f08 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -708,6 +708,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);