Print this page
2553 mac address should be a dladm link property

@@ -147,22 +147,22 @@
                         get_speed, get_channel, get_powermode, get_radio,
                         get_duplex, get_link_state, get_binary, get_uint32,
                         get_flowctl, get_maxbw, get_cpus, get_priority,
                         get_tagmode, get_range, get_stp, get_bridge_forward,
                         get_bridge_pvid, get_protection, get_rxrings,
-                        get_txrings, get_cntavail,
+                        get_txrings, get_cntavail, get_macaddr,
                         get_allowedips, get_allowedcids, get_pool,
                         get_rings_range, get_linkmode_prop;
 
 static pd_setf_t        set_zone, set_rate, set_powermode, set_radio,
                         set_public_prop, set_resource, set_stp_prop,
-                        set_bridge_forward, set_bridge_pvid;
+                        set_bridge_forward, set_bridge_pvid, set_macaddr;
 
 static pd_checkf_t      check_zone, check_autopush, check_rate, check_hoplimit,
                         check_encaplim, check_uint32, check_maxbw, check_cpus,
                         check_stp_prop, check_bridge_pvid, check_allowedips,
-                        check_allowedcids, check_rings,
+                        check_allowedcids, check_rings, check_macaddr,
                         check_pool, check_prop;
 
 struct prop_desc {
         /*
          * link property name

@@ -361,10 +361,12 @@
 
         { MAC_PROP_MAX_TXHWCLNT_AVAIL,  sizeof (uint_t), "txhwclnt-available"},
 
         { MAC_PROP_IB_LINKMODE, sizeof (uint32_t),      "linkmode"},
 
+        { MAC_PROP_MACADDRESS,  sizeof (mac_addrprop_t), "mac-address"},
+
         { MAC_PROP_PRIVATE,     0,                      "driver-private"}
 };
 
 typedef struct bridge_public_prop_s {
         const char      *bpp_name;

@@ -680,10 +682,15 @@
         { "protection", { "--", RESET_VAL },
             link_protect_vals, VALCNT(link_protect_vals),
             set_resource, NULL, get_protection, check_prop, 0,
             DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
 
+        { "mac-address", { "", 0 }, NULL, 0,
+            set_macaddr, NULL, get_macaddr, check_macaddr, PD_CHECK_ALLOC,
+            DATALINK_CLASS_PHYS|DATALINK_CLASS_AGGR|DATALINK_CLASS_VNIC|
+            DATALINK_CLASS_SIMNET, DATALINK_ANY_MEDIATYPE },
+
         { "allowed-ips", { "--", 0 },
             NULL, 0, set_resource, NULL,
             get_allowedips, check_allowedips, PD_CHECK_ALLOC,
             DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
 

@@ -723,11 +730,10 @@
             DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
 
         { "txhwclnt-available", { "", 0 }, NULL, 0,
             NULL, NULL, get_cntavail, NULL, 0,
             DATALINK_CLASS_ALL, DATALINK_ANY_MEDIATYPE },
-
 };
 
 #define DLADM_MAX_PROPS (sizeof (prop_table) / sizeof (prop_desc_t))
 
 static resource_prop_t rsrc_prop_table[] = {

@@ -2243,10 +2249,80 @@
             flags, perm_flags));
 }
 
 /* ARGSUSED */
 static dladm_status_t
+get_macaddr(dladm_handle_t handle, prop_desc_t *pdp, datalink_id_t linkid,
+    char **prop_val, uint_t *val_cnt, datalink_media_t media, uint_t flags,
+    uint_t *perm_flags)
+{
+        mac_addrprop_t  addrprop;
+        dladm_status_t  status;
+
+        status = i_dladm_get_public_prop(handle, linkid, pdp->pd_name,
+            flags, perm_flags, &addrprop, sizeof (addrprop));
+        if (status != DLADM_STATUS_OK)
+                return (status);
+
+        (void) _link_ntoa(addrprop.ma_addr, prop_val[0], addrprop.ma_len,
+            IFT_OTHER);
+
+        *val_cnt = 1;
+
+        return (DLADM_STATUS_OK);
+}
+
+/* ARGSUSED */
+static dladm_status_t
+set_macaddr(dladm_handle_t handle, prop_desc_t *pdp, datalink_id_t linkid,
+    val_desc_t *vdp, uint_t val_cnt, uint_t flags, datalink_media_t media)
+{
+        if (val_cnt != 1)
+                return (DLADM_STATUS_BADVALCNT);
+
+        return (set_public_prop(handle, pdp, linkid, vdp, val_cnt,
+            flags, media));
+}
+
+/* ARGSUSED */
+static dladm_status_t
+check_macaddr(dladm_handle_t handle, prop_desc_t *pdp, datalink_id_t linkid,
+    char **prop_val, uint_t *val_cntp, uint_t flags, val_desc_t **vdpp,
+    datalink_media_t media)
+{
+        mac_addrprop_t  *addrprop;
+        val_desc_t      *vdp = *vdpp;
+        uint_t          val_cnt = *val_cntp;
+        uchar_t         *macaddr;
+        int             maclen;
+        dladm_status_t  status = DLADM_STATUS_OK;
+
+        if (val_cnt != 1)
+                return (DLADM_STATUS_BADVALCNT);
+
+        macaddr = _link_aton(*prop_val, &maclen);
+        if (macaddr == NULL)
+                return (DLADM_STATUS_BADVAL);
+
+        addrprop = malloc(sizeof (mac_addrprop_t));
+        if (addrprop == NULL) {
+                status = DLADM_STATUS_NOMEM;
+                goto out;
+        }
+
+        (void) memcpy(addrprop->ma_addr, macaddr, maclen);
+        addrprop->ma_len = maclen;
+
+        vdp->vd_val = (uintptr_t)addrprop;
+
+out:
+        free(macaddr);
+        return (status);
+}
+
+/* ARGSUSED */
+static dladm_status_t
 set_resource(dladm_handle_t handle, prop_desc_t *pdp,
     datalink_id_t linkid, val_desc_t *vdp, uint_t val_cnt,
     uint_t flags, datalink_media_t media)
 {
         mac_resource_props_t    mrp;