Print this page
feth prototype

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/dladm/dladm.c
          +++ new/usr/src/cmd/dladm/dladm.c
↓ open down ↓ 55 lines elided ↑ open up ↑
  56   56  #include <libdllink.h>
  57   57  #include <libdlstat.h>
  58   58  #include <libdlaggr.h>
  59   59  #include <libdlwlan.h>
  60   60  #include <libdlvlan.h>
  61   61  #include <libdlvnic.h>
  62   62  #include <libdlib.h>
  63   63  #include <libdlether.h>
  64   64  #include <libdliptun.h>
  65   65  #include <libdlsim.h>
       66 +#include <libdlfeth.h>
  66   67  #include <libdlbridge.h>
  67   68  #include <libdloverlay.h>
  68   69  #include <libinetutil.h>
  69   70  #include <libvrrpadm.h>
  70   71  #include <bsm/adt.h>
  71   72  #include <bsm/adt_event.h>
  72   73  #include <libdlvnic.h>
  73   74  #include <sys/types.h>
  74   75  #include <sys/socket.h>
  75   76  #include <sys/ib/ib_types.h>
↓ open down ↓ 143 lines elided ↑ open up ↑
 219  220  static cmdfunc_t do_rename_link, do_delete_phys, do_init_phys;
 220  221  static cmdfunc_t do_show_linkmap;
 221  222  static cmdfunc_t do_show_ether;
 222  223  static cmdfunc_t do_create_vnic, do_delete_vnic, do_show_vnic;
 223  224  static cmdfunc_t do_up_vnic;
 224  225  static cmdfunc_t do_create_part, do_delete_part, do_show_part, do_show_ib;
 225  226  static cmdfunc_t do_up_part;
 226  227  static cmdfunc_t do_create_etherstub, do_delete_etherstub, do_show_etherstub;
 227  228  static cmdfunc_t do_create_simnet, do_modify_simnet;
 228  229  static cmdfunc_t do_delete_simnet, do_show_simnet, do_up_simnet;
      230 +static cmdfunc_t do_create_feth, do_delete_feth, do_show_feth, do_up_feth;
 229  231  static cmdfunc_t do_show_usage;
 230  232  static cmdfunc_t do_create_bridge, do_modify_bridge, do_delete_bridge;
 231  233  static cmdfunc_t do_add_bridge, do_remove_bridge, do_show_bridge;
 232  234  static cmdfunc_t do_create_iptun, do_modify_iptun, do_delete_iptun;
 233  235  static cmdfunc_t do_show_iptun, do_up_iptun, do_down_iptun;
 234  236  static cmdfunc_t do_create_overlay, do_delete_overlay, do_modify_overlay;
 235  237  static cmdfunc_t do_show_overlay, do_up_overlay;
 236  238  
 237  239  static void     do_up_vnic_common(int, char **, const char *, boolean_t);
 238  240  
