Користувальницькькі налаштування

Налаштування сайту


Сайдбар

Розділи

Загальний опис
Історія змін
Рекомендації до оновлення
Плани на майбутнє
Відомі проблеми
Онлайн демо
Допомога проекту
Люди
Трохи про безпеку

FAQ



Редагувати сайдбар

option82

Це стара версія документу!


Mini FAQ

Q: Что требуется от свича, чтобы заработала option 82?
A: Иметь настроенный и работающий dhcp relay с включенной option 82, dhcp snooping не пропускающий клиентские запросы в обход рилея и ip source guard дропающий пакеты для айпишек не полученных сквозь рилей.

Q: На каких свичах должен быть рилей?
A: На всех - уровня доступа.

Q: У нас тут пол сети на мыльницах, это будет работать? А можно держать часть сети на IP+MAC и другую часть на option 82?
A: Произошла критическая ошибка - у вас недостаточно денег для использования этого функционала.

Настройка Ubilling и DHCP option 82

Для того, чтобы все заработало в базовом варианте, нам потребуется выполнить шесть простых шагов:

1. Подсеть пользователей добавлена как:

ID Начальная ІР Последняя ІР Сеть/CIDR Тип сети
1 172.16.0.0 172.16.0.255 172.16.0.0/24 dhcp82

2. /etc/rc.conf выглядит следующим образом

rc.conf
ifconfig_em0="inet 172.16.0.1 netmask 255.255.255.0"
ifconfig_em0_alias0="inet 172.32.0.1 netmask 255.255.240.0"
ifconfig_em0_alias1="inet 192.168.94.1 netmask 255.255.255.0"

3. Шаблон config/dhcp/global.template

global.template
option domain-name "ourisp";
option domain-name-servers 172.16.0.1;
default-lease-time 3600;
max-lease-time 43200;
authoritative;
ddns-update-style none;
log-facility local7;
one-lease-per-client true;
deny duplicates;
 
shared-network ourisp {
 
{SUBNETS}
 
subnet 192.168.94.0 netmask 255.255.255.0 {
}
 
subnet 172.32.0.0 netmask 255.255.240.0 {
  default-lease-time 3600;
  option domain-name "isp";
  option subnet-mask 255.255.240.0;
  option domain-name-servers 172.32.0.1;
  option routers 172.32.0.1;
 
  pool {
   range 172.32.0.100 172.32.0.254;
    {DENYMEMBERS}
   }
 
log(info, "==");
if exists agent.remote-id and exists agent.circuit-id {
if binary-to-ascii(16, 8, "", substring(option agent.remote-id, 2, 1)) = "0" {
set switch-mac = concat("0", binary-to-ascii(16, 8, "", substring(option agent.remote-id, 2, 1)), ":", binary-to-ascii(16, 8, ":", substring(option agent.remote-id, 3, 6)));
# log(info,concat("SWITCH-MAC1:",switch-mac));
} else {
# set switch-mac = binary-to-ascii(16, 8, ":", substring(option agent.remote-id, 2, 6));
# log(info,concat("SWITCH-MAC2:",switch-mac));
set switch-mac = concat (
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(option agent.remote-id,2,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(option agent.remote-id,3,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(option agent.remote-id,4,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(option agent.remote-id,5,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(option agent.remote-id,6,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(option agent.remote-id,7,1))),2)
);
# log(info,concat("SWITCH-MAC3:",switch-mac3));
}
set clip = binary-to-ascii(10,8,".",leased-address);
set clremote = binary-to-ascii(16,8,"",option agent.remote-id);
set clcircuit = binary-to-ascii(10,8,"",option agent.circuit-id);
set switch-port = binary-to-ascii(10, 8, "", substring(option agent.circuit-id, 5, 1));
set switch-port-vlan = binary-to-ascii(10, 16, "", substring(option agent.circuit-id, 2, 2));
 
log( info,concat("OPTION82 INFO - SWITCHMAC: ",switch-mac," PORTSW: ",switch-port," VLAN: ",switch-port-vlan));
 
log( info,concat("*Leased IP: ",clip, " SWITCH: ",clremote," PORT: ",clcircuit," SWITCHMAC: ",switch-mac," PORTSW: ",switch-port," VLAN: ",switch-port-vlan," (with opt82)") );
} else {
set clhw = concat (
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,1,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,2,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,3,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,4,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,5,1))),2), ":",
suffix (concat ("0", binary-to-ascii (16, 8, "", substring(hardware,6,1))),2)
);
 
log( info,concat("*Leased IP: ",binary-to-ascii(10,8,".",leased-address), " MAC: ", clhw," (without opt82)") );
}
log(info, "==");
 
}
 
}

