[Xorp-hackers] [PATCH 2/2] xorp: fea: Create input socket before registering multicast listener
igorm at etf.rs
igorm at etf.rs
Mon Apr 2 08:12:49 PDT 2012
From: Igor Maravic <igorm at etf.rs>
Enabled creation of input socket before calling the function
join_multicast group().
This enable us to get packages from the interface even if we
didn't registered multicast listener on if/vif.
Signed-off-by: Igor Maravic <igorm at etf.rs>
---
xorp/fea/data_plane/io/io_ip_dummy.cc | 19 +++++++++++
xorp/fea/data_plane/io/io_ip_dummy.hh | 12 +++++++
xorp/fea/data_plane/io/io_ip_socket.cc | 32 ++++++++++++++++++
xorp/fea/data_plane/io/io_ip_socket.hh | 12 +++++++
xorp/fea/io_ip.hh | 12 +++++++
xorp/fea/io_ip_manager.cc | 55 ++++++++++++++++++++++++++++++++
xorp/fea/io_ip_manager.hh | 11 ++++++
7 files changed, 153 insertions(+), 0 deletions(-)
diff --git a/xorp/fea/data_plane/io/io_ip_dummy.cc b/xorp/fea/data_plane/io/io_ip_dummy.cc
index b2f4656..44e1542 100644
--- a/xorp/fea/data_plane/io/io_ip_dummy.cc
+++ b/xorp/fea/data_plane/io/io_ip_dummy.cc
@@ -140,6 +140,25 @@ IoIpDummy::set_default_multicast_interface(const string& if_name,
}
int
+IoIpDummy::create_input_socket(const string& if_name,
+ const string& vif_name,
+ string& error_msg)
+{
+ const IfTreeVif* vifp;
+
+ // Find the vif
+ vifp = iftree().find_vif(if_name, vif_name);
+ if (vifp == NULL) {
+ error_msg = c_format("Creating input socket failed: "
+ "interface %s vif %s not found",
+ if_name.c_str(),
+ vif_name.c_str());
+ return (XORP_ERROR);
+ }
+ return (XORP_OK);
+}
+
+int
IoIpDummy::join_multicast_group(const string& if_name,
const string& vif_name,
const IPvX& group,
diff --git a/xorp/fea/data_plane/io/io_ip_dummy.hh b/xorp/fea/data_plane/io/io_ip_dummy.hh
index 2708acd..fda6842 100644
--- a/xorp/fea/data_plane/io/io_ip_dummy.hh
+++ b/xorp/fea/data_plane/io/io_ip_dummy.hh
@@ -116,6 +116,18 @@ public:
string& error_msg);
/**
+ * Create input socket.
+ *
+ * @param if_name the name of the interface to listen on
+ * @param vif_name the name of the vif to listen on
+ * @error error_msg the error message (if error).
+ * @return XORP_OK on success, otherwise XORP_ERROR
+ */
+ int create_input_socket(const string& if_name,
+ const string& vif_name,
+ string& error_msg);
+
+ /**
* Join a multicast group on an interface.
*
* @param if_name the name of the interface to join the multicast group.
diff --git a/xorp/fea/data_plane/io/io_ip_socket.cc b/xorp/fea/data_plane/io/io_ip_socket.cc
index a7f4a4d..c22ec0a 100644
--- a/xorp/fea/data_plane/io/io_ip_socket.cc
+++ b/xorp/fea/data_plane/io/io_ip_socket.cc
@@ -519,6 +519,38 @@ IoIpSocket::set_default_multicast_interface(const string& if_name,
}
int
+IoIpSocket::create_input_socket(const string& if_name,
+ const string& vif_name,
+ string& error_msg)
+{
+ error_msg.clear();
+
+ if (!iftree().find_vif(if_name, vif_name)) {
+ error_msg += c_format("Creating of input socket failed: "
+ "interface %s vif %s not found",
+ if_name.c_str(),
+ vif_name.c_str());
+ goto out_err;
+ }
+
+ if (!findOrCreateInputSocket(if_name, vif_name, error_msg)) {
+ string em = c_format("ERROR: Could not find or create input socket, "
+ "if_name: %s vif_name: %s error_msg: %s",
+ if_name.c_str(), vif_name.c_str(), error_msg.c_str());
+ XLOG_WARNING("%s", em.c_str());
+ error_msg += em;
+ goto out_err;
+ }
+ return XORP_OK;
+
+out_err:
+ if (error_msg.size()) {
+ XLOG_ERROR("ERROR in %s: %s", __func__, error_msg.c_str());
+ }
+ return XORP_ERROR;
+}
+
+int
IoIpSocket::join_multicast_group(const string& if_name,
const string& vif_name,
const IPvX& group,
diff --git a/xorp/fea/data_plane/io/io_ip_socket.hh b/xorp/fea/data_plane/io/io_ip_socket.hh
index 35714d7..841d1e7 100644
--- a/xorp/fea/data_plane/io/io_ip_socket.hh
+++ b/xorp/fea/data_plane/io/io_ip_socket.hh
@@ -123,6 +123,18 @@ public:
string& error_msg);
/**
+ * Create input socket.
+ *
+ * @param if_name the name of the interface to listen on
+ * @param vif_name the name of the vif to listen on
+ * @error error_msg the error message (if error).
+ * @return XORP_OK on success, otherwise XORP_ERROR
+ */
+ int create_input_socket(const string& if_name,
+ const string& vif_name,
+ string& error_msg);
+
+ /**
* Join a multicast group on an interface.
*
* @param if_name the name of the interface to join the multicast group.
diff --git a/xorp/fea/io_ip.hh b/xorp/fea/io_ip.hh
index c6d6a68..635fc41 100644
--- a/xorp/fea/io_ip.hh
+++ b/xorp/fea/io_ip.hh
@@ -191,6 +191,18 @@ public:
string& error_msg) = 0;
/**
+ * Create input socket.
+ *
+ * @param if_name the name of the interface to listen on
+ * @param vif_name the name of the vif to listen on
+ * @error error_msg the error message (if error).
+ * @return XORP_OK on success, otherwise XORP_ERROR
+ */
+ virtual int create_input_socket(const string& if_name,
+ const string& vif_name,
+ string& error_msg) = 0;
+
+ /**
* Join a multicast group on an interface.
*
* @param if_name the name of the interface to join the multicast group.
diff --git a/xorp/fea/io_ip_manager.cc b/xorp/fea/io_ip_manager.cc
index a599b9f..ddaae3f 100644
--- a/xorp/fea/io_ip_manager.cc
+++ b/xorp/fea/io_ip_manager.cc
@@ -384,6 +384,58 @@ IoIpComm::recv_system_multicast_upcall(const vector<uint8_t>& payload)
}
}
+void
+IoIpComm::create_input_socket(const string& if_name,
+ const string& vif_name)
+{
+ bool err = false;
+ string error_msg;
+
+ if (_io_ip_plugins.empty()) {
+ error_msg = c_format("No I/O IP plugin to create input socket "
+ "on interface %s vif %s protocol %u",
+ if_name.c_str(), vif_name.c_str(),
+ _ip_protocol);
+ goto error;
+ }
+
+ //
+ // Check the arguments
+ //
+ if (if_name.empty()) {
+ error_msg = c_format("Cannot create input socket: empty interface name");
+ goto error;
+ }
+ if (vif_name.empty()) {
+ error_msg = c_format("Cannot create input socket on interface %s: "
+ "empty vif name", if_name.c_str());
+ goto error;
+ }
+
+ do {
+ IoIpPlugins::iterator plugin_iter;
+ for (plugin_iter = _io_ip_plugins.begin();
+ plugin_iter != _io_ip_plugins.end(); ++plugin_iter) {
+ IoIp* io_ip = plugin_iter->second;
+ if (io_ip->create_input_socket(if_name, vif_name,
+ error_msg) != XORP_OK) {
+ err = true;
+ if (!error_msg.empty())
+ error_msg += " ";
+ error_msg += error_msg;
+ }
+ }
+ } while (0); //dummy loop to avoid compiler warning
+
+ if (err)
+ goto error;
+
+ return;
+error:
+ XLOG_WARNING("%s\n", error_msg.c_str());
+ return;
+}
+
int
IoIpComm::join_multicast_group(const string& if_name,
const string& vif_name,
@@ -932,6 +984,9 @@ IoIpManager::register_receiver(int family,
// Add the filter to those associated with receiver_name
filters.insert(FilterBag::value_type(receiver_name, filter));
+ //Create input socket for if vif pair
+ io_ip_comm->create_input_socket(if_name, vif_name);
+
// Register interest in watching the receiver
if (_fea_node.fea_io().add_instance_watch(receiver_name, this, error_msg)
!= XORP_OK) {
diff --git a/xorp/fea/io_ip_manager.hh b/xorp/fea/io_ip_manager.hh
index 3df7afa..04da094 100644
--- a/xorp/fea/io_ip_manager.hh
+++ b/xorp/fea/io_ip_manager.hh
@@ -373,6 +373,17 @@ public:
virtual void recv_system_multicast_upcall(const vector<uint8_t>& payload);
/**
+ * Create input socket.
+ *
+ * @param if_name the name of the interface to listen on
+ * @param vif_name the name of the vif to listen on
+ * @error error_msg the error message (if error).
+ * @return XORP_OK on success, otherwise XORP_ERROR
+ */
+ void create_input_socket(const string& if_name,
+ const string& vif_name);
+
+ /**
* Join an IP multicast group.
*
* @param if_name the interface through which packets should be accepted.
--
1.7.5.4
More information about the Xorp-hackers
mailing list