multicast: setsockopt(IP_MULTICAST_LOOP)


Dear iperf-users,

If you want to test multicast and have only one box with 2 ethernet 
cards, maybe you will find the following patch useful.

Thank you for this useful product.

Regards,


-- 
Eric Bourdin - ERCOM SA


diff -c3 -r iperf-1.7.0/src/Locale.hpp iperf-1.7.0-option-z/src/Locale.hpp
*** iperf-1.7.0/src/Locale.hpp	2003-03-03 22:17:08.000000000 +0100
--- iperf-1.7.0-option-z/src/Locale.hpp	2002-01-01 21:52:52.000000000 +0100
***************
*** 153,158 ****
--- 153,159 ----
     -L, --listenport #       port to recieve bidirectional tests back on\n\
     -P, --parallel  #        number of parallel client threads to run\n\
     -T, --ttl       #        time-to-live, for multicast (default 1)\n\
+   -z, --no-multicast-loop #  disable emission of multicast packets to 
local sockets\n\
   \n\
   Miscellaneous:\n\
     -h, --help               print this message and quit\n\
diff -c3 -r iperf-1.7.0/src/PerfSocket.cpp 
iperf-1.7.0-option-z/src/PerfSocket.cpp
*** iperf-1.7.0/src/PerfSocket.cpp	2003-03-12 19:54:52.000000000 +0100
--- iperf-1.7.0-option-z/src/PerfSocket.cpp	2002-01-01 
21:59:37.000000000 +0100
***************
*** 537,547 ****
           FAIL_errno( rc == SOCKET_ERROR, "setsockopt IP_TOS" );
       }
   #endif

       if ( ! mUDP ) {
           // set the TCP maximum segment size
           setsock_tcp_mss( mSock, mSettings->mMSS );
!
   #ifdef TCP_NODELAY

           // set TCP nodelay option
--- 537,557 ----
           FAIL_errno( rc == SOCKET_ERROR, "setsockopt IP_TOS" );
       }
   #endif
