1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-10-19 02:29:40 +00:00

Fix special status reporting. Prior to the reorg there was

special-purpose code to display status for an interface for
state that was not address-oriented.  This status reporting
was merged in to the address-oriented status reporting but
did not work for link address reporting (as discovered with
fwip interfaces).  Correct this mis-merge and eliminate the
bogus kludge that was used for link-level address reporting.

o add an af_other_status method for an address family for
  reporting status of things like media, vlan, etc.
o call the af_other_status methods after reporting address
  status for an interface
o special-case link address status; when reporting all
  status for an interface invoke it specially prior to
  reporting af_other_status methods (since it requires the
  sockaddr_dl that is passed in to status separately from
  the rtmsg address state)
o correct the calling convention for link address status;
  don't cast types, construct the proper parameter

This fixes ifconfig on fwip interfaces.
This commit is contained in:
Sam Leffler 2004-12-31 19:46:27 +00:00
parent 5040559548
commit 90c4b74cbe
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=139494
7 changed files with 44 additions and 18 deletions

View File

@ -36,6 +36,7 @@ static const char rcsid[] =
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <net/route.h> /* for RTX_IFA */
#include <err.h>
#include <stdio.h>
@ -53,9 +54,10 @@ static struct ifreq link_ridreq;
static void
link_status(int s __unused, const struct rt_addrinfo *info)
{
const struct sockaddr_dl *sdl = (const struct sockaddr_dl *)info;
const struct sockaddr_dl *sdl =
(const struct sockaddr_dl *) info->rti_info[RTAX_IFA];
if (sdl->sdl_alen > 0) {
if (sdl != NULL && sdl->sdl_alen > 0) {
if (sdl->sdl_type == IFT_ETHER &&
sdl->sdl_alen == ETHER_ADDR_LEN)
printf("\tether %s\n",

View File

@ -102,7 +102,7 @@ static void usage(void);
static struct afswtch *af_getbyname(const char *name);
static struct afswtch *af_getbyfamily(int af);
static void af_all_status(int, const struct rt_addrinfo *sdl);
static void af_other_status(int);
static struct option *opts = NULL;
@ -391,18 +391,18 @@ af_getbyfamily(int af)
}
static void
af_all_status(int s, const struct rt_addrinfo *sdl)
af_other_status(int s)
{
struct afswtch *afp;
uint8_t afmask[howmany(AF_MAX, NBBY)];
memset(afmask, 0, sizeof(afmask));
for (afp = afs; afp != NULL; afp = afp->af_next) {
if (afp->af_status == NULL)
if (afp->af_other_status == NULL)
continue;
if (afp->af_af != AF_UNSPEC && isset(afmask, afp->af_af))
continue;
afp->af_status(s, sdl);
afp->af_other_status(s);
setbit(afmask, afp->af_af);
}
}
@ -876,10 +876,25 @@ status(const struct afswtch *afp, int addrcount, struct sockaddr_dl *sdl,
addrcount--;
ifam = (struct ifa_msghdr *)((char *)ifam + ifam->ifam_msglen);
}
if (allfamilies || afp->af_af == AF_LINK) {
const struct afswtch *lafp;
/*
* Hack; the link level address is received separately
* from the routing information so any address is not
* handled above. Cobble together an entry and invoke
* the status method specially.
*/
lafp = af_getbyname("lladdr");
if (lafp != NULL) {
info.rti_info[RTAX_IFA] = (struct sockaddr *)sdl;
lafp->af_status(s, &info);
}
}
if (allfamilies)
af_all_status(s, (const struct rt_addrinfo *) sdl);
else if (afp->af_status != NULL)
afp->af_status(s, (const struct rt_addrinfo *) sdl);
af_other_status(s);
else if (afp->af_other_status != NULL)
afp->af_other_status(s);
strncpy(ifs.ifs_name, name, sizeof ifs.ifs_name);
if (ioctl(s, SIOCGIFSTATUS, &ifs) == 0)

View File

@ -85,8 +85,17 @@ enum {
struct afswtch {
const char *af_name; /* as given on cmd line, e.g. "inet" */
short af_af; /* AF_* */
/* print status method */
/*
* Status is handled one of two ways; if there is an
* address associated with the interface then the
* associated address family af_status method is invoked
* with the appropriate addressin info. Otherwise, if
* all possible info is to be displayed and af_other_status
* is defined then it is invoked after all address status
* is presented.
*/
void (*af_status)(int, const struct rt_addrinfo *);
void (*af_other_status)(int);
/* parse address method */
void (*af_getaddr)(const char *, int);
/* parse prefix method (IPv6) */

View File

@ -1282,7 +1282,7 @@ printkey(const struct ieee80211req_key *ik)
}
static void
ieee80211_status(int s, const struct rt_addrinfo *info __unused)
ieee80211_status(int s)
{
static const uint8_t zerobssid[IEEE80211_ADDR_LEN];
enum ieee80211_opmode opmode = get80211opmode(s);
@ -1792,7 +1792,7 @@ static struct cmd ieee80211_cmds[] = {
static struct afswtch af_ieee80211 = {
.af_name = "af_ieee80211",
.af_af = AF_UNSPEC,
.af_status = ieee80211_status,
.af_other_status = ieee80211_status,
};
static __constructor void

View File

@ -50,7 +50,7 @@
#include "ifconfig.h"
static void
maclabel_status(int s, const struct rt_addrinfo *info)
maclabel_status(int s)
{
struct ifreq ifr;
mac_t label;
@ -105,7 +105,7 @@ static struct cmd mac_cmds[] = {
static struct afswtch af_mac = {
.af_name = "af_maclabel",
.af_af = AF_UNSPEC,
.af_status = maclabel_status,
.af_other_status = maclabel_status,
};
static __constructor void

View File

@ -103,7 +103,7 @@ static struct ifmedia_description *get_subtype_desc(int,
struct ifmedia_type_to_subtype *ttos);
static void
media_status(int s, const struct rt_addrinfo *info __unused)
media_status(int s)
{
struct ifmediareq ifmr;
int *media_list, i;
@ -787,7 +787,7 @@ static struct cmd media_cmds[] = {
static struct afswtch af_media = {
.af_name = "af_media",
.af_af = AF_UNSPEC,
.af_status = media_status,
.af_other_status = media_status,
};
static __constructor void

View File

@ -62,7 +62,7 @@ static int __tag = 0;
static int __have_tag = 0;
static void
vlan_status(int s, const struct rt_addrinfo *info __unused)
vlan_status(int s)
{
struct vlanreq vreq;
@ -157,7 +157,7 @@ static struct cmd vlan_cmds[] = {
static struct afswtch af_vlan = {
.af_name = "af_vlan",
.af_af = AF_UNSPEC,
.af_status = vlan_status,
.af_other_status = vlan_status,
};
static __constructor void