/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 2001 Networks Associates Technology, Inc.4* All rights reserved.5*6* This software was developed for the FreeBSD Project by NAI Labs, the7* Security Research Division of Network Associates, Inc. under8* DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA9* CHATS research program.10*11* Redistribution and use in source and binary forms, with or without12* modification, are permitted provided that the following conditions13* are met:14* 1. Redistributions of source code must retain the above copyright15* notice, this list of conditions and the following disclaimer.16* 2. Redistributions in binary form must reproduce the above copyright17* notice, this list of conditions and the following disclaimer in the18* documentation and/or other materials provided with the distribution.19* 3. The name of the author may not be used to endorse or promote20* products derived from this software without specific prior written21* permission.22*23* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND24* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE25* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE26* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE27* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL28* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS29* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)30* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT31* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY32* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF33* SUCH DAMAGE.34*/3536#include <sys/param.h>37#include <sys/ioctl.h>38#include <sys/mac.h>39#include <sys/socket.h>40#include <sys/sockio.h>4142#include <net/if.h>43#include <net/route.h>4445#include <stdio.h>46#include <stdlib.h>47#include <string.h>4849#include "ifconfig.h"5051static void52maclabel_status(if_ctx *ctx)53{54struct ifreq ifr;55mac_t label;56char *label_text;5758memset(&ifr, 0, sizeof(ifr));59strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name));6061if (mac_prepare_ifnet_label(&label) == -1)62return;63ifr.ifr_ifru.ifru_data = (void *)label;64if (ioctl_ctx(ctx, SIOCGIFMAC, &ifr) == -1)65goto mac_free;666768if (mac_to_text(label, &label_text) == -1)69goto mac_free;7071if (strlen(label_text) != 0)72printf("\tmaclabel %s\n", label_text);73free(label_text);7475mac_free:76mac_free(label);77}7879static void80setifmaclabel(if_ctx *ctx, const char *val, int d __unused)81{82struct ifreq ifr;83mac_t label;84int error;8586if (mac_from_text(&label, val) == -1) {87perror(val);88return;89}9091memset(&ifr, 0, sizeof(ifr));92strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name));93ifr.ifr_ifru.ifru_data = (void *)label;9495error = ioctl(ctx->io_s, SIOCSIFMAC, &ifr);96mac_free(label);97if (error == -1)98perror("setifmac");99}100101static struct cmd mac_cmds[] = {102DEF_CMD_ARG("maclabel", setifmaclabel),103};104static struct afswtch af_mac = {105.af_name = "af_maclabel",106.af_af = AF_UNSPEC,107.af_other_status = maclabel_status,108};109110static __constructor void111mac_ctor(void)112{113size_t i;114115for (i = 0; i < nitems(mac_cmds); i++)116cmd_register(&mac_cmds[i]);117af_register(&af_mac);118}119120121