Committed by
Gerrit Code Review
vRouter: ignore routes that don't come from Quagga
Change-Id: I1a67a18b7f5f0a4e43156c017b92c12789e81104
Showing
3 changed files
with
153 additions
and
4 deletions
| ... | @@ -41,6 +41,7 @@ import org.onosproject.routing.fpm.protocol.RouteAttribute; | ... | @@ -41,6 +41,7 @@ import org.onosproject.routing.fpm.protocol.RouteAttribute; |
| 41 | import org.onosproject.routing.fpm.protocol.RouteAttributeDst; | 41 | import org.onosproject.routing.fpm.protocol.RouteAttributeDst; |
| 42 | import org.onosproject.routing.fpm.protocol.RouteAttributeGateway; | 42 | import org.onosproject.routing.fpm.protocol.RouteAttributeGateway; |
| 43 | import org.onosproject.routing.fpm.protocol.RtNetlink; | 43 | import org.onosproject.routing.fpm.protocol.RtNetlink; |
| 44 | +import org.onosproject.routing.fpm.protocol.RtProtocol; | ||
| 44 | import org.slf4j.Logger; | 45 | import org.slf4j.Logger; |
| 45 | import org.slf4j.LoggerFactory; | 46 | import org.slf4j.LoggerFactory; |
| 46 | 47 | ||
| ... | @@ -145,6 +146,11 @@ public class FpmManager implements RouteSourceService { | ... | @@ -145,6 +146,11 @@ public class FpmManager implements RouteSourceService { |
| 145 | log.trace("Received FPM message: {}", fpmMessage); | 146 | log.trace("Received FPM message: {}", fpmMessage); |
| 146 | } | 147 | } |
| 147 | 148 | ||
| 149 | + if (rtNetlink.protocol() != RtProtocol.ZEBRA) { | ||
| 150 | + log.trace("Ignoring non-zebra route"); | ||
| 151 | + return; | ||
| 152 | + } | ||
| 153 | + | ||
| 148 | IpAddress dstAddress = null; | 154 | IpAddress dstAddress = null; |
| 149 | IpAddress gateway = null; | 155 | IpAddress gateway = null; |
| 150 | 156 | ... | ... |
| ... | @@ -43,7 +43,7 @@ public final class RtNetlink { | ... | @@ -43,7 +43,7 @@ public final class RtNetlink { |
| 43 | private final int srcLength; | 43 | private final int srcLength; |
| 44 | private final short tos; | 44 | private final short tos; |
| 45 | private final short table; | 45 | private final short table; |
| 46 | - private final short protocol; | 46 | + private final RtProtocol protocol; |
| 47 | private final short scope; | 47 | private final short scope; |
| 48 | private final short type; | 48 | private final short type; |
| 49 | private final long flags; | 49 | private final long flags; |
| ... | @@ -69,7 +69,7 @@ public final class RtNetlink { | ... | @@ -69,7 +69,7 @@ public final class RtNetlink { |
| 69 | int srcLength, | 69 | int srcLength, |
| 70 | short tos, | 70 | short tos, |
| 71 | short table, | 71 | short table, |
| 72 | - short protocol, | 72 | + RtProtocol protocol, |
| 73 | short scope, | 73 | short scope, |
| 74 | short type, | 74 | short type, |
| 75 | long flags, | 75 | long flags, |
| ... | @@ -139,7 +139,7 @@ public final class RtNetlink { | ... | @@ -139,7 +139,7 @@ public final class RtNetlink { |
| 139 | * | 139 | * |
| 140 | * @return protocol | 140 | * @return protocol |
| 141 | */ | 141 | */ |
| 142 | - public short protocol() { | 142 | + public RtProtocol protocol() { |
| 143 | return protocol; | 143 | return protocol; |
| 144 | } | 144 | } |
| 145 | 145 | ||
| ... | @@ -222,6 +222,8 @@ public final class RtNetlink { | ... | @@ -222,6 +222,8 @@ public final class RtNetlink { |
| 222 | long flags = Integer.reverseBytes(bb.getInt()); | 222 | long flags = Integer.reverseBytes(bb.getInt()); |
| 223 | List<RouteAttribute> attributes = new ArrayList<>(); | 223 | List<RouteAttribute> attributes = new ArrayList<>(); |
| 224 | 224 | ||
| 225 | + RtProtocol rtProtocol = RtProtocol.get(protocol); | ||
| 226 | + | ||
| 225 | while (bb.hasRemaining()) { | 227 | while (bb.hasRemaining()) { |
| 226 | RouteAttribute attribute = RouteAttribute.decode(buffer, bb.position(), | 228 | RouteAttribute attribute = RouteAttribute.decode(buffer, bb.position(), |
| 227 | bb.limit() - bb.position()); | 229 | bb.limit() - bb.position()); |
| ... | @@ -235,7 +237,7 @@ public final class RtNetlink { | ... | @@ -235,7 +237,7 @@ public final class RtNetlink { |
| 235 | srcLength, | 237 | srcLength, |
| 236 | tos, | 238 | tos, |
| 237 | table, | 239 | table, |
| 238 | - protocol, | 240 | + rtProtocol, |
| 239 | scope, | 241 | scope, |
| 240 | type, | 242 | type, |
| 241 | flags, | 243 | flags, | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2016 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +package org.onosproject.routing.fpm.protocol; | ||
| 18 | + | ||
| 19 | +/** | ||
| 20 | + * RtNetlink protocol value. | ||
| 21 | + * <p> | ||
| 22 | + * This is a subset of the protocol values used in rtnetlink. | ||
| 23 | + * Taken from linux/rtnetlink.h | ||
| 24 | + * </p> | ||
| 25 | + */ | ||
| 26 | +public enum RtProtocol { | ||
| 27 | + /** | ||
| 28 | + * Unspecified. | ||
| 29 | + */ | ||
| 30 | + UNSPEC((short) 0), | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * Route installed by ICMP redirects. | ||
| 34 | + */ | ||
| 35 | + REDIRECT((short) 1), | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * Route installed by kernel. | ||
| 39 | + */ | ||
| 40 | + KERNEL((short) 2), | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * Route installed during boot. | ||
| 44 | + */ | ||
| 45 | + BOOT((short) 3), | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * Route installed by administrator. | ||
| 49 | + */ | ||
| 50 | + STATIC((short) 4), | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * GateD. | ||
| 54 | + */ | ||
| 55 | + GATED((short) 8), | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * RDISC/ND router advertisements. | ||
| 59 | + */ | ||
| 60 | + RA((short) 9), | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * Merit MRT. | ||
| 64 | + */ | ||
| 65 | + MRT((short) 10), | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * Zebra. | ||
| 69 | + */ | ||
| 70 | + ZEBRA((short) 11), | ||
| 71 | + | ||
| 72 | + /** | ||
| 73 | + * BIRD. | ||
| 74 | + */ | ||
| 75 | + BIRD((short) 12), | ||
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * DECnet routing daemon. | ||
| 79 | + */ | ||
| 80 | + DNROUTED((short) 13), | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * XORP. | ||
| 84 | + */ | ||
| 85 | + XORP((short) 14), | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * Netsukuku. | ||
| 89 | + */ | ||
| 90 | + NTK((short) 15), | ||
| 91 | + | ||
| 92 | + /** | ||
| 93 | + * DHCP client. | ||
| 94 | + */ | ||
| 95 | + DHCP((short) 16), | ||
| 96 | + | ||
| 97 | + /** | ||
| 98 | + * Multicast daemon. | ||
| 99 | + */ | ||
| 100 | + MROUTED((short) 17), | ||
| 101 | + | ||
| 102 | + /** | ||
| 103 | + * Unknown. | ||
| 104 | + */ | ||
| 105 | + UNKNOWN((short) 0); | ||
| 106 | + | ||
| 107 | + private final short value; | ||
| 108 | + | ||
| 109 | + /** | ||
| 110 | + * Constructor. | ||
| 111 | + * | ||
| 112 | + * @param value value | ||
| 113 | + */ | ||
| 114 | + RtProtocol(short value) { | ||
| 115 | + this.value = value; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + /** | ||
| 119 | + * Returns the value. | ||
| 120 | + * | ||
| 121 | + * @return value | ||
| 122 | + */ | ||
| 123 | + public short value() { | ||
| 124 | + return value; | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + /** | ||
| 128 | + * Gets the RtProtocol for the given integer value. | ||
| 129 | + * | ||
| 130 | + * @param value value | ||
| 131 | + * @return RtProtocol, or null if unsupported type value | ||
| 132 | + */ | ||
| 133 | + public static RtProtocol get(short value) { | ||
| 134 | + for (RtProtocol p : RtProtocol.values()) { | ||
| 135 | + if (p.value() == value) { | ||
| 136 | + return p; | ||
| 137 | + } | ||
| 138 | + } | ||
| 139 | + return UNKNOWN; | ||
| 140 | + } | ||
| 141 | +} |
-
Please register or login to post a comment