diff options
author | Paul Garver <garverp@gatech.edu> | 2015-01-24 11:32:57 -0500 |
---|---|---|
committer | Paul Garver <garverp@gatech.edu> | 2015-01-24 11:32:57 -0500 |
commit | 844d2d76ae994bb051733cb73f0ddaa7175805cb (patch) | |
tree | cacc29fead62663bb054486a77db36c6fe703050 | |
parent | 620817ede54bbb89bff449fccfc999c1e6e7887b (diff) |
gr-blocks: Make tap/tun configurable, fix GRC spec to be consistent with default flag of IFF_TAP
-rw-r--r-- | gr-blocks/grc/blocks_tuntap_pdu.xml | 18 | ||||
-rw-r--r-- | gr-blocks/include/gnuradio/blocks/tuntap_pdu.h | 3 | ||||
-rw-r--r-- | gr-blocks/lib/tuntap_pdu_impl.cc | 17 | ||||
-rw-r--r-- | 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 d9a63d4a7f..16e5871b93 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 3a18a60c2f..a34bab0d83 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 0b9ef424ef..4e01f45bea 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 41e4587ac4..360f954630 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 }; |