commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 03/07: gr-blocks: Make tap/tun configurable


From: git
Subject: [Commit-gnuradio] [gnuradio] 03/07: gr-blocks: Make tap/tun configurable, fix GRC spec to be consistent with default flag of IFF_TAP
Date: Mon, 26 Jan 2015 19:06:42 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit 844d2d76ae994bb051733cb73f0ddaa7175805cb
Author: Paul Garver <address@hidden>
Date:   Sat Jan 24 11:32:57 2015 -0500

    gr-blocks: Make tap/tun configurable, fix GRC spec to be consistent with 
default flag of IFF_TAP
---
 gr-blocks/grc/blocks_tuntap_pdu.xml            | 18 ++++++++++++++++--
 gr-blocks/include/gnuradio/blocks/tuntap_pdu.h |  3 ++-
 gr-blocks/lib/tuntap_pdu_impl.cc               | 17 ++++++++++++-----
 gr-blocks/lib/tuntap_pdu_impl.h                |  5 +++--
 4 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/gr-blocks/grc/blocks_tuntap_pdu.xml 
b/gr-blocks/grc/blocks_tuntap_pdu.xml
index d9a63d4..16e5871 100644
--- a/gr-blocks/grc/blocks_tuntap_pdu.xml
+++ b/gr-blocks/grc/blocks_tuntap_pdu.xml
@@ -8,11 +8,11 @@
   <name>TUNTAP PDU</name>
   <key>blocks_tuntap_pdu</key>
   <import>from gnuradio import blocks</import>
-  <make>blocks.tuntap_pdu($ifn, $mtu)</make>
+  <make>blocks.tuntap_pdu($ifn, $mtu, $istunflag)</make>
   <param>
     <name>Interface Name</name>
     <key>ifn</key>
-    <value>tun0</value>
+    <value>tap0</value>
     <type>string</type>
   </param>
   <param>
@@ -21,6 +21,20 @@
     <value>10000</value>
     <type>int</type>
   </param>
+  <param>
+    <name>Flag</name>
+    <key>istunflag</key>
+    <value>False</value>
+    <type>enum</type>
+    <option>
+       <name>TUN(IP Packet)</name>
+       <key>True</key>
+    </option>
+    <option>
+       <name>TAP(Ethernet Frame)</name>
+       <key>False</key>
+    </option>
+  </param>
   <sink>
     <name>pdus</name>
     <type>message</type>
diff --git a/gr-blocks/include/gnuradio/blocks/tuntap_pdu.h 
b/gr-blocks/include/gnuradio/blocks/tuntap_pdu.h
index 3a18a60..a34bab0 100644
--- a/gr-blocks/include/gnuradio/blocks/tuntap_pdu.h
+++ b/gr-blocks/include/gnuradio/blocks/tuntap_pdu.h
@@ -43,8 +43,9 @@ namespace gr {
        * \brief Construct a TUNTAP PDU interface
        * \param dev Device name to create
        * \param MTU Maximum Transmission Unit size
+          * \param istunflag Flag to indicate TUN or Tap
        */
-      static sptr make(std::string dev, int MTU=10000);
+      static sptr make(std::string dev, int MTU=10000, bool istunflag=false);
     };
 
   } /* namespace blocks */
diff --git a/gr-blocks/lib/tuntap_pdu_impl.cc b/gr-blocks/lib/tuntap_pdu_impl.cc
index 0b9ef42..4e01f45 100644
--- a/gr-blocks/lib/tuntap_pdu_impl.cc
+++ b/gr-blocks/lib/tuntap_pdu_impl.cc
@@ -43,29 +43,36 @@ namespace gr {
   namespace blocks {
 
     tuntap_pdu::sptr
-    tuntap_pdu::make(std::string dev, int MTU)
+    tuntap_pdu::make(std::string dev, int MTU, bool istunflag)
     {
 #if (defined(linux) || defined(__linux) || defined(__linux__))
-      return gnuradio::get_initial_sptr(new tuntap_pdu_impl(dev, MTU));
+      return gnuradio::get_initial_sptr(new tuntap_pdu_impl(dev, MTU, 
istunflag));
 #else
       throw std::runtime_error("tuntap_pdu not implemented on this platform");
 #endif
     }
 
 #if (defined(linux) || defined(__linux) || defined(__linux__))
-    tuntap_pdu_impl::tuntap_pdu_impl(std::string dev, int MTU)
+    tuntap_pdu_impl::tuntap_pdu_impl(std::string dev, int MTU, bool istunflag)
       :        block("tuntap_pdu",
                 io_signature::make (0, 0, 0),
                 io_signature::make (0, 0, 0)),
        stream_pdu_base(MTU),
-       d_dev(dev)
+       d_dev(dev),
+       d_istunflag(istunflag)
     {
       // make the tuntap
       char dev_cstr[1024];
       memset(dev_cstr, 0x00, 1024);
       strncpy(dev_cstr, dev.c_str(), std::min(sizeof(dev_cstr), dev.size()));
 
-      d_fd = tun_alloc(dev_cstr);
+      bool istun = d_istunflag;
+      if(istun){
+       d_fd = tun_alloc(dev_cstr, (IFF_TUN | IFF_NO_PI));
+      } else {
+       d_fd = tun_alloc(dev_cstr, (IFF_TAP | IFF_NO_PI));
+      }
+
       if (d_fd <= 0)
         throw std::runtime_error("gr::tuntap_pdu::make: tun_alloc failed (are 
you running as root?)");
 
diff --git a/gr-blocks/lib/tuntap_pdu_impl.h b/gr-blocks/lib/tuntap_pdu_impl.h
index 41e4587..360f954 100644
--- a/gr-blocks/lib/tuntap_pdu_impl.h
+++ b/gr-blocks/lib/tuntap_pdu_impl.h
@@ -38,10 +38,11 @@ namespace gr {
 #if (defined(linux) || defined(__linux) || defined(__linux__))
     private:
       std::string d_dev;
-      int tun_alloc(char *dev, int flags = IFF_TAP | IFF_NO_PI);
+      bool d_istunflag;
+      int tun_alloc(char *dev, int flags);
 
     public:
-      tuntap_pdu_impl(std::string dev, int MTU);
+      tuntap_pdu_impl(std::string dev, int MTU, bool istunflag);
 #endif
     };
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]