dladm.c (13994ee8) | dladm.c (f4b3ec61) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 5 unchanged lines hidden (view full) --- 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21/* | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 5 unchanged lines hidden (view full) --- 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21/* |
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. | 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. |
23 * Use is subject to license terms. 24 */ 25 26#pragma ident "%Z%%M% %I% %E% SMI" 27 28#include <stdio.h> 29#include <ctype.h> 30#include <locale.h> --- 80 unchanged lines hidden (view full) --- 111static cmdfunc_t do_show_link, do_show_dev, do_show_wifi; 112static cmdfunc_t do_create_aggr, do_delete_aggr, do_add_aggr, do_remove_aggr; 113static cmdfunc_t do_modify_aggr, do_show_aggr, do_up_aggr, do_down_aggr; 114static cmdfunc_t do_scan_wifi, do_connect_wifi, do_disconnect_wifi; 115static cmdfunc_t do_show_linkprop, do_set_linkprop, do_reset_linkprop; 116static cmdfunc_t do_create_secobj, do_delete_secobj, do_show_secobj; 117static cmdfunc_t do_init_linkprop, do_init_secobj; 118 | 23 * Use is subject to license terms. 24 */ 25 26#pragma ident "%Z%%M% %I% %E% SMI" 27 28#include <stdio.h> 29#include <ctype.h> 30#include <locale.h> --- 80 unchanged lines hidden (view full) --- 111static cmdfunc_t do_show_link, do_show_dev, do_show_wifi; 112static cmdfunc_t do_create_aggr, do_delete_aggr, do_add_aggr, do_remove_aggr; 113static cmdfunc_t do_modify_aggr, do_show_aggr, do_up_aggr, do_down_aggr; 114static cmdfunc_t do_scan_wifi, do_connect_wifi, do_disconnect_wifi; 115static cmdfunc_t do_show_linkprop, do_set_linkprop, do_reset_linkprop; 116static cmdfunc_t do_create_secobj, do_delete_secobj, do_show_secobj; 117static cmdfunc_t do_init_linkprop, do_init_secobj; 118 |
119static void show_linkprop_onelink(void *, const char *); 120 |
|
119static void link_stats(const char *, uint_t); 120static void aggr_stats(uint32_t, uint_t); 121static void dev_stats(const char *dev, uint32_t); 122 123static void get_mac_stats(const char *, pktsum_t *); 124static void get_link_stats(const char *, pktsum_t *); 125static uint64_t mac_ifspeed(const char *); 126static char *mac_link_state(const char *); --- 2208 unchanged lines hidden (view full) --- 2335 uint_t pl_count; 2336 char *pl_buf; 2337} prop_list_t; 2338 2339typedef struct show_linkprop_state { 2340 const char *ls_link; 2341 char *ls_line; 2342 char **ls_propvals; | 121static void link_stats(const char *, uint_t); 122static void aggr_stats(uint32_t, uint_t); 123static void dev_stats(const char *dev, uint32_t); 124 125static void get_mac_stats(const char *, pktsum_t *); 126static void get_link_stats(const char *, pktsum_t *); 127static uint64_t mac_ifspeed(const char *); 128static char *mac_link_state(const char *); --- 2208 unchanged lines hidden (view full) --- 2337 uint_t pl_count; 2338 char *pl_buf; 2339} prop_list_t; 2340 2341typedef struct show_linkprop_state { 2342 const char *ls_link; 2343 char *ls_line; 2344 char **ls_propvals; |
2345 prop_list_t *ls_proplist; |
|
2343 boolean_t ls_parseable; 2344 boolean_t ls_persist; 2345 boolean_t ls_header; 2346} show_linkprop_state_t; 2347 2348static void 2349free_props(prop_list_t *list) 2350{ --- 64 unchanged lines hidden (view full) --- 2415fail: 2416 free_props(list); 2417 return (-1); 2418} 2419 2420static void 2421print_linkprop_head(void) 2422{ | 2346 boolean_t ls_parseable; 2347 boolean_t ls_persist; 2348 boolean_t ls_header; 2349} show_linkprop_state_t; 2350 2351static void 2352free_props(prop_list_t *list) 2353{ --- 64 unchanged lines hidden (view full) --- 2418fail: 2419 free_props(list); 2420 return (-1); 2421} 2422 2423static void 2424print_linkprop_head(void) 2425{ |
2423 (void) printf("%-15s %-14s %-14s %-30s \n", 2424 "PROPERTY", "VALUE", "DEFAULT", "POSSIBLE"); | 2426 (void) printf("%-12s %-15s %-14s %-14s %-20s \n", 2427 "LINK", "PROPERTY", "VALUE", "DEFAULT", "POSSIBLE"); |
2425} 2426 2427static void 2428print_linkprop(show_linkprop_state_t *statep, const char *propname, 2429 dladm_prop_type_t type, const char *typename, const char *format, 2430 char **pptr) 2431{ 2432 int i; --- 43 unchanged lines hidden (view full) --- 2476 2477static boolean_t 2478show_linkprop(void *arg, const char *propname) 2479{ 2480 show_linkprop_state_t *statep = arg; 2481 char *ptr = statep->ls_line; 2482 char *lim = ptr + MAX_PROP_LINE; 2483 | 2428} 2429 2430static void 2431print_linkprop(show_linkprop_state_t *statep, const char *propname, 2432 dladm_prop_type_t type, const char *typename, const char *format, 2433 char **pptr) 2434{ 2435 int i; --- 43 unchanged lines hidden (view full) --- 2479 2480static boolean_t 2481show_linkprop(void *arg, const char *propname) 2482{ 2483 show_linkprop_state_t *statep = arg; 2484 char *ptr = statep->ls_line; 2485 char *lim = ptr + MAX_PROP_LINE; 2486 |
2487 if (statep->ls_persist && dladm_is_prop_temponly(propname, NULL)) 2488 return (B_TRUE); 2489 |
|
2484 if (statep->ls_parseable) | 2490 if (statep->ls_parseable) |
2491 ptr += snprintf(ptr, lim - ptr, "LINK=\"%s\" ", 2492 statep->ls_link); 2493 else 2494 ptr += snprintf(ptr, lim - ptr, "%-12s ", statep->ls_link); 2495 2496 if (statep->ls_parseable) |
|
2485 ptr += snprintf(ptr, lim - ptr, "PROPERTY=\"%s\" ", propname); 2486 else 2487 ptr += snprintf(ptr, lim - ptr, "%-15s ", propname); 2488 2489 print_linkprop(statep, propname, 2490 statep->ls_persist ? DLADM_PROP_VAL_PERSISTENT : 2491 DLADM_PROP_VAL_CURRENT, "VALUE", "%-14s ", &ptr); 2492 print_linkprop(statep, propname, DLADM_PROP_VAL_DEFAULT, 2493 "DEFAULT", "%-14s ", &ptr); 2494 print_linkprop(statep, propname, DLADM_PROP_VAL_MODIFIABLE, | 2497 ptr += snprintf(ptr, lim - ptr, "PROPERTY=\"%s\" ", propname); 2498 else 2499 ptr += snprintf(ptr, lim - ptr, "%-15s ", propname); 2500 2501 print_linkprop(statep, propname, 2502 statep->ls_persist ? DLADM_PROP_VAL_PERSISTENT : 2503 DLADM_PROP_VAL_CURRENT, "VALUE", "%-14s ", &ptr); 2504 print_linkprop(statep, propname, DLADM_PROP_VAL_DEFAULT, 2505 "DEFAULT", "%-14s ", &ptr); 2506 print_linkprop(statep, propname, DLADM_PROP_VAL_MODIFIABLE, |
2495 "POSSIBLE", "%-30s ", &ptr); | 2507 "POSSIBLE", "%-20s ", &ptr); |
2496 2497 if (statep->ls_header) { 2498 statep->ls_header = B_FALSE; 2499 if (!statep->ls_parseable) 2500 print_linkprop_head(); 2501 } 2502 (void) printf("%s\n", statep->ls_line); 2503 return (B_TRUE); 2504} 2505 2506static void 2507do_show_linkprop(int argc, char **argv) 2508{ | 2508 2509 if (statep->ls_header) { 2510 statep->ls_header = B_FALSE; 2511 if (!statep->ls_parseable) 2512 print_linkprop_head(); 2513 } 2514 (void) printf("%s\n", statep->ls_line); 2515 return (B_TRUE); 2516} 2517 2518static void 2519do_show_linkprop(int argc, char **argv) 2520{ |
2509 int i, option, fd; 2510 char linkname[MAXPATHLEN]; | 2521 int option; |
2511 prop_list_t *proplist = NULL; | 2522 prop_list_t *proplist = NULL; |
2512 char *buf; 2513 dladm_status_t status; | |
2514 show_linkprop_state_t state; 2515 2516 opterr = 0; 2517 state.ls_link = NULL; 2518 state.ls_propvals = NULL; 2519 state.ls_line = NULL; 2520 state.ls_parseable = B_FALSE; 2521 state.ls_persist = B_FALSE; --- 17 unchanged lines hidden (view full) --- 2539 } 2540 } 2541 2542 if (optind == (argc - 1)) 2543 state.ls_link = argv[optind]; 2544 else if (optind != argc) 2545 usage(); 2546 | 2523 show_linkprop_state_t state; 2524 2525 opterr = 0; 2526 state.ls_link = NULL; 2527 state.ls_propvals = NULL; 2528 state.ls_line = NULL; 2529 state.ls_parseable = B_FALSE; 2530 state.ls_persist = B_FALSE; --- 17 unchanged lines hidden (view full) --- 2548 } 2549 } 2550 2551 if (optind == (argc - 1)) 2552 state.ls_link = argv[optind]; 2553 else if (optind != argc) 2554 usage(); 2555 |
2547 if (state.ls_link == NULL) 2548 die("link name must be specified"); | 2556 state.ls_proplist = proplist; |
2549 | 2557 |
2558 if (state.ls_link == NULL) { 2559 (void) dladm_walk(show_linkprop_onelink, &state); 2560 } else { 2561 show_linkprop_onelink(&state, state.ls_link); 2562 } 2563 free_props(proplist); 2564} 2565 2566static void 2567show_linkprop_onelink(void *arg, const char *link) 2568{ 2569 int i, fd; 2570 char linkname[MAXPATHLEN]; 2571 char *buf; 2572 dladm_status_t status; 2573 prop_list_t *proplist = NULL; 2574 show_linkprop_state_t *statep; 2575 const char *savep; 2576 2577 statep = (show_linkprop_state_t *)arg; 2578 savep = statep->ls_link; 2579 statep->ls_link = link; 2580 proplist = statep->ls_proplist; 2581 |
|
2550 /* 2551 * When some WiFi links are opened for the first time, their hardware 2552 * automatically scans for APs and does other slow operations. Thus, 2553 * if there are no open links, the retrieval of link properties 2554 * (below) will proceed slowly unless we hold the link open. 2555 */ | 2582 /* 2583 * When some WiFi links are opened for the first time, their hardware 2584 * automatically scans for APs and does other slow operations. Thus, 2585 * if there are no open links, the retrieval of link properties 2586 * (below) will proceed slowly unless we hold the link open. 2587 */ |
2556 (void) snprintf(linkname, MAXPATHLEN, "/dev/%s", state.ls_link); | 2588 (void) snprintf(linkname, MAXPATHLEN, "/dev/%s", link); |
2557 if ((fd = open(linkname, O_RDWR)) < 0) | 2589 if ((fd = open(linkname, O_RDWR)) < 0) |
2558 die("cannot open %s: %s", state.ls_link, strerror(errno)); | 2590 die("cannot open %s: %s", link, strerror(errno)); |
2559 2560 buf = malloc((sizeof (char *) + DLADM_PROP_VAL_MAX) * MAX_PROP_VALS + 2561 MAX_PROP_LINE); 2562 if (buf == NULL) 2563 die("insufficient memory"); 2564 | 2591 2592 buf = malloc((sizeof (char *) + DLADM_PROP_VAL_MAX) * MAX_PROP_VALS + 2593 MAX_PROP_LINE); 2594 if (buf == NULL) 2595 die("insufficient memory"); 2596 |
2565 state.ls_propvals = (char **)(void *)buf; | 2597 statep->ls_propvals = (char **)(void *)buf; |
2566 for (i = 0; i < MAX_PROP_VALS; i++) { | 2598 for (i = 0; i < MAX_PROP_VALS; i++) { |
2567 state.ls_propvals[i] = buf + sizeof (char *) * MAX_PROP_VALS + | 2599 statep->ls_propvals[i] = buf + sizeof (char *) * MAX_PROP_VALS + |
2568 i * DLADM_PROP_VAL_MAX; 2569 } | 2600 i * DLADM_PROP_VAL_MAX; 2601 } |
2570 state.ls_line = buf + | 2602 statep->ls_line = buf + |
2571 (sizeof (char *) + DLADM_PROP_VAL_MAX) * MAX_PROP_VALS; 2572 2573 if (proplist != NULL) { 2574 for (i = 0; i < proplist->pl_count; i++) { | 2603 (sizeof (char *) + DLADM_PROP_VAL_MAX) * MAX_PROP_VALS; 2604 2605 if (proplist != NULL) { 2606 for (i = 0; i < proplist->pl_count; i++) { |
2575 if (!show_linkprop(&state, | 2607 if (!show_linkprop(statep, |
2576 proplist->pl_info[i].pi_name)) 2577 break; 2578 } 2579 } else { | 2608 proplist->pl_info[i].pi_name)) 2609 break; 2610 } 2611 } else { |
2580 status = dladm_walk_prop(state.ls_link, &state, show_linkprop); | 2612 status = dladm_walk_prop(link, statep, show_linkprop); |
2581 if (status != DLADM_STATUS_OK) 2582 die_dlerr(status, "show-linkprop"); 2583 } 2584 (void) close(fd); 2585 free(buf); | 2613 if (status != DLADM_STATUS_OK) 2614 die_dlerr(status, "show-linkprop"); 2615 } 2616 (void) close(fd); 2617 free(buf); |
2586 free_props(proplist); | 2618 statep->ls_link = savep; |
2587} 2588 2589static dladm_status_t 2590set_linkprop_persist(const char *link, const char *prop_name, char **prop_val, 2591 uint_t val_cnt, boolean_t reset) 2592{ 2593 dladm_status_t status; | 2619} 2620 2621static dladm_status_t 2622set_linkprop_persist(const char *link, const char *prop_name, char **prop_val, 2623 uint_t val_cnt, boolean_t reset) 2624{ 2625 dladm_status_t status; |
2626 char *errprop; |
|
2594 2595 status = dladm_set_prop(link, prop_name, prop_val, val_cnt, | 2627 2628 status = dladm_set_prop(link, prop_name, prop_val, val_cnt, |
2596 DLADM_OPT_PERSIST); | 2629 DLADM_OPT_PERSIST, &errprop); |
2597 2598 if (status != DLADM_STATUS_OK) { 2599 if (reset) { 2600 warn_dlerr(status, "cannot persistently reset link " | 2630 2631 if (status != DLADM_STATUS_OK) { 2632 if (reset) { 2633 warn_dlerr(status, "cannot persistently reset link " |
2601 "property '%s' on '%s'", prop_name, link); | 2634 "property '%s' on '%s'", errprop, link); |
2602 } else { 2603 warn_dlerr(status, "cannot persistently set link " | 2635 } else { 2636 warn_dlerr(status, "cannot persistently set link " |
2604 "property '%s' on '%s'", prop_name, link); | 2637 "property '%s' on '%s'", errprop, link); |
2605 } 2606 } 2607 return (status); 2608} 2609 2610static void 2611set_linkprop(int argc, char **argv, boolean_t reset) 2612{ --- 32 unchanged lines hidden (view full) --- 2645 link = argv[optind]; 2646 else if (optind != argc) 2647 usage(); 2648 2649 if (link == NULL) 2650 die("link name must be specified"); 2651 2652 if (proplist == NULL) { | 2638 } 2639 } 2640 return (status); 2641} 2642 2643static void 2644set_linkprop(int argc, char **argv, boolean_t reset) 2645{ --- 32 unchanged lines hidden (view full) --- 2678 link = argv[optind]; 2679 else if (optind != argc) 2680 usage(); 2681 2682 if (link == NULL) 2683 die("link name must be specified"); 2684 2685 if (proplist == NULL) { |
2686 char *errprop; 2687 |
|
2653 if (!reset) 2654 die("link property must be specified"); 2655 | 2688 if (!reset) 2689 die("link property must be specified"); 2690 |
2656 status = dladm_set_prop(link, NULL, NULL, 0, DLADM_OPT_TEMP); | 2691 status = dladm_set_prop(link, NULL, NULL, 0, DLADM_OPT_TEMP, 2692 &errprop); |
2657 if (status != DLADM_STATUS_OK) { | 2693 if (status != DLADM_STATUS_OK) { |
2658 warn_dlerr(status, "cannot reset link properties " 2659 "on '%s'", link); | 2694 warn_dlerr(status, "cannot reset link property '%s' " 2695 "on '%s'", errprop, link); |
2660 } 2661 if (!temp) { 2662 dladm_status_t s; 2663 2664 s = set_linkprop_persist(link, NULL, NULL, 0, reset); 2665 if (s != DLADM_STATUS_OK) 2666 status = s; 2667 } --- 15 unchanged lines hidden (view full) --- 2683 if (count == 0) { 2684 warn("no value specified for '%s'", 2685 pip->pi_name); 2686 status = DLADM_STATUS_BADARG; 2687 continue; 2688 } 2689 } 2690 s = dladm_set_prop(link, pip->pi_name, val, count, | 2696 } 2697 if (!temp) { 2698 dladm_status_t s; 2699 2700 s = set_linkprop_persist(link, NULL, NULL, 0, reset); 2701 if (s != DLADM_STATUS_OK) 2702 status = s; 2703 } --- 15 unchanged lines hidden (view full) --- 2719 if (count == 0) { 2720 warn("no value specified for '%s'", 2721 pip->pi_name); 2722 status = DLADM_STATUS_BADARG; 2723 continue; 2724 } 2725 } 2726 s = dladm_set_prop(link, pip->pi_name, val, count, |
2691 DLADM_OPT_TEMP); | 2727 DLADM_OPT_TEMP, NULL); |
2692 if (s == DLADM_STATUS_OK) { 2693 if (!temp) { 2694 s = set_linkprop_persist(link, 2695 pip->pi_name, val, count, reset); 2696 if (s != DLADM_STATUS_OK) 2697 status = s; 2698 } 2699 continue; --- 29 unchanged lines hidden (view full) --- 2729 lim = ptr + DLADM_STRSIZE; 2730 *ptr = '\0'; 2731 for (j = 0; j < valcnt && s == DLADM_STATUS_OK; j++) { 2732 ptr += snprintf(ptr, lim - ptr, "%s,", 2733 propvals[j]); 2734 if (ptr >= lim) 2735 break; 2736 } | 2728 if (s == DLADM_STATUS_OK) { 2729 if (!temp) { 2730 s = set_linkprop_persist(link, 2731 pip->pi_name, val, count, reset); 2732 if (s != DLADM_STATUS_OK) 2733 status = s; 2734 } 2735 continue; --- 29 unchanged lines hidden (view full) --- 2765 lim = ptr + DLADM_STRSIZE; 2766 *ptr = '\0'; 2767 for (j = 0; j < valcnt && s == DLADM_STATUS_OK; j++) { 2768 ptr += snprintf(ptr, lim - ptr, "%s,", 2769 propvals[j]); 2770 if (ptr >= lim) 2771 break; 2772 } |
2737 if (ptr > errmsg) | 2773 if (ptr > errmsg) { |
2738 *(ptr - 1) = '\0'; | 2774 *(ptr - 1) = '\0'; |
2739 warn("link property '%s' must be one of: %s", 2740 pip->pi_name, errmsg); | 2775 warn("link property '%s' must be one of: %s", 2776 pip->pi_name, errmsg); 2777 } else 2778 warn("invalid link property '%s'", *val); |
2741 free(propvals); 2742 break; 2743 } 2744 default: 2745 if (reset) { 2746 warn_dlerr(status, "cannot reset link property " 2747 "'%s' on '%s'", pip->pi_name, link); 2748 } else { --- 690 unchanged lines hidden --- | 2779 free(propvals); 2780 break; 2781 } 2782 default: 2783 if (reset) { 2784 warn_dlerr(status, "cannot reset link property " 2785 "'%s' on '%s'", pip->pi_name, link); 2786 } else { --- 690 unchanged lines hidden --- |