Skip to content

Commit

Permalink
Merge pull request #24 from trema/feature/fix_vhost_exit
Browse files Browse the repository at this point in the history
vhost should not exit if the link to which the vhost is connected is disabled.
  • Loading branch information
yasuhito committed Jun 4, 2015
2 parents b793a20 + aeec534 commit 7bbd98d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
## develop (unreleased)


## 0.6.4 (6/4/2015)
### Bugs fixed
* [#24](https://github.com/trema/phut/pull/24): vhost should not exit
if the link to which the vhost is connected is disabled.


## 0.6.3 (6/4/2015)
### Bugs fixed
* [#23](https://github.com/trema/phut/pull/23): Fix vhost restart failure.
Expand Down
22 changes: 16 additions & 6 deletions lib/phut/vhost_daemon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def lookup_arp_table(ip_address)
def write_to_raw_socket(packet)
@packets_sent << packet.snapshot
raw_socket.write packet.to_binary_s
rescue Errno::ENXIO
# link is disconnected
true
end

def create_udp_packet(dest)
Expand All @@ -81,17 +84,24 @@ def log_file
"#{@options.fetch(:log_dir)}/vhost.#{@options.fetch(:name)}.log"
end

# rubocop:disable MethodLength
def read_loop
loop do
raw_data, = raw_socket.recvfrom(8192)
udp = Pio::Udp.read(raw_data)
unless @options[:promisc]
next if udp.ip_destination_address != @options.fetch(:ip_address)
begin
raw_data, = raw_socket.recvfrom(8192)
udp = Pio::Udp.read(raw_data)
unless @options[:promisc]
next if udp.ip_destination_address != @options.fetch(:ip_address)
end
@logger.info "Received: #{udp}"
@packets_received << udp.snapshot
rescue Errno::ENETDOWN
# link is disconnected
sleep 1
end
@logger.info "Received: #{udp}"
@packets_received << udp.snapshot
end
end
# rubocop:enable MethodLength

def start_daemon
Process.daemon
Expand Down

0 comments on commit 7bbd98d

Please sign in to comment.