↓ open down ↓ 145 lines elided ↑ open up ↑
 384  386              "    create-etherstub [-t] <link>"                          },
 385  387          { "delete-etherstub",   do_delete_etherstub,
 386  388              "    delete-etherstub [-t] <link>"                          },
 387  389          { "show-etherstub",     do_show_etherstub,
 388  390              "    show-etherstub   [-t] [<link>]\n"                      },
 389  391          { "create-simnet",      do_create_simnet,       NULL            },
 390  392          { "modify-simnet",      do_modify_simnet,       NULL            },
 391  393          { "delete-simnet",      do_delete_simnet,       NULL            },
 392  394          { "show-simnet",        do_show_simnet,         NULL            },
 393  395          { "up-simnet",          do_up_simnet,           NULL            },
      396 +        { "create-feth",        do_create_feth,
      397 +            "    create-feth      [-t] [-s] [-R <root-dir>] [-m <mac address>] "
      398 +                    "<feth-link>" },
      399 +        { "delete-feth",        do_delete_feth,         
      400 +            "    delete-feth      [-R <root-dir>] <feth-link>" },
      401 +        { "show-feth",          do_show_feth,
      402 +            "    show-feth        [-p] [-o <field>,...] [-P] [<feth-link>]" },
      403 +        { "up-feth",            do_up_feth,
      404 +            "    up-feth          <feth-link>\n" },
 394  405          { "create-bridge",      do_create_bridge,
 395  406              "    create-bridge    [-R <root-dir>] [-P <protect>] "
 396  407              "[-p <priority>]\n"
 397  408              "\t\t     [-m <max-age>] [-h <hello-time>] [-d <forward-delay>]\n"
 398  409              "\t\t     [-f <force-protocol>] [-l <link>]... <bridge>"    },
 399  410          { "modify-bridge",      do_modify_bridge,
 400  411              "    modify-bridge    [-R <root-dir>] [-P <protect>] "
 401  412              "[-p <priority>]\n"
 402  413              "\t\t     [-m <max-age>] [-h <hello-time>] [-d <forward-delay>]\n"
 403  414              "\t\t     [-f <force-protocol>] <bridge>"                   },
↓ open down ↓ 178 lines elided ↑ open up ↑
 582  593  };
 583  594  
 584  595  static const struct option simnet_lopts[] = {
 585  596          {"temporary",   no_argument,            0, 't'  },
 586  597          {"root-dir",    required_argument,      0, 'R'  },
 587  598          {"media",       required_argument,      0, 'm'  },
 588  599          {"peer",        required_argument,      0, 'p'  },
 589  600          { NULL, 0, NULL, 0 }
 590  601  };
 591  602  
      603 +static const struct option feth_lopts[] = {
      604 +        {"temporary",   no_argument,0, 't'  },
      605 +        {"root-dir",    required_argument,      0, 'R'  },
      606 +        { NULL, 0, NULL, 0 }
      607 +};
      608 +
 592  609  static const struct option bridge_lopts[] = {
 593  610          { "protect",            required_argument,      0, 'P' },
 594  611          { "root-dir",           required_argument,      0, 'R'  },
 595  612          { "forward-delay",      required_argument,      0, 'd'  },
 596  613          { "force-protocol",     required_argument,      0, 'f'  },
 597  614          { "hello-time",         required_argument,      0, 'h'  },
 598  615          { "link",               required_argument,      0, 'l'  },
 599  616          { "max-age",            required_argument,      0, 'm'  },
 600  617          { "priority",           required_argument,      0, 'p'  },
 601  618          { NULL, 0, NULL, 0 }
↓ open down ↓ 529 lines elided ↑ open up ↑
1131 1148  { "MEDIA",              20,
1132 1149          offsetof(simnet_fields_buf_t, simnet_media), print_default_cb},
1133 1150  { "MACADDRESS",         18,
1134 1151          offsetof(simnet_fields_buf_t, simnet_macaddr), print_default_cb},
1135 1152  { "OTHERLINK",          12,
1136 1153          offsetof(simnet_fields_buf_t, simnet_otherlink), print_default_cb},
1137 1154  { NULL,                 0, 0, NULL}}
1138 1155  ;
1139 1156  
1140 1157  /*
     1158 + * structures for 'dladm show-feth'
     1159 + */
     1160 +
     1161 +typedef struct feth_fields_buf_s
     1162 +{
     1163 +        char feth_name[DLPI_LINKNAME_MAX];
     1164 +        char feth_macaddr[18];
     1165 +} feth_fields_buf_t;
     1166 +
     1167 +static const ofmt_field_t feth_fields[] = {
     1168 +        { "LINK",12,
     1169 +                offsetof(feth_fields_buf_t, feth_name), print_default_cb},
     1170 +        { "MACADDRESS",18,
     1171 +                offsetof(feth_fields_buf_t, feth_macaddr), print_default_cb},
     1172 +        { NULL,0, 0, NULL}}
     1173 +;
     1174 +
     1175 +/*
1141 1176   * structures for 'dladm show-usage'
1142 1177   */
1143 1178  
1144 1179  typedef struct  usage_fields_buf_s {
1145 1180          char    usage_link[12];
1146 1181          char    usage_duration[10];
1147 1182          char    usage_ipackets[9];
1148 1183          char    usage_rbytes[10];
1149 1184          char    usage_opackets[9];
1150 1185          char    usage_obytes[10];
↓ open down ↓ 1738 lines elided ↑ open up ↑
2889 2924                          break;
2890 2925                  }
2891 2926                  if (slinfo.sna_peer_link_id != DATALINK_INVALID_LINKID) {
2892 2927                          if (dladm_datalink_id2info(handle,
2893 2928                              slinfo.sna_peer_link_id, NULL, NULL, NULL,
2894 2929                              lbuf->link_over, sizeof (lbuf->link_over)) !=
2895 2930                              DLADM_STATUS_OK)
2896 2931                                  (void) strcpy(lbuf->link_over, "?");
2897 2932                  }
2898 2933                  break;
     2934 +            }
     2935 +        
     2936 +        case DATALINK_CLASS_FETH: {
     2937 +                (void) strcpy(lbuf->link_over, "--");
     2938 +                break;
2899 2939          }
2900 2940          }
2901 2941  }
2902 2942  
2903 2943  static dladm_status_t
2904 2944  print_link(show_state_t *state, datalink_id_t linkid, link_fields_buf_t *lbuf)
2905 2945  {
2906 2946          char                    link[MAXLINKNAMELEN];
2907 2947          datalink_class_t        class;
2908 2948          uint_t                  mtu;
↓ open down ↓ 2837 lines elided ↑ open up ↑
5746 5786                  (void) show_simnet(handle, linkid, &state);
5747 5787                  if (state.ls_status != DLADM_STATUS_OK) {
5748 5788                          ofmt_close(ofmt);
5749 5789                          die_dlerr(state.ls_status, "failed to show simnet %s",
5750 5790                              argv[optind]);
5751 5791                  }
5752 5792          }
5753 5793          ofmt_close(ofmt);
5754 5794  }
5755 5795  
     5796 +/* ARGSUSED */
