Quais são as definições de addrtype no iptables?

10

Eu estou interessado em usar o addrtype em combinação com o -src como regra em uma das minhas cadeias de filtros, assim, para remover alguns bogons ips:

-A INPUT -p tcp --dport 80 -m addrtype --src-type UNICAST ! -s 127.0.0.0/8 -j WEB

A página man diz o seguinte

addrtype
This module matches packets based on their address type. Address types are used within the kernel networking stack and categorize addresses into various groups. The exact definition of that group depends on the specific layer three protocol.

The following address types are possible:

  • UNSPEC an unspecified address (i.e. 0.0.0.0)
  • UNICAST an unicast address
  • LOCAL a local address
  • BROADCAST a broadcast address
  • ANYCAST an anycast packet
  • MULTICAST a multicast address
  • BLACKHOLE a blackhole address
  • UNREACHABLE an unreachable address
  • PROHIBIT a prohibited address
  • THROW FIXME
  • NAT FIXME
  • XRESOLVE

Não está claro quais são as definições exatas e diz que isso depende do protocolo específico da camada 3. Isso é o que eu penso:

  • UNICAST (! BROADCAST,! MULTICAST,! ANYCAST)
  • LOCAL ( 127.0.0.0/8 )
  • BROADCAST ( *.*.*.255 )
  • ANYCAST ( *.*.*.* )
  • MULTICAST ( 224.0.0.0/4 )

Alguém tem uma ideia clara do que isso significa e como é implementado pelo iptables (por exemplo, como ele sabe onde diabos está o BLACKHOLE)?

    
por Question Overflow 18.05.2014 / 09:56

1 resposta

3

Eu acho que depende de você fazer o kernel saber qual é o tipo de endereço blackhole.

Do arquivo xt_addrtype.h no código-fonte do iptables, você pode ver :

/* rtn_type enum values from rtnetlink.h, but shifted */                        
enum {                                                                          
    XT_ADDRTYPE_UNSPEC = 1 << 0,                                                
    XT_ADDRTYPE_UNICAST = 1 << 1,   /* 1 << RTN_UNICAST */                      
    XT_ADDRTYPE_LOCAL  = 1 << 2,    /* 1 << RTN_LOCAL, etc */                   
    XT_ADDRTYPE_BROADCAST = 1 << 3,                                             
    XT_ADDRTYPE_ANYCAST = 1 << 4,                                               
    XT_ADDRTYPE_MULTICAST = 1 << 5,                                             
    XT_ADDRTYPE_BLACKHOLE = 1 << 6,                                             
    XT_ADDRTYPE_UNREACHABLE = 1 << 7,                                           
    XT_ADDRTYPE_PROHIBIT = 1 << 8,                                              
    XT_ADDRTYPE_THROW = 1 << 9,                                                 
    XT_ADDRTYPE_NAT = 1 << 10,                                                  
    XT_ADDRTYPE_XRESOLVE = 1 << 11,                                             
};

E em rtnetlink.h , você verá a mesma definição:

enum {                                                                          
    RTN_UNSPEC,                                                                 
    RTN_UNICAST,        /* Gateway or direct route  */                          
    RTN_LOCAL,      /* Accept locally       */                                  
    RTN_BROADCAST,      /* Accept locally as broadcast,                         
                   send as broadcast */                                         
    RTN_ANYCAST,        /* Accept locally as broadcast,                         
                   but send as unicast */                                       
    RTN_MULTICAST,      /* Multicast route      */                              
    RTN_BLACKHOLE,      /* Drop             */                                  
    RTN_UNREACHABLE,    /* Destination is unreachable   */                      
    RTN_PROHIBIT,       /* Administratively prohibited  */                      
    RTN_THROW,      /* Not in this table        */                              
    RTN_NAT,        /* Translate this address   */                              
    RTN_XRESOLVE,       /* Use external resolver    */                          
    __RTN_MAX                                                                   
};

Você pode ver iptables usar a mesma definição de tipo de endereço com a pilha de rede do kernel tcp.

Em seguida, de man ip :

Route types:

      unicast - the route entry describes real paths to the destinations covered by the route prefix.

      unreachable  - these destinations are unreachable.  Packets are discarded and the ICMP message host unreachable is generated.
               The local senders get an EHOSTUNREACH error.

      blackhole - these destinations are unreachable.  Packets are discarded silently.  The local senders get an EINVAL error.

      prohibit - these destinations are unreachable.  Packets are discarded and the  ICMP  message  communication  administratively
               prohibited is generated.  The local senders get an EACCES error.

      local - the destinations are assigned to this host.  The packets are looped back and delivered locally.

      broadcast - the destinations are broadcast addresses.  The packets are sent as link broadcasts.

      throw  - a special control route used together with policy rules. If such a route is selected, lookup in this table is termi‐
               nated pretending that no route was found.  Without policy routing it is equivalent to the absence of the route in the routing
               table.   The  packets  are  dropped  and the ICMP message net unreachable is generated.  The local senders get an ENETUNREACH
               error.

      nat - a special NAT route.  Destinations covered by the prefix are considered to  be  dummy  (or  external)  addresses  which
               require  translation  to  real  (or  internal)  ones  before forwarding.  The addresses to translate to are selected with the
               attribute Warning: Route NAT is no longer supported in Linux 2.6.

               via.

      anycast - not implemented the destinations are anycast addresses assigned to this host.  They are mainly equivalent to  local
               with one difference: such addresses are invalid when used as the source address of any packet.

      multicast - a special type used for multicast routing.  It is not present in normal routing tables.

Então, quando você define uma rota para uma rede pelo comando ip e a marca como uma rota blackhole, o kernel agora faz esse tipo de blackhole de endereço de rede:

ip route add blackhole X.X.X.X/24
    
por 18.05.2014 / 17:47

Tags