Category Archives: 谈编程

RFC3580关于802.1x端口vlan分配的描述

备忘,摘录自rfc3808第14页
Tunnel Attributes
   Reference [RFC2868] defines RADIUS tunnel attributes used for
   authentication and authorization, and [RFC2867] defines tunnel
   attributes used for accounting.  Where the IEEE 802.1X Authenticator
   supports tunneling, a compulsory tunnel may be set up for the
   Supplicant as a result of the authentication.
   In particular, it may be desirable to allow a port to [...]

dhcp option82包解析小记(之二)

接昨天的dhcp option82 包解析小记 (之一)
解析的原理很简单。
接到dhcp包以后,使用指针跳转到option82的value部分的地址,因为dhcp header是定长的,而option是变长的,因此此过程需要使用遍历,方法很多,不管使用什么方法,找到option82后,得到地址,然后使用强之类型转换转为我们预定义好的结构,然后取出我们所需要的值并传给处理函数。
option 82结构 (思科),参考文档:switch 2950 Configuring DHCP Features
struct dhcp_cisco_option82
{
u_int8_t subop1_type; /*sub option 1:type */
u_int8_t subop1_length; /*sub option 1: length*/
u_int8_t circuit_id;
u_int8_t circuit_length;
u_int16_t vlan;
u_int8_t module;
u_int8_t port;
u_int8_t subop21_type; /*sub option 2:type */
u_int8_t subop2_length; /*sub option 2: length*/
u_int8_t remote_id;
u_int8_t remote_length;
u_int8_t mac[6];
};
类型转换和取值:
char switchmac[20] = {0},vlan[8] = {0},port[12] = {0};
if(info->op82rai)
{
struct dhcp_cisco_option82 *op82 = (dhcp_cisco_option82 *)(info->op82rai);
format(op82->mac,switchmac,0 );
sprintf(vlan,”%u”,ntohs(op82->vlan));
sprintf(port,”%u/%u”,op82->module,(op82->port+1));
}
注:info->op82rai 是指向 [...]

dhcp option82包解析小记(之一)

已经忙了将近两个星期的dhcp 包解析,整个过程中option 82包的解析费掉的时间最多,因为我花了很久才抓到这个包,之前的开发过程没有写过日志,option82包的解析,我决定写点东西,一为备忘,二为纪念我的08年阳历年。
option82包是dhcp包option部分的一项,具体内容可以参考rfc3046。
这个包里面包括了交换机、dhcp客户端所在vlan以及端口号 ,这些信息对于某些应用是非常重要的。
本文的重点是如何让交换机启动填充option82。
1、交换机配置(2950)
configure terminal
ip dhcp snooping
ip dhcp snooping vlan 1
ip dhcp snooping information option
以上为交换机全局配置,接着配置dhcp server所连接的接口,这里是2
interface f0/2
设置该接口为信任接口
p dhcp snooping trust
ip dhcp snooping limit rate 1000
end
show running-config
copy running-config startup-config
show ip dhcp snooping
确保 dhcp客户端所连接接口是un trust的,否则交换机不会填充option82.
交换机上配置结束
2、配置dhcpd.
vim /etc/dhcpd.conf
看到内容如下:
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
#

ok,我们来打开/usr/share/doc/dhcp*/dhcpd.conf.sample,内容是:

ddns-update-style interim;
ignore client-updates;
subnet 192.168.0.0 netmask 255.255.255.0 {
# — default [...]