Jonathan Hart
Committed by Gerrit Code Review

vRouter: ignore routes that don't come from Quagga

Change-Id: I1a67a18b7f5f0a4e43156c017b92c12789e81104
......@@ -41,6 +41,7 @@ import org.onosproject.routing.fpm.protocol.RouteAttribute;
import org.onosproject.routing.fpm.protocol.RouteAttributeDst;
import org.onosproject.routing.fpm.protocol.RouteAttributeGateway;
import org.onosproject.routing.fpm.protocol.RtNetlink;
import org.onosproject.routing.fpm.protocol.RtProtocol;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -145,6 +146,11 @@ public class FpmManager implements RouteSourceService {
log.trace("Received FPM message: {}", fpmMessage);
}
if (rtNetlink.protocol() != RtProtocol.ZEBRA) {
log.trace("Ignoring non-zebra route");
return;
}
IpAddress dstAddress = null;
IpAddress gateway = null;
......
......@@ -43,7 +43,7 @@ public final class RtNetlink {
private final int srcLength;
private final short tos;
private final short table;
private final short protocol;
private final RtProtocol protocol;
private final short scope;
private final short type;
private final long flags;
......@@ -69,7 +69,7 @@ public final class RtNetlink {
int srcLength,
short tos,
short table,
short protocol,
RtProtocol protocol,
short scope,
short type,
long flags,
......@@ -139,7 +139,7 @@ public final class RtNetlink {
*
* @return protocol
*/
public short protocol() {
public RtProtocol protocol() {
return protocol;
}
......@@ -222,6 +222,8 @@ public final class RtNetlink {
long flags = Integer.reverseBytes(bb.getInt());
List<RouteAttribute> attributes = new ArrayList<>();
RtProtocol rtProtocol = RtProtocol.get(protocol);
while (bb.hasRemaining()) {
RouteAttribute attribute = RouteAttribute.decode(buffer, bb.position(),
bb.limit() - bb.position());
......@@ -235,7 +237,7 @@ public final class RtNetlink {
srcLength,
tos,
table,
protocol,
rtProtocol,
scope,
type,
flags,
......
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.routing.fpm.protocol;
/**
* RtNetlink protocol value.
* <p>
* This is a subset of the protocol values used in rtnetlink.
* Taken from linux/rtnetlink.h
* </p>
*/
public enum RtProtocol {
/**
* Unspecified.
*/
UNSPEC((short) 0),
/**
* Route installed by ICMP redirects.
*/
REDIRECT((short) 1),
/**
* Route installed by kernel.
*/
KERNEL((short) 2),
/**
* Route installed during boot.
*/
BOOT((short) 3),
/**
* Route installed by administrator.
*/
STATIC((short) 4),
/**
* GateD.
*/
GATED((short) 8),
/**
* RDISC/ND router advertisements.
*/
RA((short) 9),
/**
* Merit MRT.
*/
MRT((short) 10),
/**
* Zebra.
*/
ZEBRA((short) 11),
/**
* BIRD.
*/
BIRD((short) 12),
/**
* DECnet routing daemon.
*/
DNROUTED((short) 13),
/**
* XORP.
*/
XORP((short) 14),
/**
* Netsukuku.
*/
NTK((short) 15),
/**
* DHCP client.
*/
DHCP((short) 16),
/**
* Multicast daemon.
*/
MROUTED((short) 17),
/**
* Unknown.
*/
UNKNOWN((short) 0);
private final short value;
/**
* Constructor.
*
* @param value value
*/
RtProtocol(short value) {
this.value = value;
}
/**
* Returns the value.
*
* @return value
*/
public short value() {
return value;
}
/**
* Gets the RtProtocol for the given integer value.
*
* @param value value
* @return RtProtocol, or null if unsupported type value
*/
public static RtProtocol get(short value) {
for (RtProtocol p : RtProtocol.values()) {
if (p.value() == value) {
return p;
}
}
return UNKNOWN;
}
}