Annotation of embedaddon/freevrrpd/vrrp_vlanlist.c, revision 1.1
1.1 ! misho 1: /*
! 2: * Copyright (c) 2001,2002 Sebastien Petit <spe@bsdfr.org>
! 3: *
! 4: * Redistribution and use in source forms, with and without modification,
! 5: * are permitted provided that the following conditions are met:
! 6: * 1. Redistributions of source code must retain the above copyright notice,
! 7: * this list of conditions and the following disclaimer.
! 8: * 2. Redistributions in binary form must reproduce the above copyright notice,
! 9: * this list of conditions and the following disclaimer in the documentation
! 10: * and/or other materials provided with the distribution. Obviously, it
! 11: * would be nice if you gave credit where credit is due but requiring it
! 12: * would be too onerous.
! 13: * 3. All advertising materials mentioning features or use of this software
! 14: * must display the following acknowledgement:
! 15: * This product includes software developed by Sebastien Petit.
! 16: * 4. Neither the name of its contributors may be used to endorse or promote
! 17: * products derived from this software without specific prior written
! 18: * permission.
! 19: *
! 20: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
! 21: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 22: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 23: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
! 24: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 25: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 26: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 27: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 28: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 29: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 30: * SUCH DAMAGE.
! 31: *
! 32: * $Id: vrrp_vlanlist.c,v 1.1 2004/03/06 18:33:57 spe Exp $
! 33: */
! 34:
! 35: #include <errno.h>
! 36: #include "vrrp_vlanlist.h"
! 37:
! 38: /*
! 39: * We use a double chained list with sentinels --- --- |f|->|d|->NULL
! 40: * NULL<-| |<-| | --- ---
! 41: */
! 42:
! 43: char
! 44: vrrp_vlanlist_initialize(struct vrrp_vr * vr)
! 45: {
! 46: vr->vr_if->vlanp = (struct vrrp_vlan_list *) malloc(sizeof(*(vr->vr_if->vlanp)));
! 47: vr->vr_if->vland = (struct vrrp_vlan_list *) malloc(sizeof(*(vr->vr_if->vland)));
! 48: if (!vr->vr_if->vlanp || !vr->vr_if->vland) {
! 49: syslog(LOG_ERR, "Can't allocate memory for vrrp_vlanlist_initialize: %s", strerror(errno));
! 50: return -1;
! 51: }
! 52: bzero(vr->vr_if->vlanp, sizeof(*vr->vr_if->vlanp));
! 53: bzero(vr->vr_if->vland, sizeof(*vr->vr_if->vland));
! 54: vr->vr_if->vlanp->previous = NULL;
! 55: vr->vr_if->vlanp->next = vr->vr_if->vland;
! 56: vr->vr_if->vland->previous = vr->vr_if->vlanp;
! 57: vr->vr_if->vland->next = NULL;
! 58: /*if (vrrp_vlanlist_add(vr, vlan_ifname) == -1) {
! 59: free(vr->vr_if->vlanp);
! 60: free(vr->vr_if->vland);
! 61: return -1;
! 62: } */
! 63: return 0;
! 64: }
! 65:
! 66: /*
! 67: * Add a new element in list
! 68: */
! 69: char
! 70: vrrp_vlanlist_add(struct vrrp_vr * vr, char *vlan_ifname)
! 71: {
! 72: struct vrrp_vlan_list *n;
! 73:
! 74: if (!(n = (struct vrrp_vlan_list *) malloc(sizeof(*n)))) {
! 75: syslog(LOG_ERR, "Can't allocate memory for vrrp_vlanlist_add: %s", strerror(errno));
! 76: return -1;
! 77: }
! 78: bzero(n, sizeof(*n));
! 79: strncpy(n->vlan_ifname, vlan_ifname, sizeof(n->vlan_ifname));
! 80: n->previous = vr->vr_if->vland->previous;
! 81: n->next = vr->vr_if->vland;
! 82: vr->vr_if->vland->previous->next = n;
! 83: vr->vr_if->vland->previous = n;
! 84:
! 85: return 0;
! 86: }
! 87:
! 88: /*
! 89: * Enleve un element de la liste
! 90: */
! 91: char
! 92: vrrp_vlanlist_delete(struct vrrp_vr * vr, char *vlan_ifname)
! 93: {
! 94: struct vrrp_vlan_list *e = vr->vr_if->vlanp;
! 95:
! 96: while (e->next && strcpy(vlan_ifname, e->vlan_ifname))
! 97: e = e->next;
! 98: if (!e->next)
! 99: return -1;
! 100: e->next->previous = e->previous;
! 101: e->previous->next = e->next;
! 102: free(e);
! 103:
! 104: return 0;
! 105: }
! 106:
! 107: char *
! 108: vrrp_vlanlist_get_first(struct vrrp_vr * vr)
! 109: {
! 110: return vr->vr_if->vlanp->next->vlan_ifname;
! 111: }
! 112:
! 113: /*
! 114: * Renvoie l'adresse MAC du dernier element
! 115: */
! 116: char *
! 117: vrrp_vlanlist_get_last(struct vrrp_vr * vr)
! 118: {
! 119: return vr->vr_if->vland->previous->vlan_ifname;
! 120: }
! 121:
! 122: void
! 123: vrrp_vlanlist_destroy(struct vrrp_vr * vr)
! 124: {
! 125: vr->vr_if->vland = vr->vr_if->vland->previous;
! 126: while (vr->vr_if->vland != vr->vr_if->vlanp) {
! 127: free(vr->vr_if->vland->next);
! 128: vr->vr_if->vland = vr->vr_if->vland->previous;
! 129: }
! 130: free(vr->vr_if->vland);
! 131: free(vr->vr_if->vlanp);
! 132:
! 133: return;
! 134: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>