5756 5797  static void
     5798 +do_up_feth(int argc, char *argv[], const char *use)
     5799 +{
     5800 +        (void) dladm_feth_up(handle, DATALINK_ALL_LINKID, 0);
     5801 +}
     5802 +
     5803 +static void
     5804 +do_create_feth(int argc, char *argv[], const char *use)
     5805 +{
     5806 +        uint32_t flags;
     5807 +        char *altroot = NULL;
     5808 +        int option;
     5809 +        dladm_status_t status;
     5810 +        char name[MAXLINKNAMELEN];
     5811 +        boolean_t       mac_provided = B_FALSE;
     5812 +        boolean_t       mac_fixed;
     5813 +        uint8_t                 mac_addr[ETHERADDRL];
     5814 +        
     5815 +        name[0] = '\0';
     5816 +        flags = DLADM_OPT_ACTIVE | DLADM_OPT_PERSIST;
     5817 +
     5818 +        opterr = 0;
     5819 +        while ((option = getopt_long(argc, argv, ":tsR:m:",
     5820 +                                        feth_lopts, NULL)) != -1) {
     5821 +                switch (option) {
     5822 +                        case 't':
     5823 +                                flags &= ~DLADM_OPT_PERSIST;
     5824 +                                break;
     5825 +                        case 's':
     5826 +                                flags |= FETH_FLAG_SINGLESHOT;
     5827 +                                break;
     5828 +                        case 'R':
     5829 +                                altroot = optarg;
     5830 +                                break;
     5831 +                case 'm':
     5832 +                        if (mac_provided == B_TRUE)
     5833 +                                die("cannot specify -m option twice");
     5834 +
     5835 +                        if (!dladm_aggr_str2macaddr(optarg, &mac_fixed, mac_addr)) {
     5836 +                                die("invalid MAC address");
     5837 +                        }
     5838 +                        mac_provided = B_TRUE;
     5839 +                        printf("have mac address\n");
     5840 +                        break;
     5841 +                        default:
     5842 +                                die_opterr(optopt, option, use);
     5843 +                }
     5844 +        }
     5845 +
     5846 +        /* the simnet id is the required operand */
     5847 +        if (optind != (argc - 1))
     5848 +                usage();
     5849 +
     5850 +        if (strlcpy(name, argv[optind], MAXLINKNAMELEN) >= MAXLINKNAMELEN)
     5851 +                die("link name too long '%s'", argv[optind]);
     5852 +
     5853 +        if (!dladm_valid_linkname(name))
     5854 +                die("invalid link name '%s'", name);
     5855 +
     5856 +        if (altroot != NULL)
     5857 +                altroot_cmd(altroot, argc, argv);
     5858 +
     5859 +        if(mac_provided)
     5860 +                status = dladm_feth_create_mac(handle, name, flags, mac_addr);
     5861 +        else
     5862 +                status = dladm_feth_create(handle, name, flags);
     5863 +        if (status != DLADM_STATUS_OK)
     5864 +                die_dlerr(status, "feth creation failed");
     5865 +}
     5866 +
     5867 +static void
     5868 +do_delete_feth(int argc, char *argv[], const char *use)
     5869 +{
     5870 +        int option;
     5871 +        uint32_t flags = DLADM_OPT_ACTIVE | DLADM_OPT_PERSIST;
     5872 +        datalink_id_t linkid;
     5873 +        char *altroot = NULL;
     5874 +        dladm_status_t status;
     5875 +        dladm_feth_attr_t flinfo;
     5876 +
     5877 +        opterr = 0;
     5878 +        while ((option = getopt_long(argc, argv, ":R:", feth_lopts,
     5879 +                                        NULL)) != -1) {
     5880 +                switch (option) {
     5881 +                        case 'R':
     5882 +                                altroot = optarg;
     5883 +                                break;
     5884 +                        default:
     5885 +                                die_opterr(optopt, option, use);
     5886 +                }
     5887 +        }
     5888 +
     5889 +        /* get feth name (required last argument) */
     5890 +        if (optind != (argc - 1))
     5891 +                usage();
     5892 +
     5893 +        if (!dladm_valid_linkname(argv[optind]))
     5894 +                die("invalid link name '%s'", argv[optind]);
     5895 +
     5896 +        if (altroot != NULL)
     5897 +                altroot_cmd(altroot, argc, argv);
     5898 +
     5899 +        status = dladm_name2info(handle, argv[optind], &linkid, NULL, NULL,
     5900 +                        NULL);
     5901 +        if (status != DLADM_STATUS_OK)
     5902 +                die("feth '%s' not found", argv[optind]);
     5903 +
     5904 +        if ((status = dladm_feth_info(handle, linkid, &flinfo,
     5905 +                                        flags)) != DLADM_STATUS_OK)
     5906 +                die_dlerr(status, "failed to retrieve feth information");
     5907 +        
     5908 +        status = dladm_feth_delete(handle, linkid, flags);
     5909 +        if (status != DLADM_STATUS_OK)
     5910 +                die_dlerr(status, "feth deletion failed");
     5911 +}
     5912 +
     5913 +static dladm_status_t
     5914 +print_feth(show_state_t *state, datalink_id_t linkid)
     5915 +{
     5916 +        dladm_feth_attr_t     flinfo;
     5917 +        uint32_t flags;
     5918 +        dladm_status_t status;
     5919 +        feth_fields_buf_t     flbuf;
     5920 +        char mstr[ETHERADDRL * 3];
     5921 +
     5922 +        bzero(&flbuf, sizeof (flbuf));
     5923 +        if ((status = dladm_datalink_id2info(handle, linkid, &flags, NULL, NULL,
     5924 +                                        flbuf.feth_name, sizeof (flbuf.feth_name)))
     5925 +                        != DLADM_STATUS_OK)
     5926 +                return (status);
     5927 +
     5928 +        if (!(state->ls_flags & flags))
     5929 +                return (DLADM_STATUS_NOTFOUND);
     5930 +
     5931 +        if ((status = dladm_feth_info(handle, linkid, &flinfo,
     5932 +                                        state->ls_flags)) != DLADM_STATUS_OK)
     5933 +                return (status);
     5934 +
     5935 +        if (flinfo.sna_mac_len > sizeof (flbuf.feth_macaddr))
     5936 +                return (DLADM_STATUS_BADVAL);
     5937 +
     5938 +        (void) strlcpy(flbuf.feth_macaddr,
     5939 +                        dladm_aggr_macaddr2str(flinfo.sna_mac_addr, mstr),
     5940 +                        sizeof (flbuf.feth_macaddr));
     5941 +
     5942 +        ofmt_print(state->ls_ofmt, &flbuf);
     5943 +        return (status);
     5944 +}
     5945 +
     5946 +/* ARGSUSED */
     5947 +static int
     5948 +show_feth(dladm_handle_t dh, datalink_id_t linkid, void *arg)
     5949 +{
     5950 +        show_state_t* state = arg;
     5951 +
     5952 +        state->ls_status = print_feth(state, linkid);
     5953 +        return (DLADM_WALK_CONTINUE);
     5954 +}
     5955 +
     5956 +static void
     5957 +do_show_feth(int argc, char *argv[], const char *use)
     5958 +{
     5959 +        int option;
     5960 +        uint32_t        flags = DLADM_OPT_ACTIVE;
     5961 +        boolean_t       p_arg = B_FALSE;
     5962 +        datalink_id_t   linkid = DATALINK_ALL_LINKID;
     5963 +        show_state_t    state;
     5964 +        dladm_status_t  status;
     5965 +        boolean_t       o_arg = B_FALSE;
     5966 +        ofmt_handle_t   ofmt;
     5967 +        ofmt_status_t   oferr;
     5968 +        char *all_fields = "link,macaddress";
     5969 +        char *fields_str = all_fields;
     5970 +        uint_t          ofmtflags = 0;
     5971 +
     5972 +        bzero(&state, sizeof (state));
     5973 +
     5974 +        opterr = 0;
     5975 +        while ((option = getopt_long(argc, argv, ":pPo:",
     5976 +                                        show_lopts, NULL)) != -1) {
     5977 +                switch (option) {
     5978 +                        case 'p':
     5979 +                                if (p_arg)
     5980 +                                        die_optdup(option);
     5981 +
     5982 +                                p_arg = B_TRUE;
     5983 +                                state.ls_parsable = p_arg;
     5984 +                                break;
     5985 +                        case 'P':
     5986 +                                if (flags != DLADM_OPT_ACTIVE)
     5987 +                                        die_optdup(option);
     5988 +
     5989 +                                flags = DLADM_OPT_PERSIST;
     5990 +                                break;
     5991 +                        case 'o':
     5992 +                                o_arg = B_TRUE;
     5993 +                                fields_str = optarg;
     5994 +                                break;
     5995 +                        default:
     5996 +                                die_opterr(optopt, option, use);
     5997 +                                break;
     5998 +                }
     5999 +        }
     6000 +
     6001 +        if (p_arg && !o_arg)
     6002 +                die("-p requires -o");
     6003 +
     6004 +        if (strcasecmp(fields_str, "all") == 0) {
     6005 +                if (p_arg)
     6006 +                        die("\"-o all\" is invalid with -p");
     6007 +                fields_str = all_fields;
     6008 +        }
     6009 +
     6010 +        /* get link name (optional last argument) */
     6011 +        if (optind == (argc-1)) {
     6012 +                if ((status = dladm_name2info(handle, argv[optind], &linkid,
     6013 +                  NULL, NULL, NULL)) != DLADM_STATUS_OK) {
     6014 +                        die_dlerr(status, "link %s is not valid", argv[optind]);
     6015 +                }
     6016 +        } else if (optind != argc) {
     6017 +                usage();
     6018 +        }
     6019 +
     6020 +        state.ls_flags = flags;
     6021 +        state.ls_donefirst = B_FALSE;
     6022 +        if (state.ls_parsable)
     6023 +                ofmtflags |= OFMT_PARSABLE;
     6024 +        oferr = ofmt_open(fields_str, feth_fields, ofmtflags, 0, &ofmt);
     6025 +        ofmt_check(oferr, state.ls_parsable, ofmt, die, warn);
     6026 +        state.ls_ofmt = ofmt;
     6027 +
     6028 +        if (linkid == DATALINK_ALL_LINKID) {
     6029 +                (void) dladm_walk_datalink_id(show_feth, handle, &state,
     6030 +                                DATALINK_CLASS_FETH, DATALINK_ANY_MEDIATYPE, flags);
     6031 +        } else {
     6032 +                (void) show_feth(handle, linkid, &state);
     6033 +                if (state.ls_status != DLADM_STATUS_OK) {
     6034 +                        ofmt_close(ofmt);
     6035 +                        die_dlerr(state.ls_status, "failed to show feth %s",
     6036 +                                        argv[optind]);
     6037 +                }
     6038 +        }
     6039 +        ofmt_close(ofmt);
     6040 +}
     6041 +
     6042 +static void
