4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * CDDL HEADER START
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * The contents of this file are subject to the terms of the
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * Common Development and Distribution License (the "License").
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * You may not use this file except in compliance with the License.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * or http://www.opensolaris.org/os/licensing.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * See the License for the specific language governing permissions
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * and limitations under the License.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * When distributing Covered Code, include this CDDL HEADER in each
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * If applicable, add the following below this CDDL HEADER, with the
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * fields enclosed by brackets "[]" replaced with your own identifying
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * information: Portions Copyright [yyyy] [name of copyright owner]
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * CDDL HEADER END
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * Use is subject to license terms.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * bridged - bridging control daemon.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * engine_lock is held while the main loop is busy calling librstp functions.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * Door threads take the lock to protect the library from reentrancy.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaistatic pthread_mutex_t engine_lock = PTHREAD_MUTEX_INITIALIZER;
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * These wrapper functions allow the other components in the daemon to remain
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * ignorant of pthreads details.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai return (pthread_mutex_lock(&engine_lock));
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai (void) pthread_mutex_unlock(&engine_lock);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * Utility function for STREAMS ioctls.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavaistrioctl(int fd, int cmd, void *buf, size_t buflen)
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * A little bit of magic here. By the first fork+setsid, we
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * disconnect from our current controlling terminal and become
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * a session group leader. By forking again without calling
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * setsid again, we make certain that we are not the session
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * group leader and can never reacquire a controlling terminal.
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai syslog(LOG_NOTICE, "%s signal, shutting down",
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai /* if we're shutting down, exit this thread */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai if ((fdarray = malloc(FDOFFSET * sizeof (struct pollfd))) == NULL) {
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai syslog(LOG_ERR, "unable to allocate fdarray: %m");
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai syslog(LOG_ERR, "unable to create signal pipe: %m");
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai (void) pthread_sigmask(SIG_BLOCK, &new, NULL);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai (void) pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai err = pthread_create(&sighand, &attr, sighandler,
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai syslog(LOG_ERR, "cannot create signal handling thread: %s",
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai openlog("bridged", LOG_PID | LOG_NDELAY, LOG_DAEMON);
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai syslog(LOG_ERR, "instance name is required");
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai if ((status = dladm_open(&dlhandle)) != DLADM_STATUS_OK) {
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai syslog(LOG_ERR, "%s: unable to open datalink control: %s",
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai instance_name, dladm_status2str(status, buf));
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai status = dladm_bridge_get_privprop(instance_name, &debugging,
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai syslog(LOG_ERR, "%s: unable to read properties: %s",
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai instance_name, dladm_status2str(status, buf));
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai /* Get the properties once so that we have the right initial values */
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai syslog(LOG_INFO, "bridged started: instance %s", instance_name);