Compare commits
1 Commits
master
...
28f5022603
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28f5022603 |
@@ -41,6 +41,31 @@ func NewServer() (*Server, error) {
|
||||
return &Server{}, nil
|
||||
}
|
||||
|
||||
func (s *Server) UpdateDNS(b []byte) error {
|
||||
m,err := ndp.ParseMessage(b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if m.Type() != ipv6.ICMPTypeNeighborAdvertisement {
|
||||
return fmt.Errorf("incorrect icmp message recieved expected %s, got %s", ipv6.ICMPTypeNeighborAdvertisement, m.Type())
|
||||
}
|
||||
n :=m.(*ndp.NeighborAdvertisement)
|
||||
var hw net.HardwareAddr
|
||||
for _,o := range n.Options {
|
||||
if o.Code() == uint8(ndp.Target) {
|
||||
ll := o.(*ndp.LinkLayerAddress)
|
||||
hw = ll.Addr
|
||||
break
|
||||
}
|
||||
}
|
||||
if hw == nil || !n.TargetAddress.IsGlobalUnicast() || !n.Solicited {
|
||||
// Ignore advertisements that donot provide the MAC, are not solicited and are not global unicast addresses
|
||||
return nil
|
||||
}
|
||||
log.Printf("found IPv6 address %s for MAC address %s", n.TargetAddress, hw)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) SetPrefixes(prefixes []net.IPNet) {
|
||||
s.mu.Lock()
|
||||
if s.ifname != "" {
|
||||
@@ -75,6 +100,7 @@ func (s *Server) Serve(ifname string, conn net.PacketConn) error {
|
||||
var filter ipv6.ICMPFilter
|
||||
filter.SetAll(true)
|
||||
filter.Accept(ipv6.ICMPTypeRouterSolicitation)
|
||||
filter.Accept(ipv6.ICMPTypeNeighborAdvertisement)
|
||||
if err := s.pc.SetICMPFilter(&filter); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -101,6 +127,9 @@ func (s *Server) Serve(ifname string, conn net.PacketConn) error {
|
||||
// TODO: isn’t this guaranteed by the filter above?
|
||||
if n == 0 ||
|
||||
ipv6.ICMPType(buf[0]) != ipv6.ICMPTypeRouterSolicitation {
|
||||
if ipv6.ICMPType(buf[0]) == ipv6.ICMPTypeNeighborAdvertisement{
|
||||
s.UpdateDNS(buf)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err := s.sendAdvertisement(addr); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user