face, mgmt: improve face creation failure and bad URI handling

Prevent creation of faces to endpoints owned by NFD instance

Prevent creation of UDP broadcast faces (255.255.255.255 and
those belonging to machine's interfaces) in response to
face creation command

Sanity check configuration file port numbers in face manager

refs: #1414, #1427

Change-Id: Ia3f0a9337f3d97c34388773eab05bc39ad6dd804
diff --git a/daemon/face/udp-factory.hpp b/daemon/face/udp-factory.hpp
index 969ef8c..fe69794 100644
--- a/daemon/face/udp-factory.hpp
+++ b/daemon/face/udp-factory.hpp
@@ -26,7 +26,7 @@
   {
     Error(const std::string& what) : ProtocolFactory::Error(what) {}
   };
-  
+
   explicit
   UdpFactory(const std::string& defaultPort = "6363");
 
@@ -66,10 +66,10 @@
    *
    * Note that this call will **BLOCK** until resolution is done or failed.
    *
-   * If localHost is a IPv6 address of a specific device, it must be in the form: 
+   * If localHost is a IPv6 address of a specific device, it must be in the form:
    * ip address%interface name
    * Example: fe80::5e96:9dff:fe7d:9c8d%en1
-   * Otherwise, you can use :: 
+   * Otherwise, you can use ::
    *
    * Once a face is created, if it doesn't send/receive anything for
    * a period of time equal to timeout, it will be destroyed
@@ -98,7 +98,7 @@
    * creation fails and an exception is thrown
    *
    * \returns always a valid pointer to a MulticastUdpFace object, an exception
-   *          is thrown if it cannot be created. 
+   *          is thrown if it cannot be created.
    *
    * \throws UdpFactory::Error
    *
@@ -108,12 +108,12 @@
   shared_ptr<MulticastUdpFace>
   createMulticastFace(const udp::Endpoint& localEndpoint,
                       const udp::Endpoint& multicastEndpoint);
-  
+
   shared_ptr<MulticastUdpFace>
   createMulticastFace(const std::string& localIp,
                       const std::string& multicastIp,
                       const std::string& multicastPort);
-  
+
   // from Factory
   virtual void
   createFace(const FaceUri& uri,
@@ -129,9 +129,19 @@
   MulticastFaceMap m_multicastFaces;
 
 private:
+
+  void
+  prohibitEndpoint(const udp::Endpoint& endpoint);
+
+  void
+  prohibitAllIpv4Endpoints(const uint16_t port);
+
+  void
+  prohibitAllIpv6Endpoints(const uint16_t port);
+
   void
   afterFaceFailed(udp::Endpoint& endpoint);
-    
+
   /**
    * \brief Look up UdpChannel using specified local endpoint
    *
@@ -142,8 +152,8 @@
    */
   shared_ptr<UdpChannel>
   findChannel(const udp::Endpoint& localEndpoint);
-  
-  
+
+
   /**
    * \brief Look up multicast UdpFace using specified local endpoint
    *
@@ -154,16 +164,18 @@
    */
   shared_ptr<MulticastUdpFace>
   findMulticastFace(const udp::Endpoint& localEndpoint);
-  
+
   void
   continueCreateFaceAfterResolve(const udp::Endpoint& endpoint,
                                  const FaceCreatedCallback& onCreated,
                                  const FaceConnectFailedCallback& onConnectFailed);
-  
+
   typedef std::map< udp::Endpoint, shared_ptr<UdpChannel> > ChannelMap;
   ChannelMap m_channels;
-  
+
   std::string m_defaultPort;
+
+  std::set<udp::Endpoint> m_prohibitedEndpoints;
 };
 
 } // namespace nfd