+    if ( mUDP && mSettings->mNoMulticastLoop) {
+ 	int flag = 0;
+ 	int rc = setsockopt( mSock, IPPROTO_IP, IP_MULTICAST_LOOP,
+ 		(void*)&flag, sizeof(flag));
+         if(rc<0) {
+ 		FAIL_errno( rc == SOCKET_ERROR, "setsockopt IP_MULTICAST_LOOP = 0" );
+ 		exit(rc);
+         }
+    }

       if ( ! mUDP ) {
           // set the TCP maximum segment size
           setsock_tcp_mss( mSock, mSettings->mMSS );
! 	
   #ifdef TCP_NODELAY

           // set TCP nodelay option
diff -c3 -r iperf-1.7.0/src/Settings.cpp 
iperf-1.7.0-option-z/src/Settings.cpp
*** iperf-1.7.0/src/Settings.cpp	2003-03-03 22:17:08.000000000 +0100
--- iperf-1.7.0-option-z/src/Settings.cpp	2002-01-01 21:56:23.000000000 
+0100
***************
*** 97,102 ****
--- 97,103 ----
   {"udp",              no_argument, NULL, 'u'},
   {"version",          no_argument, NULL, 'v'},
   {"window",     required_argument, NULL, 'w'},
+ {"no-multicast-loop", no_argument, NULL, 'z'},

   // more esoteric options
   {"bind",       required_argument, NULL, 'B'},
***************
*** 156,162 ****

   #define SHORT_OPTIONS()

! const char short_options[] = 
"b:c:df:hi:l:mn:o:p:rst:uvw:B:CDF:IL:M:NP:RS:T:VW";

   /* -------------------------------------------------------------------
    * defaults
--- 157,163 ----

   #define SHORT_OPTIONS()

! const char short_options[] = 
"b:c:df:hi:l:mn:o:p:rst:uvw:zB:CDF:IL:M:NP:RS:T:VW";

   /* -------------------------------------------------------------------
    * defaults
***************
*** 212,217 ****
--- 213,219 ----
       mExtSettings->mRemoveService = false;      // -R,
       mExtSettings->mTOS        = 0;             // -S,  ie. don't set 
type of service
       mExtSettings->mTTL        = 1;             // -T,  link-local TTL
+     mExtSettings->mNoMulticastLoop = false;    // -Z --no-multicast-loop
       mExtSettings->mDomain     = kMode_IPv4;    // -V,
       mExtSettings->mSuggestWin = false;         // -W,  Suggest the 
window size.

***************
*** 438,443 ****
--- 440,448 ----
                   printf( warn_window_small, mExtSettings->mTCPWin );
               }
               break;
+ 	case 'z': // No Multicast loopback
+ 		mExtSettings->mNoMulticastLoop = true;
+ 	    break;

               // more esoteric options
           case 'B': // specify bind address
diff -c3 -r iperf-1.7.0/src/Settings.hpp 
iperf-1.7.0-option-z/src/Settings.hpp
*** iperf-1.7.0/src/Settings.hpp	2003-02-27 23:35:24.000000000 +0100
--- iperf-1.7.0-option-z/src/Settings.hpp	2002-01-01 21:51:42.000000000 
+0100
***************
*** 134,139 ****
--- 134,140 ----
       bool   mStdin;                  // -I
       bool   mStdout;                 // -o
       bool   mSuggestWin;             // -W
+     bool   mNoMulticastLoop;	      // -z
   };

   #define HEADER_VERSION1 0x80000000
***************
*** 340,345 ****
--- 341,350 ----
           return mExtSettings->mTCPWin;
       }

+     // -z
+     bool GetNoMulticastLoop( void ) const {
+ 	return mExtSettings->mNoMulticastLoop;
+     }
       // ---- more esoteric options

       // -B <host>


diff -c3 -r iperf-1.7.0/src/Locale.hpp iperf-1.7.0-option-z/src/Locale.hpp
*** iperf-1.7.0/src/Locale.hpp	2003-03-03 22:17:08.000000000 +0100
--- iperf-1.7.0-option-z/src/Locale.hpp	2002-01-01 21:52:52.000000000 +0100
***************
*** 153,158 ****
--- 153,159 ----
    -L, --listenport #       port to recieve bidirectional tests back on\n\
    -P, --parallel  #        number of parallel client threads to run\n\
    -T, --ttl       #        time-to-live, for multicast (default 1)\n\
+   -z, --no-multicast-loop #  disable emission of multicast packets to local sockets\n\
  \n\
  Miscellaneous:\n\
    -h, --help               print this message and quit\n\
diff -c3 -r iperf-1.7.0/src/PerfSocket.cpp iperf-1.7.0-option-z/src/PerfSocket.cpp
*** iperf-1.7.0/src/PerfSocket.cpp	2003-03-12 19:54:52.000000000 +0100
--- iperf-1.7.0-option-z/src/PerfSocket.cpp	2002-01-01 21:59:37.000000000 +0100
***************
*** 537,547 ****
          FAIL_errno( rc == SOCKET_ERROR, "setsockopt IP_TOS" );
      }
  #endif
  
      if ( ! mUDP ) {
          // set the TCP maximum segment size
          setsock_tcp_mss( mSock, mSettings->mMSS );
! 
  #ifdef TCP_NODELAY
  
          // set TCP nodelay option
--- 537,557 ----
          FAIL_errno( rc == SOCKET_ERROR, "setsockopt IP_TOS" );
      }
  #endif
+    if ( mUDP && mSettings->mNoMulticastLoop) {
+ 	int flag = 0;
+ 	int rc = setsockopt( mSock, IPPROTO_IP, IP_MULTICAST_LOOP,
+ 		(void*)&flag, sizeof(flag));
+         if(rc<0) {
+ 		FAIL_errno( rc == SOCKET_ERROR, "setsockopt IP_MULTICAST_LOOP = 0" );
+ 		exit(rc);
+         }
+    }
  
      if ( ! mUDP ) {
          // set the TCP maximum segment size
          setsock_tcp_mss( mSock, mSettings->mMSS );
! 	
  #ifdef TCP_NODELAY
  
          // set TCP nodelay option
diff -c3 -r iperf-1.7.0/src/Settings.cpp iperf-1.7.0-option-z/src/Settings.cpp
*** iperf-1.7.0/src/Settings.cpp	2003-03-03 22:17:08.000000000 +0100
--- iperf-1.7.0-option-z/src/Settings.cpp	2002-01-01 21:56:23.000000000 +0100
***************
*** 97,102 ****
--- 97,103 ----
  {"udp",              no_argument, NULL, 'u'},
  {"version",          no_argument, NULL, 'v'},
  {"window",     required_argument, NULL, 'w'},
+ {"no-multicast-loop", no_argument, NULL, 'z'},
  
  // more esoteric options
  {"bind",       required_argument, NULL, 'B'},
***************
*** 156,162 ****
  
  #define SHORT_OPTIONS()
  
! const char short_options[] = "b:c:df:hi:l:mn:o:p:rst:uvw:B:CDF:IL:M:NP:RS:T:VW";
  
  /* -------------------------------------------------------------------
   * defaults
--- 157,163 ----
  
  #define SHORT_OPTIONS()
  
! const char short_options[] = "b:c:df:hi:l:mn:o:p:rst:uvw:zB:CDF:IL:M:NP:RS:T:VW";
  
  /* -------------------------------------------------------------------
   * defaults
***************
*** 212,217 ****
--- 213,219 ----
      mExtSettings->mRemoveService = false;      // -R,
      mExtSettings->mTOS        = 0;             // -S,  ie. don't set type of service
      mExtSettings->mTTL        = 1;             // -T,  link-local TTL
+     mExtSettings->mNoMulticastLoop = false;    // -Z --no-multicast-loop
      mExtSettings->mDomain     = kMode_IPv4;    // -V,
      mExtSettings->mSuggestWin = false;         // -W,  Suggest the window size.
  
***************
*** 438,443 ****
--- 440,448 ----
                  printf( warn_window_small, mExtSettings->mTCPWin );
              }
              break;
+ 	case 'z': // No Multicast loopback
+ 		mExtSettings->mNoMulticastLoop = true;
+ 	    break;
  
              // more esoteric options
          case 'B': // specify bind address
diff -c3 -r iperf-1.7.0/src/Settings.hpp iperf-1.7.0-option-z/src/Settings.hpp
*** iperf-1.7.0/src/Settings.hpp	2003-02-27 23:35:24.000000000 +0100
--- iperf-1.7.0-option-z/src/Settings.hpp	2002-01-01 21:51:42.000000000 +0100
***************
*** 134,139 ****
--- 134,140 ----
      bool   mStdin;                  // -I
      bool   mStdout;                 // -o
      bool   mSuggestWin;             // -W
+     bool   mNoMulticastLoop;	      // -z
  };
  
  #define HEADER_VERSION1 0x80000000
***************
*** 340,345 ****
--- 341,350 ----
          return mExtSettings->mTCPWin;
      }
  
+     // -z
+     bool GetNoMulticastLoop( void ) const {
+ 	return mExtSettings->mNoMulticastLoop;
+     }
      // ---- more esoteric options
  
      // -B <host>


Other Mailing lists | Author Index | Date Index | Subject Index | Thread Index