Skip to content

Commit

Permalink
Update arp cache for own-address-probes.
Browse files Browse the repository at this point in the history
  • Loading branch information
archaelus committed Mar 10, 2013
1 parent f242019 commit 46f7921
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/enet_arp_responder.erl
Expand Up @@ -111,8 +111,8 @@ handle_cast(Msg, State) ->
handle_info({enet, IF, {RX, _Frame, Pkt = #eth{type=arp}}}, State) handle_info({enet, IF, {RX, _Frame, Pkt = #eth{type=arp}}}, State)
when RX =:= rx; when RX =:= rx;
RX =:= promisc_rx -> RX =:= promisc_rx ->
handle_arp_rx(IF, Pkt, State), NewState = handle_arp_rx(IF, Pkt, State),
{noreply, State}; {noreply, NewState};




handle_info(Info, State) -> handle_info(Info, State) ->
Expand All @@ -139,35 +139,40 @@ handle_arp_rx(IF, #eth{type=arp,data=Pkt}, State) ->
handle_arp_request(IF, Q, State); handle_arp_request(IF, Q, State);
_ -> _ ->
?INFO("Ignoring arp:~n~p", [Pkt]), ?INFO("Ignoring arp:~n~p", [Pkt]),
ignore State
catch catch
Class:Error -> Class:Error ->
?WARN("~p:~p while decoding~n~p~nStack:~p", ?WARN("~p:~p while decoding~n~p~nStack:~p",
[Class, Error, Pkt, erlang:get_stacktrace()]), [Class, Error, Pkt, erlang:get_stacktrace()]),
%% XXX - couldn't decode Pkt, Type:Error. %% XXX - couldn't decode Pkt, Type:Error.
ignore State
end. end.


handle_arp_request({enet_eth_iface, IF}, handle_arp_request({enet_eth_iface, IF},
#arp{htype = ethernet, #arp{htype = ethernet,
ptype = ipv4, ptype = ipv4,
op = request, op = request,
sender = Sender = {SMac, _SAddr}, sender = Sender = {SMac, SAddr},
target = {_TMac, TAddr}}, target = {_TMac, TAddr}},
#state{cache = Cache}) -> State = #state{cache = Cache}) ->
case enet_arp_cache:lookup_ip_addr(TAddr, Cache) of case enet_arp_cache:lookup_ip_addr(TAddr, Cache) of
not_found -> ignore;
#entry{publish = false} -> ignore;
#entry{publish = true, #entry{publish = true,
ethaddr = CMac, ethaddr = CMac,
ipaddr = CAddr} -> ipaddr = TAddr} ->
R = #arp{op = reply, R = #arp{op = reply,
htype = ethernet, htype = ethernet,
ptype = ipv4, ptype = ipv4,
sender = {CMac, CAddr}, sender = {CMac, TAddr},
target = Sender target = Sender
}, },
Reply = #eth{dst=SMac, type=arp, Reply = #eth{dst=SMac, type=arp,
data=enet_codec:encode(arp, R, [])}, data=enet_codec:encode(arp, R, [])},
enet_eth_iface:send(IF, Reply) enet_eth_iface:send(IF, Reply),
State#state{cache = Cache};
_ when SAddr =:= TAddr ->
%% They're advertising themselves, so learn anyway. YOLO.
NewCache = enet_arp_cache:learn(SMac, SAddr, Cache),
State#state{cache = NewCache};
_ ->
State
end. end.

0 comments on commit 46f7921

Please sign in to comment.