5757 6043  link_stats(datalink_id_t linkid, uint_t interval, char *fields_str,
5758 6044      show_state_t *state)
5759 6045  {
5760 6046          ofmt_handle_t   ofmt;
5761 6047          ofmt_status_t   oferr;
5762 6048          uint_t          ofmtflags = 0;
5763 6049  
5764 6050          if (state->ls_parsable)
5765 6051                  ofmtflags |= OFMT_PARSABLE;
5766 6052          oferr = ofmt_open(fields_str, link_s_fields, ofmtflags, 0, &ofmt);
↓ open down ↓ 2258 lines elided ↑ open up ↑
8025 8311  
8026 8312          for (n = 0; n < nlink; n++) {
8027 8313                  datalink_class_t class;
8028 8314                  uint32_t media;
8029 8315                  char pointless[DLADM_STRSIZE];
8030 8316  
8031 8317                  if (dladm_name2info(handle, links[n], &linkids[n], NULL, &class,
8032 8318                      &media) != DLADM_STATUS_OK)
8033 8319                          die("invalid link name '%s'", links[n]);
8034 8320                  if (class & ~(DATALINK_CLASS_PHYS | DATALINK_CLASS_AGGR |
8035      -                    DATALINK_CLASS_ETHERSTUB | DATALINK_CLASS_SIMNET))
     8321 +                    DATALINK_CLASS_ETHERSTUB | DATALINK_CLASS_SIMNET | 
     8322 +                    DATALINK_CLASS_FETH))
8036 8323                          die("%s %s cannot be bridged",
8037 8324                              dladm_class2str(class, pointless), links[n]);
8038 8325                  if (media != DL_ETHER && media != DL_100VG &&
8039 8326                      media != DL_ETH_CSMA && media != DL_100BT)
8040 8327                          die("%s interface %s cannot be bridged",
8041 8328                              dladm_media2str(media, pointless), links[n]);
8042 8329          }
8043 8330  
8044 8331          if (func == brCreate)
8045 8332                  flags |= DLADM_OPT_CREATE;
↓ open down ↓ 2546 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX