1da14cebeSEric Cheng /* 2da14cebeSEric Cheng * CDDL HEADER START 3da14cebeSEric Cheng * 4da14cebeSEric Cheng * The contents of this file are subject to the terms of the 5da14cebeSEric Cheng * Common Development and Distribution License (the "License"). 6da14cebeSEric Cheng * You may not use this file except in compliance with the License. 7da14cebeSEric Cheng * 8da14cebeSEric Cheng * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9da14cebeSEric Cheng * or http://www.opensolaris.org/os/licensing. 10da14cebeSEric Cheng * See the License for the specific language governing permissions 11da14cebeSEric Cheng * and limitations under the License. 12da14cebeSEric Cheng * 13da14cebeSEric Cheng * When distributing Covered Code, include this CDDL HEADER in each 14da14cebeSEric Cheng * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15da14cebeSEric Cheng * If applicable, add the following below this CDDL HEADER, with the 16da14cebeSEric Cheng * fields enclosed by brackets "[]" replaced with your own identifying 17da14cebeSEric Cheng * information: Portions Copyright [yyyy] [name of copyright owner] 18da14cebeSEric Cheng * 19da14cebeSEric Cheng * CDDL HEADER END 20da14cebeSEric Cheng */ 21da14cebeSEric Cheng /* 22da000602SGirish Moodalbail * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23da14cebeSEric Cheng * Use is subject to license terms. 24da14cebeSEric Cheng */ 25da14cebeSEric Cheng 26da14cebeSEric Cheng #include <errno.h> 27da14cebeSEric Cheng #include <stdlib.h> 28da14cebeSEric Cheng #include <strings.h> 29da14cebeSEric Cheng #include <sys/mac_flow.h> 30da14cebeSEric Cheng #include <sys/types.h> 31da14cebeSEric Cheng #include <sys/socket.h> 32da14cebeSEric Cheng #include <netinet/in.h> 33da14cebeSEric Cheng #include <arpa/inet.h> 34da14cebeSEric Cheng #include <netdb.h> 35da14cebeSEric Cheng #include <net/if_types.h> 36da14cebeSEric Cheng #include <net/if_dl.h> 37da14cebeSEric Cheng #include <inet/ip.h> 38da14cebeSEric Cheng #include <inet/ip6.h> 39da14cebeSEric Cheng 40da14cebeSEric Cheng #include <libdladm.h> 41da14cebeSEric Cheng #include <libdlflow.h> 42da14cebeSEric Cheng #include <libdlflow_impl.h> 43da14cebeSEric Cheng 44da14cebeSEric Cheng #define V4_PART_OF_V6(v6) ((v6)._S6_un._S6_u32[3]) 45da14cebeSEric Cheng 46da14cebeSEric Cheng /* max port number for UDP, TCP & SCTP */ 47da14cebeSEric Cheng #define MAX_PORT 65535 48da14cebeSEric Cheng 49da14cebeSEric Cheng static fad_checkf_t do_check_local_ip; 50da14cebeSEric Cheng static fad_checkf_t do_check_remote_ip; 51da14cebeSEric Cheng static fad_checkf_t do_check_protocol; 52da14cebeSEric Cheng static fad_checkf_t do_check_local_port; 53da14cebeSEric Cheng 54da14cebeSEric Cheng static dladm_status_t do_check_port(char *, boolean_t, flow_desc_t *); 55da14cebeSEric Cheng 56da14cebeSEric Cheng static fattr_desc_t attr_table[] = { 57da14cebeSEric Cheng { "local_ip", do_check_local_ip }, 58da14cebeSEric Cheng { "remote_ip", do_check_remote_ip }, 59da14cebeSEric Cheng { "transport", do_check_protocol }, 60da14cebeSEric Cheng { "local_port", do_check_local_port }, 61da14cebeSEric Cheng { "dsfield", do_check_dsfield }, 62da14cebeSEric Cheng }; 63da14cebeSEric Cheng 64da14cebeSEric Cheng #define DLADM_MAX_FLOWATTRS (sizeof (attr_table) / sizeof (fattr_desc_t)) 65da14cebeSEric Cheng 66da14cebeSEric Cheng static dladm_status_t 67da14cebeSEric Cheng do_check_local_ip(char *attr_val, flow_desc_t *fdesc) 68da14cebeSEric Cheng { 69da14cebeSEric Cheng return (do_check_ip_addr(attr_val, B_TRUE, fdesc)); 70da14cebeSEric Cheng } 71da14cebeSEric Cheng 72da14cebeSEric Cheng static dladm_status_t 73da14cebeSEric Cheng do_check_remote_ip(char *attr_val, flow_desc_t *fdesc) 74da14cebeSEric Cheng { 75da14cebeSEric Cheng return (do_check_ip_addr(attr_val, B_FALSE, fdesc)); 76da14cebeSEric Cheng } 77da14cebeSEric Cheng 78da14cebeSEric Cheng dladm_status_t 79da14cebeSEric Cheng do_check_ip_addr(char *addr_str, boolean_t local, flow_desc_t *fd) 80da14cebeSEric Cheng { 81da14cebeSEric Cheng dladm_status_t status; 82da000602SGirish Moodalbail int prefix_max, prefix_len = 0; 83da14cebeSEric Cheng char *prefix_str, *endp = NULL; 84da14cebeSEric Cheng flow_mask_t mask; 85da14cebeSEric Cheng in6_addr_t *addr; 86da14cebeSEric Cheng uchar_t *netmask; 87da000602SGirish Moodalbail struct in_addr v4addr; 88da000602SGirish Moodalbail struct in6_addr v6addr; 89da000602SGirish Moodalbail int family; 90da14cebeSEric Cheng 91da14cebeSEric Cheng if ((prefix_str = strchr(addr_str, '/')) != NULL) { 92da14cebeSEric Cheng *prefix_str++ = '\0'; 93da14cebeSEric Cheng errno = 0; 94da14cebeSEric Cheng prefix_len = (int)strtol(prefix_str, &endp, 10); 95da14cebeSEric Cheng if (errno != 0 || prefix_len == 0 || *endp != '\0') 96da14cebeSEric Cheng return (DLADM_STATUS_INVALID_PREFIXLEN); 97da14cebeSEric Cheng } 98da000602SGirish Moodalbail if (inet_pton(AF_INET, addr_str, &v4addr.s_addr) == 1) { 99da000602SGirish Moodalbail family = AF_INET; 100da000602SGirish Moodalbail } else if (inet_pton(AF_INET6, addr_str, v6addr.s6_addr) == 1) { 101da000602SGirish Moodalbail family = AF_INET6; 102da000602SGirish Moodalbail } else { 103da14cebeSEric Cheng return (DLADM_STATUS_INVALID_IP); 104da000602SGirish Moodalbail } 105da14cebeSEric Cheng 106da14cebeSEric Cheng mask = FLOW_IP_VERSION; 107da14cebeSEric Cheng if (local) { 108da14cebeSEric Cheng mask |= FLOW_IP_LOCAL; 109da14cebeSEric Cheng addr = &fd->fd_local_addr; 110da14cebeSEric Cheng netmask = (uchar_t *)&fd->fd_local_netmask; 111da14cebeSEric Cheng } else { 112da14cebeSEric Cheng mask |= FLOW_IP_REMOTE; 113da14cebeSEric Cheng addr = &fd->fd_remote_addr; 114da14cebeSEric Cheng netmask = (uchar_t *)&fd->fd_remote_netmask; 115da14cebeSEric Cheng } 116da14cebeSEric Cheng 117da000602SGirish Moodalbail if (family == AF_INET) { 118da000602SGirish Moodalbail IN6_INADDR_TO_V4MAPPED(&v4addr, addr); 119da14cebeSEric Cheng prefix_max = IP_ABITS; 120da14cebeSEric Cheng fd->fd_ipversion = IPV4_VERSION; 121da14cebeSEric Cheng netmask = (uchar_t *) 122da14cebeSEric Cheng &(V4_PART_OF_V6((*((in6_addr_t *)(void *)netmask)))); 123da000602SGirish Moodalbail } else { 124da000602SGirish Moodalbail *addr = v6addr; 125da14cebeSEric Cheng prefix_max = IPV6_ABITS; 126da14cebeSEric Cheng fd->fd_ipversion = IPV6_VERSION; 127da14cebeSEric Cheng } 128da14cebeSEric Cheng 129da14cebeSEric Cheng if (prefix_len == 0) 130da14cebeSEric Cheng prefix_len = prefix_max; 131da14cebeSEric Cheng 132da14cebeSEric Cheng status = dladm_prefixlen2mask(prefix_len, prefix_max, netmask); 133da14cebeSEric Cheng 134da14cebeSEric Cheng if (status != DLADM_STATUS_OK) { 135da14cebeSEric Cheng return (DLADM_STATUS_INVALID_PREFIXLEN); 136da14cebeSEric Cheng } 137da14cebeSEric Cheng 138da14cebeSEric Cheng fd->fd_mask |= mask; 139da14cebeSEric Cheng return (DLADM_STATUS_OK); 140da14cebeSEric Cheng } 141da14cebeSEric Cheng 142da14cebeSEric Cheng dladm_status_t 143da14cebeSEric Cheng do_check_protocol(char *attr_val, flow_desc_t *fdesc) 144da14cebeSEric Cheng { 145da14cebeSEric Cheng uint8_t protocol; 146da14cebeSEric Cheng 147da14cebeSEric Cheng protocol = dladm_str2proto(attr_val); 148da14cebeSEric Cheng 149da14cebeSEric Cheng if (protocol != 0) { 150da14cebeSEric Cheng fdesc->fd_mask |= FLOW_IP_PROTOCOL; 151da14cebeSEric Cheng fdesc->fd_protocol = protocol; 152da14cebeSEric Cheng return (DLADM_STATUS_OK); 153da14cebeSEric Cheng } else { 154da14cebeSEric Cheng return (DLADM_STATUS_INVALID_PROTOCOL); 155da14cebeSEric Cheng } 156da14cebeSEric Cheng } 157da14cebeSEric Cheng 158da14cebeSEric Cheng dladm_status_t 159da14cebeSEric Cheng do_check_local_port(char *attr_val, flow_desc_t *fdesc) 160da14cebeSEric Cheng { 161da14cebeSEric Cheng return (do_check_port(attr_val, B_TRUE, fdesc)); 162da14cebeSEric Cheng } 163da14cebeSEric Cheng 164da14cebeSEric Cheng dladm_status_t 165da14cebeSEric Cheng do_check_port(char *attr_val, boolean_t local, flow_desc_t *fdesc) 166da14cebeSEric Cheng { 167da14cebeSEric Cheng char *endp = NULL; 168da14cebeSEric Cheng long val; 169da14cebeSEric Cheng 170da14cebeSEric Cheng if (local) { 171da14cebeSEric Cheng fdesc->fd_mask |= FLOW_ULP_PORT_LOCAL; 172da14cebeSEric Cheng val = strtol(attr_val, &endp, 10); 173da14cebeSEric Cheng if (val < 1 || val > MAX_PORT) 174da14cebeSEric Cheng return (DLADM_STATUS_INVALID_PORT); 175da14cebeSEric Cheng fdesc->fd_local_port = htons((uint16_t)val); 176da14cebeSEric Cheng } else { 177da14cebeSEric Cheng return (DLADM_STATUS_BADVAL); 178da14cebeSEric Cheng } 179da14cebeSEric Cheng 180da14cebeSEric Cheng return (DLADM_STATUS_OK); 181da14cebeSEric Cheng } 182da14cebeSEric Cheng 183da14cebeSEric Cheng /* 184da14cebeSEric Cheng * Check for invalid and/or duplicate attribute specification 185da14cebeSEric Cheng */ 186da14cebeSEric Cheng static dladm_status_t 187da14cebeSEric Cheng flow_attrlist_check(dladm_arg_list_t *attrlist) 188da14cebeSEric Cheng { 189da14cebeSEric Cheng int i, j; 190da14cebeSEric Cheng boolean_t isset[DLADM_MAX_FLOWATTRS]; 191da14cebeSEric Cheng boolean_t matched; 192da14cebeSEric Cheng 193da14cebeSEric Cheng for (j = 0; j < DLADM_MAX_FLOWATTRS; j++) 194da14cebeSEric Cheng isset[j] = B_FALSE; 195da14cebeSEric Cheng 196da14cebeSEric Cheng for (i = 0; i < attrlist->al_count; i++) { 197da14cebeSEric Cheng matched = B_FALSE; 198da14cebeSEric Cheng for (j = 0; j < DLADM_MAX_FLOWATTRS; j++) { 199da14cebeSEric Cheng if (strcmp(attrlist->al_info[i].ai_name, 200da14cebeSEric Cheng attr_table[j].ad_name) == 0) { 201da14cebeSEric Cheng if (isset[j]) 202da14cebeSEric Cheng return (DLADM_STATUS_FLOW_INCOMPATIBLE); 203da14cebeSEric Cheng else 204da14cebeSEric Cheng isset[j] = B_TRUE; 205da14cebeSEric Cheng matched = B_TRUE; 206da14cebeSEric Cheng } 207da14cebeSEric Cheng } 208da14cebeSEric Cheng /* 209da14cebeSEric Cheng * if the attribute did not match any of the attribute in 210da14cebeSEric Cheng * attr_table, then it's an invalid attribute. 211da14cebeSEric Cheng */ 212da14cebeSEric Cheng if (!matched) 213da14cebeSEric Cheng return (DLADM_STATUS_BADARG); 214da14cebeSEric Cheng } 215da14cebeSEric Cheng return (DLADM_STATUS_OK); 216da14cebeSEric Cheng } 217da14cebeSEric Cheng 218da14cebeSEric Cheng /* 219da14cebeSEric Cheng * Convert an attribute list to a flow_desc_t using the attribute ad_check() 220da14cebeSEric Cheng * functions. 221da14cebeSEric Cheng */ 222da14cebeSEric Cheng dladm_status_t 223da14cebeSEric Cheng dladm_flow_attrlist_extract(dladm_arg_list_t *attrlist, flow_desc_t *flowdesc) 224da14cebeSEric Cheng { 225da14cebeSEric Cheng dladm_status_t status = DLADM_STATUS_BADARG; 226da14cebeSEric Cheng int i; 227da14cebeSEric Cheng 228da14cebeSEric Cheng for (i = 0; i < attrlist->al_count; i++) { 229da14cebeSEric Cheng dladm_arg_info_t *aip = &attrlist->al_info[i]; 230da14cebeSEric Cheng int j; 231da14cebeSEric Cheng 232da14cebeSEric Cheng for (j = 0; j < DLADM_MAX_FLOWATTRS; j++) { 233da14cebeSEric Cheng fattr_desc_t *adp = &attr_table[j]; 234da14cebeSEric Cheng 235da14cebeSEric Cheng if (strcasecmp(aip->ai_name, adp->ad_name) != 0) 236da14cebeSEric Cheng continue; 237da14cebeSEric Cheng 238da14cebeSEric Cheng if ((aip->ai_val == NULL) || (*aip->ai_val == NULL)) 239da14cebeSEric Cheng return (DLADM_STATUS_BADARG); 240da14cebeSEric Cheng 241da14cebeSEric Cheng if (adp->ad_check != NULL) 242da14cebeSEric Cheng status = adp->ad_check(*aip->ai_val, flowdesc); 243da14cebeSEric Cheng else 244da14cebeSEric Cheng status = DLADM_STATUS_BADARG; 245da14cebeSEric Cheng 246da14cebeSEric Cheng if (status != DLADM_STATUS_OK) 247da14cebeSEric Cheng return (status); 248da14cebeSEric Cheng } 249da14cebeSEric Cheng } 250da14cebeSEric Cheng return (status); 251da14cebeSEric Cheng } 252da14cebeSEric Cheng 253da14cebeSEric Cheng void 254da14cebeSEric Cheng dladm_free_attrs(dladm_arg_list_t *list) 255da14cebeSEric Cheng { 256da14cebeSEric Cheng dladm_free_args(list); 257da14cebeSEric Cheng } 258da14cebeSEric Cheng 259da14cebeSEric Cheng dladm_status_t 260da14cebeSEric Cheng dladm_parse_flow_attrs(char *str, dladm_arg_list_t **listp, boolean_t novalues) 261da14cebeSEric Cheng { 262da14cebeSEric Cheng 263da14cebeSEric Cheng if (dladm_parse_args(str, listp, novalues) 264da14cebeSEric Cheng != DLADM_STATUS_OK) 265da14cebeSEric Cheng return (DLADM_STATUS_ATTR_PARSE_ERR); 266da14cebeSEric Cheng 267*63a6526dSMichael Lim if (*listp != NULL && flow_attrlist_check(*listp) 268*63a6526dSMichael Lim != DLADM_STATUS_OK) { 269da14cebeSEric Cheng dladm_free_attrs(*listp); 270da14cebeSEric Cheng return (DLADM_STATUS_ATTR_PARSE_ERR); 271da14cebeSEric Cheng } 272da14cebeSEric Cheng 273da14cebeSEric Cheng return (DLADM_STATUS_OK); 274da14cebeSEric Cheng } 275da14cebeSEric Cheng 276da14cebeSEric Cheng dladm_status_t 277da14cebeSEric Cheng do_check_dsfield(char *str, flow_desc_t *fd) 278da14cebeSEric Cheng { 279da14cebeSEric Cheng char *mask_str, *endp = NULL; 280da14cebeSEric Cheng uint_t mask = 0xff, value; 281da14cebeSEric Cheng 282da14cebeSEric Cheng if ((mask_str = strchr(str, ':')) != NULL) { 283da14cebeSEric Cheng *mask_str++ = '\0'; 284da14cebeSEric Cheng errno = 0; 285da14cebeSEric Cheng mask = strtoul(mask_str, &endp, 16); 286da14cebeSEric Cheng if (errno != 0 || mask == 0 || mask > 0xff || 287da14cebeSEric Cheng *endp != '\0') 288da14cebeSEric Cheng return (DLADM_STATUS_INVALID_DSFMASK); 289da14cebeSEric Cheng } 290da14cebeSEric Cheng errno = 0; 291da14cebeSEric Cheng endp = NULL; 292da14cebeSEric Cheng value = strtoul(str, &endp, 16); 293da14cebeSEric Cheng if (errno != 0 || value == 0 || value > 0xff || *endp != '\0') 294da14cebeSEric Cheng return (DLADM_STATUS_INVALID_DSF); 295da14cebeSEric Cheng 296da14cebeSEric Cheng fd->fd_dsfield = (uint8_t)value; 297da14cebeSEric Cheng fd->fd_dsfield_mask = (uint8_t)mask; 298da14cebeSEric Cheng fd->fd_mask |= FLOW_IP_DSFIELD; 299da14cebeSEric Cheng return (DLADM_STATUS_OK); 300da14cebeSEric Cheng } 301da14cebeSEric Cheng 302da14cebeSEric Cheng char * 303da14cebeSEric Cheng dladm_proto2str(uint8_t protocol) 304da14cebeSEric Cheng { 305da14cebeSEric Cheng if (protocol == IPPROTO_TCP) 306da14cebeSEric Cheng return ("tcp"); 307da14cebeSEric Cheng if (protocol == IPPROTO_UDP) 308da14cebeSEric Cheng return ("udp"); 309da14cebeSEric Cheng if (protocol == IPPROTO_SCTP) 310da14cebeSEric Cheng return ("sctp"); 311da14cebeSEric Cheng if (protocol == IPPROTO_ICMPV6) 312da14cebeSEric Cheng return ("icmpv6"); 313da14cebeSEric Cheng if (protocol == IPPROTO_ICMP) 314da14cebeSEric Cheng return ("icmp"); 315da14cebeSEric Cheng else 316da14cebeSEric Cheng return (""); 317da14cebeSEric Cheng } 318da14cebeSEric Cheng 319da14cebeSEric Cheng uint8_t 320da14cebeSEric Cheng dladm_str2proto(const char *protostr) 321da14cebeSEric Cheng { 322da14cebeSEric Cheng if (strncasecmp(protostr, "tcp", 3) == 0) 323da14cebeSEric Cheng return (IPPROTO_TCP); 324da14cebeSEric Cheng else if (strncasecmp(protostr, "udp", 3) == 0) 325da14cebeSEric Cheng return (IPPROTO_UDP); 326da14cebeSEric Cheng else if (strncasecmp(protostr, "sctp", 4) == 0) 327da14cebeSEric Cheng return (IPPROTO_SCTP); 328da14cebeSEric Cheng else if (strncasecmp(protostr, "icmpv6", 6) == 0) 329da14cebeSEric Cheng return (IPPROTO_ICMPV6); 330da14cebeSEric Cheng else if (strncasecmp(protostr, "icmp", 4) == 0) 331da14cebeSEric Cheng return (IPPROTO_ICMP); 332da14cebeSEric Cheng 333da14cebeSEric Cheng return (0); 334da14cebeSEric Cheng } 335da14cebeSEric Cheng 336da14cebeSEric Cheng void 337da14cebeSEric Cheng dladm_flow_attr_ip2str(dladm_flow_attr_t *attrp, char *buf, size_t buf_len) 338da14cebeSEric Cheng { 339da14cebeSEric Cheng flow_desc_t fdesc = attrp->fa_flow_desc; 340da14cebeSEric Cheng struct in_addr ipaddr; 341da14cebeSEric Cheng int prefix_len, prefix_max; 342da14cebeSEric Cheng char *cp, abuf[INET6_ADDRSTRLEN]; 343da14cebeSEric Cheng 344da14cebeSEric Cheng if (fdesc.fd_mask & FLOW_IP_LOCAL) { 345da14cebeSEric Cheng if (fdesc.fd_ipversion == IPV6_VERSION) { 346da14cebeSEric Cheng (void) inet_ntop(AF_INET6, &fdesc.fd_local_addr, abuf, 347da14cebeSEric Cheng INET6_ADDRSTRLEN); 348da14cebeSEric Cheng cp = abuf; 349da14cebeSEric Cheng prefix_max = IPV6_ABITS; 350da14cebeSEric Cheng } else { 351da14cebeSEric Cheng ipaddr.s_addr = fdesc.fd_local_addr._S6_un._S6_u32[3]; 352da14cebeSEric Cheng cp = inet_ntoa(ipaddr); 353da14cebeSEric Cheng prefix_max = IP_ABITS; 354da14cebeSEric Cheng } 355da14cebeSEric Cheng (void) dladm_mask2prefixlen(&fdesc.fd_local_netmask, 356da14cebeSEric Cheng prefix_max, &prefix_len); 357da14cebeSEric Cheng (void) snprintf(buf, buf_len, "LCL:%s/%d ", cp, prefix_len); 358da14cebeSEric Cheng } else if (fdesc.fd_mask & FLOW_IP_REMOTE) { 359da14cebeSEric Cheng if (fdesc.fd_ipversion == IPV6_VERSION) { 360da14cebeSEric Cheng (void) inet_ntop(AF_INET6, &fdesc.fd_remote_addr, abuf, 361da14cebeSEric Cheng INET6_ADDRSTRLEN); 362da14cebeSEric Cheng cp = abuf; 363da14cebeSEric Cheng prefix_max = IPV6_ABITS; 364da14cebeSEric Cheng } else { 365da14cebeSEric Cheng ipaddr.s_addr = fdesc.fd_remote_addr._S6_un._S6_u32[3]; 366da14cebeSEric Cheng cp = inet_ntoa(ipaddr); 367da14cebeSEric Cheng prefix_max = IP_ABITS; 368da14cebeSEric Cheng } 369da14cebeSEric Cheng (void) dladm_mask2prefixlen(&fdesc.fd_remote_netmask, 370da14cebeSEric Cheng prefix_max, &prefix_len); 371da14cebeSEric Cheng (void) snprintf(buf, buf_len, "RMT:%s/%d ", cp, prefix_len); 372da14cebeSEric Cheng } else { 373da14cebeSEric Cheng buf[0] = '\0'; 374da14cebeSEric Cheng } 375da14cebeSEric Cheng } 376da14cebeSEric Cheng 377da14cebeSEric Cheng void 378da14cebeSEric Cheng dladm_flow_attr_proto2str(dladm_flow_attr_t *attrp, char *buf, size_t buf_len) 379da14cebeSEric Cheng { 380da14cebeSEric Cheng flow_desc_t fdesc = attrp->fa_flow_desc; 381da14cebeSEric Cheng 382da14cebeSEric Cheng (void) snprintf(buf, buf_len, "%s", 383da14cebeSEric Cheng dladm_proto2str(fdesc.fd_protocol)); 384da14cebeSEric Cheng } 385da14cebeSEric Cheng 386da14cebeSEric Cheng void 387da14cebeSEric Cheng dladm_flow_attr_port2str(dladm_flow_attr_t *attrp, char *buf, size_t buf_len) 388da14cebeSEric Cheng { 389da14cebeSEric Cheng flow_desc_t fdesc = attrp->fa_flow_desc; 390da14cebeSEric Cheng 391da14cebeSEric Cheng if (fdesc.fd_mask & FLOW_ULP_PORT_LOCAL) { 392da14cebeSEric Cheng (void) snprintf(buf, buf_len, "%d", 393da14cebeSEric Cheng ntohs(fdesc.fd_local_port)); 394da14cebeSEric Cheng } else { 395da14cebeSEric Cheng buf[0] = '\0'; 396da14cebeSEric Cheng } 397da14cebeSEric Cheng } 398da14cebeSEric Cheng 399da14cebeSEric Cheng void 400da14cebeSEric Cheng dladm_flow_attr_dsfield2str(dladm_flow_attr_t *attrp, char *buf, size_t buf_len) 401da14cebeSEric Cheng { 402da14cebeSEric Cheng flow_desc_t fdesc = attrp->fa_flow_desc; 403da14cebeSEric Cheng 404da14cebeSEric Cheng if (fdesc.fd_mask & FLOW_IP_DSFIELD) { 405da14cebeSEric Cheng (void) snprintf(buf, buf_len, "0x%x:0x%x", 406da14cebeSEric Cheng fdesc.fd_dsfield, fdesc.fd_dsfield_mask); 407da14cebeSEric Cheng } else { 408da14cebeSEric Cheng buf[0] = '\0'; 409da14cebeSEric Cheng } 410da14cebeSEric Cheng } 411