• Monthly Archives: 11月 2023

在OpenWRT中使用USB网卡桥接Wlan及Lan网络时偶现“br-lan: reveived packet on eth0 with own address as source address”的错误提示

使用以下命令查看网络端口的相关信息:

ip addr

然后返回如下信息:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq master br-lan state DOWN group default qlen 1000
    link/ether e4:5f:01:16:9b:b3 brd ff:ff:ff:ff:ff:ff
3: gre0@NONE: <NOARP> mtu 1476 qdisc noop state DOWN group default qlen 1000
    link/gre 0.0.0.0 brd 0.0.0.0
4: gretap0@NONE: <BROADCAST,MULTICAST> mtu 1462 qdisc noop state DOWN group default qlen 1000
    link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
5: erspan0@NONE: <BROADCAST,MULTICAST> mtu 1450 qdisc noop state DOWN group default qlen 1000
    link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
7: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br-lan state UP group default qlen 1000
    link/ether e4:5f:01:16:9b:b4 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::e65f:1ff:fe16:9bb4/64 scope link
       valid_lft forever preferred_lft forever
17: br-lan: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether e4:5f:01:16:9b:b3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.1/24 brd 192.168.1.255 scope global br-lan
       valid_lft forever preferred_lft forever
    inet6 fe80::e65f:1ff:fe16:9bb5/64 scope link
       valid_lft forever preferred_lft forever
54: usb0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br-SIM7600G state UNKNOWN group default qlen 1000
    link/ether b6:09:ba:f2:6a:1f brd ff:ff:ff:ff:ff:ff
55: br-SIM7600G: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether b6:09:ba:f2:6a:1f brd ff:ff:ff:ff:ff:ff
    inet 192.168.225.54/24 brd 192.168.225.255 scope global br-SIM7600G
       valid_lft forever preferred_lft forever
    inet6 fe80::b409:baff:fef2:6a1f/64 scope link
       valid_lft forever preferred_lft forever

由上述信息可以看到,ip信息中的br-lan和eth0的mac地址一样的,分析原因可能是由于安装好OpenWRT并配置完USB网卡的桥接网络《br-lan》时,br-lan的mac地址默认可能会出现和其他网络端口的mac地址一样的情况。

因此,我们只需要更改其br-lan的mac地址即可解决这个问题。

登录OpenWRT的管理界面,找到如下位置:

如上图所示,我讲mac地址最后的B3改成了B5,于是重启设备生效后,该问题解决。

补充

经过之前的操作后,这个问题已经有一段时间消失没有出现了。但最近又再出现了,使用“ip addr”命令查看mac地址也没有存在一样的情况。这个时候可以使用以下方法尝试打开br-lan的STP功能:

#查看STP的开启情况
brctl show
#为br-lan开启STP
brctl stp br-lan on

然后再次查看STP的开启情况,此时应该已经开启成功,如下图所示:

在Windows下使用JBoss的standalone模式运行打成war包的SrpingBoot时使用外部配置文件

先在SpringBoot项目中新增一个MyApplicationContext.java文件,内容如下:

import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.boot.env.YamlPropertySourceLoader;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.InputStreamResource;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class MyApplicationContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {

    @Override
    public void initialize(ConfigurableApplicationContext applicationContext) {
        String activeProfile = applicationContext.getEnvironment().getProperty("spring.profiles.active");
        if("uat".equals(activeProfile) || "prod".equals(activeProfile)){
            YamlPropertySourceLoader loader = new YamlPropertySourceLoader();
            try {
                String jbossHome = (String) applicationContext.getEnvironment().getSystemEnvironment().get("JBOSS_HOME");
                PropertySource<?> propertySource = loader.load("externalConfiguration", new InputStreamResource(Files.newInputStream(Paths.get(jbossHome+"\\standalone\\configuration\\application-druid.yml")))).get(0);
                applicationContext.getEnvironment().getPropertySources().addLast(propertySource);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

    }
}

然后再resources的META-INF目录中创建一个spring.factories文件,内容需要指向到刚刚创建的MyApplicationContextInitializer类文件:

在系统中新建JBOSS_HOME环境并指向JBOSS的根目录:

然后在jboss的standalone\configuration目录中放置对应的配置文件:

然后启用jboss服务,此时springboot的war应用会优先到这个configuration目录中寻找对应的application配置文件,找不到时便会使用war包中的配置文件。

close