* Set the link layer address on an interface. * * At this time we only support certain types of interfaces, * and we don't allow the length of the address to change. * * Set noinline to be dtrace-friendly */
| 3782 | * Set noinline to be dtrace-friendly |
| 3783 | */ |
| 3784 | __noinline int |
| 3785 | if_setlladdr(struct ifnet *ifp, const u_char *lladdr, int len) |
| 3786 | { |
| 3787 | struct sockaddr_dl *sdl; |
| 3788 | struct ifaddr *ifa; |
| 3789 | struct ifreq ifr; |
| 3790 | |
| 3791 | ifa = ifp->if_addr; |
| 3792 | if (ifa == NULL) |
| 3793 | return (EINVAL); |
| 3794 | |
| 3795 | sdl = (struct sockaddr_dl *)ifa->ifa_addr; |
| 3796 | if (sdl == NULL) |
| 3797 | return (EINVAL); |
| 3798 | |
| 3799 | if (len != sdl->sdl_alen) /* don't allow length to change */ |
| 3800 | return (EINVAL); |
| 3801 | |
| 3802 | switch (ifp->if_type) { |
| 3803 | case IFT_ETHER: |
| 3804 | case IFT_XETHER: |
| 3805 | case IFT_L2VLAN: |
| 3806 | case IFT_BRIDGE: |
| 3807 | case IFT_IEEE8023ADLAG: |
| 3808 | bcopy(lladdr, LLADDR(sdl), len); |
| 3809 | break; |
| 3810 | default: |
| 3811 | return (ENODEV); |
| 3812 | } |
| 3813 | |
| 3814 | /* |
| 3815 | * If the interface is already up, we need |
| 3816 | * to re-init it in order to reprogram its |
| 3817 | * address filter. |
| 3818 | */ |
| 3819 | if ((ifp->if_flags & IFF_UP) != 0) { |
| 3820 | if (ifp->if_ioctl) { |
| 3821 | ifp->if_flags &= ~IFF_UP; |
| 3822 | ifr.ifr_flags = ifp->if_flags & 0xffff; |
| 3823 | ifr.ifr_flagshigh = ifp->if_flags >> 16; |
| 3824 | (*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, (caddr_t)&ifr); |
| 3825 | ifp->if_flags |= IFF_UP; |
| 3826 | ifr.ifr_flags = ifp->if_flags & 0xffff; |
| 3827 | ifr.ifr_flagshigh = ifp->if_flags >> 16; |
| 3828 | (*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, (caddr_t)&ifr); |
| 3829 | } |
| 3830 | } |
| 3831 | EVENTHANDLER_INVOKE(iflladdr_event, ifp); |
| 3832 | |
| 3833 | return (0); |
| 3834 | } |
| 3835 | |
| 3836 | /* |
| 3837 | * Compat function for handling basic encapsulation requests. |
no outgoing calls
no test coverage detected