Watchdog源码--neighboursPacketDetected

邻居包检测与转发机制
本文详细解析了一种网络中邻居包的检测与转发机制,包括如何处理邻居发送的包,判断是否需要转发,以及如何将包添加到等待转发列表,并从列表中删除已转发的包。涉及的主要操作包括检测包、判断包是否有趣、判断是否需要转发、将包添加到邻居转发列表以及从列表中移除已转发的包。
/**
* A packet from a neighbour has been detected.
*/
void
WATCHDOG::neighboursPacketDetected(int32_t source_ip, int32_t destination_ip, int source_mac, int destination_mac, int sourcePort, int destinationPort, char * tmp_data, packet_t packet_type, double pktime) {
if (debug > 2) printf("NeighbourPacket\n");
neighbour *neigh_src, *neigh_dst;
int data_size;

data_size = strlen(tmp_data);
protocol = packet_type;

neigh_src = neigs->ExistNeighbourMac(source_mac);
neigh_dst = neigs->ExistNeighbourMac(destination_mac);

if (isInterestingPacket(source_ip, source_mac, destination_ip, destination_mac)) {
/* If the destination IP is different of the destination neighbour, means that must be forwarded */
if (neigh_dst != NULL && (neigh_dst->ip != 666) && (destination_ip != neigh_dst->ip)) {
neigs->ShowAllNeighbours();
waitingForwardPacket(source_ip, destination_ip, sourcePort, destinationPort, tmp_data, data_size, neigh_dst, protocol, pktime);
}else{
if(destination_mac!=ownMAC){
neigs->ShowAllNeighbours();
}
}
/* If the IP source is different of the sender, means that is a forwarded packet */
if ((neigh_src != NULL) && (neigh_src->ip != 666)){
if (debug > 2) printf("Sender: %d Hop: %d Destination: %d\n", source_mac, neigh_src->mac, destination_ip);
if (source_ip != neigh_src->ip) {
packetForwarded(destination_ip, source_ip, tmp_data, data_size, neigh_src, protocol, pktime);
}}
}
}
/**
* A packet has been forwarded, delete it from the waiting forward list.
*/
void
WATCHDOG::packetForwarded(int32_t destination_ip, int32_t source_ip, char *body, int data_size, neighbour *neigh, int protocol, double pktime) {
if (debug > 2) printf("packetForwarded\n");
if (neigh != NULL) {
neigs->AddNeighbourPacketForwarded(neigh, body, destination_ip, source_ip, data_size, storing_packet_timeout, protocol, pktime);
}
}
 * Add a packet to a neighbour not forwarded yet.
*/
void
NEIGHBOURS::AddNeighbourPacketForwarded(neighbour *neig, char *body, int32_t ip_dst, int32_t ip_src, int data_size, int storing_time, int protocol, double pktime) {
neig->time = pktime;
neig->pckts->AddPacketForwarded(body, ip_dst, ip_src, data_size, storing_time, protocol, pktime);
}
/**
* Indicates that a new packet forwarded has been listened.
*/
void
PACKETS::AddPacketForwarded( char *body, int32_t ip_dst, int32_t ip_src, int data_size, int storing_time, int protocol, double pktime) {
packet * exists;
exists = ExistsPacket(body, ip_dst, ip_src, data_size, storing_time, protocol, pktime);
if (exists != NULL) {
pckts->forwarded_packets[protocol]++;
RemovePacket(exists, protocol);
}
}

 

/**
* Delete a stored packet.
*/
void
PACKETS::RemovePacket( packet *pk, int protocol) {
packet *next, *prev;
if (pk != NULL) {
next = pk->next;
prev = pk->previous;

/* is the first packet */
if (pk == pckts->packets[protocol]) {
pckts->packets[protocol] = pk->next;
}

/* is the last packet */
if (pk == pckts->last_packet[protocol]) {
pckts->last_packet[protocol] = pk->previous;
}

if (next != NULL) next->previous = prev;
if (prev != NULL) prev->next = next;

pckts->stored_packets--;
pckts->stored_packets_protocol[protocol] = pckts->stored_packets_protocol[protocol] - (1 / pk->devalue);
DeletePacket(pk);
pk = NULL;

} else {
printf("This packet does not exists!\n");
}
}





转载于:https://www.cnblogs.com/zhangrui/archive/2012/03/08/2385236.html