4. Шаблон config/dhcp/option82.template находиться в дефолтном состоянии (поддерживаемые макросы)

5. В конфиге alter.ini установлена опция NMLEASES = /var/log/dhcpd.log и настроено правильное логирование ISP-DHCPD

6. В OnConnect отключена прибивка по MAC-у. Теперь это проблема ip source guard и dhcp snooping вашего свича (192.168.94.4 в примере).

Исходя из всего вышеуказанного, не сложно заключить, что привязка планируется по паре полных remote-id/circuit-id. Проверить поведение такого конфига не сложно при помощи следующих нехитрых телодвижений

Отладка scapy

p="\x01\x01\x05\x02\x06\x11\x22\x34\x44\x55\x66"
dhcp_discover =  Ether(src=RandMAC(),dst="ff:ff:ff:ff:ff:ff")/IP(src="0.0.0.0",dst="255.255.255.255")/UDP(sport=68,dport=67)/BOOTP(chaddr=RandString(12,'0123456789abcdef'))/DHCP(options=[("message-type","discover"),("relay_agent_Information",p),"end"])
sendp(dhcp_discover)

в ответ на что мы должны получить что-то типа:

dhcpd.log
Oct 15 00:38:20 test dhcpd: Wrote 0 class decls to leases file.
Oct 15 00:38:20 test dhcpd: Wrote 1 leases to leases file.
Oct 15 00:38:34 test dhcpd: ==
Oct 15 00:38:34 test dhcpd: *Leased IP: 172.16.0.2 SWITCH: 112234445566 PORT: 5 (with opt82)
Oct 15 00:38:34 test dhcpd: ==
Oct 15 00:38:34 test dhcpd: ==
Oct 15 00:38:34 test dhcpd: *Leased IP: 172.16.0.2 SWITCH: 112234445566 PORT: 5 (with opt82)
Oct 15 00:38:34 test dhcpd: ==
Oct 15 00:38:34 test dhcpd: DHCPDISCOVER from 30:32:63:30:35:62 via em0
Oct 15 00:38:35 test dhcpd: DHCPOFFER on 172.16.0.2 to 30:32:63:30:35:62 via em0

а также при прослушивании при помощи

tcpdump -n -i em0 -s 0 -v -vv

мы будем наблюдать прилетающие к нам

Agent-Information Option 82, length 13: 
              Remote-ID........
	      Circuit-ID.......

Особенности работы на свитчах Zyxel

GS-4012, GS-3012 вообще не возвращают remote-id. Поэтому ориентироваться стоит только sub-option 1 (Agent Circuit ID). Так что при построении шаблона требуется руководствоваться вот этим: http://zyxel.ru/kb/2030

В черновом варианте можно оформить это примерно так:

    set clremote = binary-to-ascii(10,16,"",substring(option agent.circuit-id,4,2));
    set clcircuit = binary-to-ascii(10,16,"",substring(option agent.circuit-id,1,2));

а также исправить option82.template в соответствии с этими реалиями

что в результате дает нам следующий лог

Oct 15 16:52:00 test dhcpd: ==
Oct 15 16:52:00 test dhcpd: *Leased IP: 172.32.0.100 SWITCH: 18259 PORT: 768 (with opt82)
Oct 15 16:52:00 test dhcpd: ==

Пример конфигурации Zyxel GS-3012:

ip address inband-default 192.168.94.4 255.255.255.0 
ip address default-gateway 192.168.94.1
interface port-channel 12  
  dhcp snooping trust 
exit 
dhcp smart-relay 
dhcp smart-relay helper-address 192.168.94.1 
dhcp smart-relay option 
dhcp smart-relay information 
dhcp snooping 
dhcp snooping vlan 1  
dhcp snooping vlan 1 option 
dhcp snooping vlan 1 information 
dhcp dhcp-vlan 1 

Упрощение жизни

Для более удобного вылавливания пар remote-id и circuit-id существует сервис аналогичный UHW находящийся в docs/opt82_uhw. Настройка в основном аналогична таковой у оригинального сервиса. Ходят слухи, что грозились дописать еще и самостоятельную активацию абонентом ;)

option82.1665063468.txt.gz · Востаннє змінено: 2022/10/06 16:37 повз pautina