海运的博客

openwrt/immortalwrt修改odhcpd ipv6 preferred_lifetime和valid_lifetime

发布时间:December 14, 2023 // 分类: // No Comments

宽带重新拨号会重新分配ipv6前缀,有的设备仍然优先使用旧的ip段,导致ipv6不能使用,可减小preferred_lifetime时间使旧的ip段快速失效。
openwrt dhcp提供preferred_lifetime参数设置preferred时间,需要将ra_useleasetime启用才有效,同时会将valid_lifetime修改为leasetime时间。

option leasetime '2h' 
option ra_lifetime 1200
option ra_useleasetime '1'
option preferred_lifetime '10m'

odhcpd源码判断设置preferred_lifetime和valid_lifetime:

src/router.c
if (addr->preferred > (uint32_t)now) {
        preferred = TIME_LEFT(addr->preferred, now);

        if (iface->ra_useleasetime &&
                        preferred > iface->preferred_lifetime)
                preferred = iface->preferred_lifetime;
}

valid = TIME_LEFT(addr->valid, now);
if (iface->ra_useleasetime && valid > iface->dhcp_leasetime)
        valid = iface->dhcp_leasetime;

使用wireshark查看效果:
2023-12-14_162454.jpg
也可用tcpdump查看:

tcpdump -i br-lan -nn "icmp6 && ip6[40] == 134" -vv

golang版本udpxy iptv rtp多播转http单播

发布时间:December 13, 2023 // 分类: // 2 Comments

使用udpxy和msd_lite都有一些小问题,参考多方用golang写了个简单rtp多播转http单播,无缓存,cpu占用有点小高,效果不错。

package main

import (
    "flag"
    "fmt"
    "github.com/pion/rtp"
    "io"
    "net"
    "net/http"
    //"strings"
    "time"
)

var timeout = 2000 * time.Millisecond
var readbuffer = 2 * 1024 * 1024
var buffer = 1500

const (
    RTP_Payload_MP2T = 33
    ContentType_MP2T    = "video/MP2T"
    ContentType_DEFAULT = "application/octet-stream"
)

var McastIface = flag.String("m", "eth1.23", "mcast iface (IP addr or name)")
var ListenAddr = flag.String("a", "0.0.0.0", "http listen addr (default 0.0.0.0)")
var ListenPort = flag.Int("p", 8080, "http listen port (default 8080)")

func main() {
    flag.Parse()
    http.HandleFunc("/", handler)
    fmt.Printf("http listen: %s:%d\n", *ListenAddr, *ListenPort)
    err := http.ListenAndServe(fmt.Sprintf("%s:%d", *ListenAddr, *ListenPort), nil)
    if err != nil {
        panic(err)
    }
}

var tag = "/udp/"
var tagLen = len(tag)

func handler(w http.ResponseWriter, r *http.Request) {
    var err error
    defer func(w http.ResponseWriter, r *http.Request) {
        if err != nil {
            w.WriteHeader(http.StatusInternalServerError)
            io.WriteString(w, err.Error()+"\n")
        }
        fmt.Println(time.Now().Format("2006-01-02 15:04:05"), "close http: "+r.RemoteAddr)
    }(w, r)

    path := r.URL.Path
    if len(path) < tagLen {
        w.WriteHeader(http.StatusBadRequest)
        io.WriteString(w, "No address specified\n")
        return
    }

    addr := path[tagLen:]
    fmt.Println(time.Now().Format("2006-01-02 15:04:05"), addr, r.RemoteAddr)

    conn, err := newMulticastReader(addr)
    if err != nil {
        return
    }

    defer func() {
        _ = conn.Close()
        fmt.Println(time.Now().Format("2006-01-02 15:04:05"), "close udp: "+addr)
    }()

    w.Header().Set("X-Content-Type-Options", "nosniff")
    conn.SetReadBuffer(readbuffer)
    headerSent := false
    p := &rtp.Packet{}
    var buf = make([]byte, buffer)
    for {
        conn.SetReadDeadline(time.Now().Add(timeout))
        n, err := conn.Read(buf)
        if err != nil {
            fmt.Println("read err:", err)
            w.WriteHeader(http.StatusInternalServerError)
            io.WriteString(w, err.Error())
            return
        }

        //fmt.Println(time.Now(), n, "buf len:", len(buf))
        if err = p.Unmarshal(buf[:n]); err != nil {
            fmt.Println("unpack err:", err)
            return
        }
        if !headerSent {
            headerSent = true
            if p.PayloadType == RTP_Payload_MP2T {
                w.Header().Set("Content-Type", ContentType_MP2T)
            } else {
                w.Header().Set("Content-Type", ContentType_DEFAULT)
            }
            w.WriteHeader(http.StatusOK)
        }
        if _, err = w.Write(p.Payload); err != nil {
            return
        }
    }
}

