linkprop.c revision f595a68a3b8953a12aa778c2abd7642df8da8c3a
1N/A * The contents of this file are subject to the terms of the 1N/A * Common Development and Distribution License (the "License"). 1N/A * You may not use this file except in compliance with the License. 1N/A * See the License for the specific language governing permissions 1N/A * and limitations under the License. 1N/A * When distributing Covered Code, include this CDDL HEADER in each 1N/A * If applicable, add the following below this CDDL HEADER, with the 1N/A * fields enclosed by brackets "[]" replaced with your own identifying 1N/A * information: Portions Copyright [yyyy] [name of copyright owner] 1N/A * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 1N/A * Use is subject to license terms. 1N/A#
pragma ident "%Z%%M% %I% %E% SMI" 1N/A /* For wifi links, show wifi properties first */ 1N/A /* Then show data-link properties if there are any */ 1N/A * Data structures used for implementing persistent link properties 1N/A * Generate an entry in the link property database. 1N/A * Each entry has this format: 1N/A * <linkname> <prop0>=<val0>,...,<valn>;...;<propn>=<val0>,...,<valn>; 1N/A * Delete line if there are no properties left. 1N/A * Skip properties without values. 1N/A * This function is used to update or create an entry in the persistent db. 1N/A * process_linkprop_db() will first scan the db for an entry matching the 1N/A * specified link. If a match is found, this function is invoked with the 1N/A * entry's contents (buf) and its linked-list representation (listp). lsp 1N/A * holds the name and values of the property to be added or updated; this 1N/A * information will be merged with listp. Subsequently, an updated entry 1N/A * will be written to buf, which will in turn be written to disk by 1N/A * process_linkprop_db(). If no entry matches the specified link, listp 1N/A * will be NULL; a new entry will be generated in this case and it will 1N/A * contain only the property information in lsp. 1N/A * Find the linkprop we want to change. 1N/A * If the linkprop is not found, append it to the list. 1N/A * nlip will need to be freed later if there is no list to 1N/A * If the linkprop is found, delete the existing values from it. 1N/A * Fill our linkprop with the specified values. 1N/A * This function is used for retrieving the values for a specific property. 1N/A * It gets called if an entry matching the specified link exists in the db. 1N/A * The entry is converted into a linked-list listp. This list is then scanned 1N/A * for the specified property name; if a matching property exists, its 1N/A * associated values are copied to the array lsp->ls_propval. 1N/A * Find the linkprop we want to get. 1N/A * This function is meant to be called at most once for each call 1N/A * to process_linkprop_db(). For this reason, it's ok to overwrite 1N/A * the caller's valcnt array size with the actual number of values 1N/A * This is used for initializing link properties. 1N/A * Unlike the other routines, this gets called for every entry in the 1N/A * database. lsp->ls_link is not user-specified but instead is set to 1N/A * the current link being processed. 1N/A * Construct the propval array and fill it with 1N/A * values from listp. 1N/A * We continue with initializing other properties even 1N/A * after encountering an error. This error will be 1N/A * propagated to the caller via 'statusp'. 1N/A * Move to the next character if there is no match and 1N/A * if we have not reached the last character. 1N/A * Nul-terminate the string pointed to by 'curr'. 1N/A * We get here after we have processed the "<prop>=" 1N/A * pattern. The pattern we are now interested in is 1N/A * "<val0>,<val1>,...,<valn>;". For each value we 1N/A * find, a linkprop_val_t will be allocated and 1N/A * added to the current 'lip'. 1N/A * lip == NULL indicates that 'curr' must be refering 1N/A * to a property name. We allocate a new linkprop_info_t 1N/A * append it to the list given by the caller. 1N/A * The list must be non-empty and the last character must be ';'. 1N/A * Skip leading spaces, blank lines, and comments. 1N/A * Skip links we're not interested in. 1N/A * Note that strncmp() and isspace() are used here 1N/A * instead of strtok() and strcmp() because we don't 1N/A * want to modify buf in case it does not contain the 1N/A * If a link is not specified, find the link name 1N/A * and assign it to lsp->ls_link. 1N/A * Now find the list of link properties. 1N/A * Delete corrupted line. 1N/A * This loop processes each line of the configuration file. 1N/A * buf can potentially be modified by process_linkprop_line(). 1N/A * If this is a write operation and buf is not truncated, buf will 1N/A * be written to disk. process_linkprop_line() will no longer be 1N/A * called after it returns B_FALSE; at which point the remainder 1N/A * of the file will continue to be read and, if necessary, written 1N/A * If the specified link is not found above, we add the 1N/A * link and its properties to the configuration file. 1N/A /* Do nothing if setting to current value */ 1N/A /* Do a stat to get the vlan created by MAC, if it's not there */