@@ -182,7 +182,9 @@ func sendAsyncTCP4(listenHandler *ListenHandler, ip string, p *port.Port, pkgFla
182182
183183 hasSourceIp := listenHandler .SourceIp4 != nil
184184 var iface * net.Interface
185- if hasSourceIp {
185+ if hasSourceIp && listenHandler .SourceHW != nil {
186+ // NOTE(dwisiswant0): Only attempt to use ethernet framing if we have
187+ // both source IP and HW.
186188 itf , gateway , _ , err := PkgRouter .RouteWithSrc (listenHandler .SourceHW , listenHandler .SourceIp4 , ip4 .DstIP )
187189 if err != nil {
188190 gologger .Debug ().Msgf ("could not find route to host %s:%d: %s\n " , ip , p .Port , err )
@@ -202,15 +204,21 @@ func sendAsyncTCP4(listenHandler *ListenHandler, ip string, p *port.Port, pkgFla
202204 ip4 .SrcIP = listenHandler .SourceIp4
203205 iface = itf
204206 } else {
205- _ , _ , sourceIP , err := PkgRouter .Route (ip4 .DstIP )
206- if err != nil {
207- gologger .Debug ().Msgf ("could not find route to host %s:%d: %s\n " , ip , p .Port , err )
208- return
209- } else if sourceIP == nil {
210- gologger .Debug ().Msgf ("could not find correct source ipv4 for %s:%d\n " , ip , p .Port )
211- return
207+ if hasSourceIp {
208+ // NOTE(dwisiswant0): We have source IP but no HW, so use it
209+ // regular raw socket
210+ ip4 .SrcIP = listenHandler .SourceIp4
211+ } else {
212+ _ , _ , sourceIP , err := PkgRouter .Route (ip4 .DstIP )
213+ if err != nil {
214+ gologger .Debug ().Msgf ("could not find route to host %s:%d: %s\n " , ip , p .Port , err )
215+ return
216+ } else if sourceIP == nil {
217+ gologger .Debug ().Msgf ("could not find correct source ipv4 for %s:%d\n " , ip , p .Port )
218+ return
219+ }
220+ ip4 .SrcIP = sourceIP
212221 }
213- ip4 .SrcIP = sourceIP
214222 }
215223
216224 tcpOption := layers.TCPOption {
@@ -238,7 +246,7 @@ func sendAsyncTCP4(listenHandler *ListenHandler, ip string, p *port.Port, pkgFla
238246 gologger .Debug ().Msgf ("Can not set network layer for %s:%d port: %s\n " , ip , p .Port , err )
239247 }
240248
241- if hasSourceIp {
249+ if hasSourceIp && listenHandler . SourceHW != nil && iface != nil {
242250 err = sendWithHandler (ip , iface , & eth , & ip4 , & tcp )
243251 } else {
244252 err = sendWithConn (ip , listenHandler .TcpConn4 , & tcp )
0 commit comments