func newMulticastReader(address string) (conn *net.UDPConn, err error) {
    addr, err := net.ResolveUDPAddr("udp", address)
    if err != nil {
        return
    }
    //fmt.Printf(time.Now().Format("2006-01-02 15:04:05")+" multicast: listen addr %s\n", address)
    iface, err := net.InterfaceByName(*McastIface)
    conn, err = net.ListenMulticastUDP("udp", iface, addr)
    if err != nil {
        panic(err)
    }
    return
}

参考:
https://github.com/hello-xnew/gdpxy
https://github.com/darren/retv

贝尔G-140-ME光猫使用sshd登录提示Your password has expired

发布时间:December 5, 2023 // 分类: // No Comments

修改密码后依旧如此,修改/etc/shadow用户第三个字段为正整数即可:

cat /etc/shadow
user:$1$ercaZtGB$S8x9tyPTC1Bd8Litu7irt/:17000:0:99999::::

https://blog.csdn.net/baidu_31381143/article/details/53976386

联通使用移动贝尔G-140-ME光猫及使用TTL连接

发布时间:December 5, 2023 // 分类: // No Comments

由于移动默认使用password认证,先开启telnet http://192.168.1.1/system.cgi?telnet,通过telnet登录切换到电信界面用loid认证,只要olt认证成功,配置手工创建,此猫固件不包含联通界面。

ritool set Custom AH

重启后在web界面恢复出厂设置,电信用户名: telecomadmin密码: nE7jA%5m,移动用户名:CMCCAdmin 密码:aDm8H%MdA

ttl连接,电路板正面网口朝上,ttl针脚从上面开始依次为RX,TX,GND
2023-12-04_204734.jpg
启动后进入shell:

enable
shell
LA(ImvZx%8

https://www.chinadsl.net/forum.php?mod=viewthread&tid=172429
https://blog.ylx.me/archives/691.html

openwrt单线复用iptv并将组播转为http单播流任意设备观看

发布时间:November 29, 2023 // 分类: // No Comments

光猫内将iptv连接设置为桥接模式:
2023-11-29_083506.jpg

将上网和iptv绑定到对应的vlan,路由通过vlan区分iptv和上网。
2023-11-29_083535.jpg
如果光猫不能修改vlan,或不正常,我这个别猫直播黑屏,使用交换机中转并关闭igmp:
2023-12-04_070845.jpg
2023-12-04_070903.jpg
2023-12-04_070916.jpg
跑满千m带宽时iptv有点卡,将iptv端口优先级调高:
2024-04-17_163633.jpg
openwrt交换机配置vlan:
2023-11-29_083618.jpg

监听iptv流量获取dhcp认证信息,电视盒mac,主机名和Option60 Vendor class identifier:
2023-11-29_082520.jpg
2023-11-29_082624.jpg
2023-11-29_082739.jpg

openwrt配置iptv dhcp,0x3c即Option60用以发送16进制加密信息,dhcp有选项vendorid但是发送的是字符信息。
这样默认会发送两个Option60,修改文件/lib/netifd/proto/dhcp.sh内${vendorid:+-V "$vendorid"} \为-V '' \即可。
也可以将16进制option60设置vendorid参数并修改为${vendorid:+-V '' "-x 0x3c:$vendorid"}

config interface 'IPTV'
        option proto 'dhcp'
        option device 'eth1.23'
        option hostname 'xxxxxxx'
        option sendopts '0x3c:xxxxxxx'
        option peerdns '0'
        option delegate '0'
        option macaddr 'xxxxx'
        option defaultroute '0'

config interface 'MODEM'
        option proto 'static'
        option device 'eth1.22'
        list ipaddr '192.168.1.2/24'
        list ipaddr '192.168.0.2/24'
        option delegate '0'
        option defaultroute '0'

使用udpxy或msd_lite将组播转为http单播:

cat /etc/config/msd_lite
config instance
        option 'enabled' '1'

        # Bind address
        list 'address' '0.0.0.0:9999'
        #list 'address' '[::]:9999'
        # For multicast receive
        option 'network' 'IPTV'

        # 0 = auto detect
        option 'threads' '1'
        # Bind threads to CPUs
        option 'bind_to_cpu' '0'

        # Disconnect slow clients
        option 'drop_slow_clients' '0'
        # Pre cache size
        option 'precache_size' '4096'
        # Stream receive ring buffer size
        option 'ring_buffer_size' '1024'
        # Multicast receive socket buffer size
        option 'multicast_recv_buffer_size' '512'
        # Multicast receive timeout
        option 'multicast_recv_timeout' '2'
        # Do IGMP/MLD leave+join every X seconds
        option 'rejoin_time' '0'
cat /etc/config/udpxy 
config udpxy
        option disabled '1'
        option respawn '1'
        option verbose '0'
        option status '1'
        #option bind '0.0.0.0'
        option port '9999'
        option source 'eth1.23'
        option max_clients '100'
        # option log_file '/var/log/udpxy'
        # option buffer_size '4096'
        # option buffer_messages '-1'
        # option buffer_time '-1'
        # option nice_increment '0'
        # option mcsub_renew '0'

iptables:

iptables -A INPUT -i eth1.23 -p udp -d 224.0.0.0/4 -j ACCEPT
iptables -A INPUT -i eth1.23 -p igmp -d 224.0.0.0/4 -j ACCEPT
iptables -A INPUT -i eth1.23 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth1.23 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

当iptv接口重启时重启msd_lite:

cat /etc/hotplug.d/iface/95-msd_lite 
#!/bin/bash
if [ $ACTION = "ifup" -a "$INTERFACE" = "IPTV" ]; then
  /etc/init.d/msd_lite restart
fi

#[ "$ACTION" = "ifdown" -a "$INTERFACE" = "IPTV" ] && {
#/etc/init.d/msd_lite stop
#}

#[ "$ACTION" = "ifup" -a "$INTERFACE" = "IPTV" ] && {
#/etc/init.d/msd_lite start
#} 

openwrt交换机端口镜像抓组播或单播源,相应的端口查看vlan network配置。

switch mirror monitor 1  #镜像到的端口
switch mirror target 2 3 #要镜像的端口,0:off, 1:rx, 2:tx, 3:all
switch mirror target 2 0 #关闭镜像

遇到的问题,同样的方法一台光猫可以,另一台能获取到IPTV IP,直播黑屏,光猫不绑定vlan加管理交换机配置vlan并关闭igmp正常了。
播放时电视连接无线用diyp连接udpxy刚启动时会频繁花屏,有线无问题,无线连msd_lite无问题,但是msd_lite切换频道时偶尔花屏,msd_lite可能有同时最大8个连接数的限制,超过切换频道很慢。
udpx添加-B -R -H会大幅降低cpu占用,具体哪个没详细分析。
参考:
https://www.imyjy.cn/article/10.html

分类
最新文章
最近回复
  • 海运: 不好意思,没有。
  • zongboa: 您好,請問一下有immortalwrt設定guest Wi-Fi的GUI教學嗎?感謝您。
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
  • 孤狼: 擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办...
  • 海运: 网络,找到相应的url编辑重发请求,firefox有此功能,其它未知。
归档