]> git.sur5r.net Git - ngadmin/commitdiff
Raw: fix few bugs on port mirroring
authordarkcoven <admin@darkcoven.tk>
Tue, 8 Apr 2014 21:49:00 +0000 (23:49 +0200)
committerdarkcoven <admin@darkcoven.tk>
Tue, 8 Apr 2014 21:49:00 +0000 (23:49 +0200)
raw/src/attr.c

index ec8a0daad9574c334fe3558e2c5d8241a971f91a..fca3c329264dbd4c28b14ee5c8885969bee6b8d1 100644 (file)
@@ -259,10 +259,9 @@ static int mirror_encode (struct attr *at)
         * the ports from which the data is copied, it must not be empty
         *
         * am->outport == 0 is allowed and means mirroring is disabled
         * the ports from which the data is copied, it must not be empty
         *
         * am->outport == 0 is allowed and means mirroring is disabled
-        * but in that case the ports array must be empty
         */
        ports = at->size - sizeof(struct attr_mirror);
         */
        ports = at->size - sizeof(struct attr_mirror);
-       if ((am->outport == 0) ^ (ports == 0))
+       if (am->outport > 0 && ports == 0)
                return -EINVAL;
        
        sz = 3 + ((ports - 1) >> 3);
                return -EINVAL;
        
        sz = 3 + ((ports - 1) >> 3);
@@ -276,7 +275,7 @@ static int mirror_encode (struct attr *at)
        /* FIXME: if ports > 8 */
        for (p = 1; p <= ports; p++) {
                if (am->outport != p)
        /* FIXME: if ports > 8 */
        for (p = 1; p <= ports; p++) {
                if (am->outport != p)
-                       r[2] |= (am->ports[p] & 1) << (8 - p);
+                       r[2] |= (am->ports[p - 1] & 1) << (8 - p);
        }
        
        free(at->data);
        }
        
        free(at->data);
@@ -318,7 +317,7 @@ static int mirror_decode (struct attr *at)
        
        /* FIXME: if ports > 8 */
        for (p = 1; p <= ports; p++)
        
        /* FIXME: if ports > 8 */
        for (p = 1; p <= ports; p++)
-               am->ports[p] = (r[2] >> (8 - p)) & 1;
+               am->ports[p - 1] = (r[2] >> (8 - p)) & 1;
        
        free(at->data);
        at->data = am;
        
        free(at->data);
        at->data = am;