<think>我们正在讨论BIOS Watchdog Controller(看门狗控制器)设置为Disabled的相关信息。用户之前已经了解了看门狗控制器的工作原理和启用方法,现在想了解将其禁用的作用、影响以及如何设置。 首先,我们需要明确:禁用看门狗控制器意味着什么? - 看门狗控制器是一个硬件计时器,用于监控系统运行状态。如果系统在一定时间内没有“喂狗”(即重置计数器),则看门狗会触发系统复位或中断,以尝试恢复系统。 - 设置为Disabled,就是关闭这个监控功能。 作用: 1. 避免意外的系统复位:在某些调试场景中,开发者可能不希望系统因为未能及时喂狗而复位,禁用看门狗可以防止这种干扰。 2. 降低功耗:虽然看门狗控制器功耗很小(通常只有几毫瓦),但在极端节能的需求下,禁用它可以节省一点点电力。 3. 解决兼容性问题:极少数情况下,看门狗可能与某些硬件或软件不兼容,禁用可以避免由此引起的系统不稳定。 影响: 1. 系统失去自动恢复能力:如果系统出现死锁或挂起,看门狗将不会触发复位,需要人工干预才能恢复。 2. 对于关键应用环境(如工业控制、服务器)禁用看门狗会降低系统的可靠性,因为系统无法自动从故障中恢复。 3. 在一些安全认证要求中(如ISO 26262中的汽车电子),看门狗是必须启用的,禁用可能导致不符合安全标准。 设置方法: 通常在BIOS/UEFI设置界面中操作: 1. 开机时进入BIOS Setup(通常按Delete、F2或F12键,具体取决于主板) 2. 找到“Advanced”(高级)菜单 3. 寻找“Watchdog Timer”、“Watchdog Controller”或类似名称的选项 4. 将其设置为“Disabled” 也可以通过编程方式禁用(但需要谨慎,通常在固件开发中使用): 例如,通过写入特定的寄存器(以Intel PCH为例): - 访问配置空间(端口0xCF8, 0xCFC) - 找到看门狗控制寄存器(如前面提到的0x44地址) - 清除使能位(Bit0) 在操作系统层面(如Linux),如果之前启用了看门狗驱动,可以通过卸载驱动来停止喂狗,但这不是禁用控制器本身,只是停止使用。要完全禁用硬件功能,必须在BIOS中设置。 注意事项: 1. 在服务器环境中,通常不建议禁用,因为看门狗是系统高可用性的重要组成部分。 2. 禁用看门狗后,如果系统需要长时间无人值守运行,可靠性会降低。 相关问题: 1. 在哪些情况下应该禁用BIOS Watchdog Controller? 2. 禁用BIOS Watchdog Controller后,是否还能通过其他方式监控系统状态? 3. 如何在Windows系统中检查BIOS Watchdog Controller的状态? 根据以上思路,组织回答: </think>### BIOS Watchdog Controller 设置为 Disabled 详解 #### 一、禁用作用与影响 **核心作用**: 当设置为 Disabled 时,BIOS Watchdog Controller 将**完全停止监控功能**,系统失去自动故障恢复能力: $$ \text{禁用状态} = \text{关闭计数器} + \text{阻断复位信号} $$ **主要影响**: | 场景 | 启用状态响应 | 禁用状态风险 | |---------------------|---------------------------|---------------------------| | 系统死锁 | 自动硬复位(<90秒) | 需人工干预重启 | | 进程崩溃 | 触发NMI中断[^1] | 进程持续阻塞 | | 固件故障 | 切换备份固件 | 系统完全瘫痪 | | 持续高负载 | 维持稳定性 | 可能过热关机 | **典型禁用场景**: 1. **开发调试阶段**:避免看门狗意外复位干扰断点调试 2. **功耗敏感设备**:节能需求(省去$ \approx 5\text{mW} $功耗) 3. **兼容性测试**:排除看门狗与特定硬件的冲突 #### 二、设置方法 ##### 1. BIOS/UEFI 设置界面 ```plaintext 进入路径: BIOS Setup → Advanced → Chipset Configuration → Watchdog Timer Configuration → [Enabled/Disabled] ``` **操作步骤**: 1. 重启按 `Del/F2` 进入 BIOS 2. 找到 watchdog 相关选项(名称可能为 `WDT`/`ASF Watchdog`) 3. 设置为 **Disabled** 4. 按 F10 保存退出 ##### 2. 寄存器级禁用(开发人员) ```c // Intel PCH 示例(通过端口 0xCF8/0xCFC) outl(0x8000F844, 0xCF8); // 定位控制寄存器 uint32_t ctrl = inl(0xCFC); ctrl &= ~0x01; // 清除使能位(Bit0) outl(ctrl, 0xCFC); // 写入禁用指令 ``` ⚠️ **风险提示**:寄存器操作错误可能导致系统不稳定[^2] ##### 3. 操作系统层联动 禁用 BIOS watchdog 后需同步关闭 OS 层驱动: ```bash # Linux 系统 sudo systemctl stop watchdog.service sudo rmmod iTCO_wdt # 卸载驱动 ``` #### 三、禁用后的替代监控方案 | 监控类型 | 实现方式 | 恢复能力对比 | |---------------|--------------------------|------------------| | 软件看门狗 | systemd-watchdog (Linux) | 仅用户空间复位 | | BMC 监控 | IPMI 健康检测 | 完整硬件级复位 | | 双机热备 | 集群心跳检测 | 业务级切换 | ```mermaid graph LR A[系统故障] --> B{Watchdog状态} B -->|Enabled| C[自动恢复] B -->|Disabled| D[人工干预] --> E[BMC强制重启] D --> F[电源循环复位] ``` #### 四、关键注意事项 1. **安全认证影响** - 工业/车载系统禁用后不符合 IEC 61508/ISO 26262 要求 - 服务器领域违反 IPMI 2.0 规范[^3] 2. **特殊场景风险** - 无显示器设备(工业HMI)死锁后无法人工复位 - 数据中心远程管理失效概率提升: $$ P_{\text{故障}} = 1 - (1 - \lambda)^t \quad (\lambda \uparrow \text{当禁用时}) $$ 3. **启用建议** ```diff + 生产环境/关键业务系统必须启用 - 开发环境可临时禁用(调试后需恢复) ``` --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值