Linux内核参数rp_filter

问题现象 主机上有两个网卡ens192和ens224。ens129网卡是对内网络的网卡,ens224是对网网络的网卡。 SIP信令阶段都是正常的,但是发现,对于来自node3的RTP流, 并没有从ens192网卡转发给node1上。 sequenceDiagram title network autonumber node1->>ens192: INVITE ens224->>node2: INVITE node2->>ens224: 200 ok ens192->>node1: 200 ok node1->>ens192: ACK ens224->>node2: ACK node1-->>ens192: RTP out ens224-->>node3: RTP out node3-->>ens224: RTP in 抓包程序抓到了node3发送到ens224上的包,但是排查应用服务器的日志发现,似乎应用服务器根本没有收到node3上过来的包, 所以也就无法转发。 因而怀疑是不是在内核上被拦截了。 后来通过将rp_filter设置为0, 然后语音流的转发就正常了。 事后复盘 node3的这个IP直接往应用服务器上发包,可能会被拦截。因为在信令建立的阶段,应用服务器并没有主动发 在kernel文档上 rp_filter - INTEGER 0 - No source validation. 1 - Strict mode as defined in RFC3704 Strict Reverse Path Each incoming packet is tested against the FIB and if the interface is not the best reverse path the packet check will fail. By default failed packets are discarded. 2 - Loose mode as defined in RFC3704 Loose Reverse Path Each incoming packet's source address is also tested against the FIB and if the source address is not reachable via any interface the packet check will fail. Current recommended practice in RFC3704 is to enable strict mode to prevent IP spoofing from DDos attacks. If using asymmetric routing or other complicated routing, then loose mode is recommended. The max value from conf/{all,interface}/rp_filter is used when doing source validation on the {interface}. Default value is 0. Note that some distributions enable it in startup scripts. 参考 https://www.jianshu.com/p/717e6cd9d2bb https://www.jianshu.com/p/16d5c130670b https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt

2022-06-13 00:00:00 · 1 min · Eddie Wang

mysql placeholder的错误使用方式

Error EXTRA *mysql.MySQLError=Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘? ( 然而我仔细看了看sql语句,没有看出来究竟哪里有sql报错。 然而当我把作为placeholder的问号去掉,直接用表的名字,sql是可以直接执行的。我意识到这个可能是和placeholder有关。 搜索了一下,看到一个链接 https://github.com/go-sql-driver/mysql/issues/848 Placeholder can’t be used for table name or column name. It’s MySQL spec. Not bug of this project. 大意是说,placeholder是不能作为表名或者列名的。 在mysql关于prepared文档介绍中,在允许使用prepared的语句里,没有看到create table可以用placeholderhttps://dev.mysql.com/doc/refman/8.0/en/sql-prepared-statements.html prepared语句的优点有以下几个 优化查询速度 防止sql注入 但是也有一些限制 不是所有语句都能用prepared语句。常见的用法应该是作为select where之后的条件,或者INSERT语句之后的值 不支持一个sql中多条查询语句的形式

2022-06-11 23:51:34 · 1 min · Eddie Wang

WebRTC 人声检测与舒适噪音

人声检测 VAD 人声检测(VAD: Voice Activity Detection)是区分语音中是人说话的声音,还是其他例如环境音的一种功能。 除此以外,人声检测还能用于减少网络中语音包传输的数据量,从而极大的降低语音的带宽,极限情况下能降低50%的带宽。 在一个通话中,一般都是只有一个人说话,另一人听。很少可能是两个人都说话的。 例如A在说话的时候,B可能在等待。 虽然B在等待过程中,B的语音流依然再按照原始速度和编码再发给A, 即使这里面是环境噪音或者是无声。 A ----> B # A在说话 A <--- B # B在等待过程中,B的语音流依然再按照原始速度和编码再发给A 如果B具有VAD检测功能,那么B就可以在不说话的时候,发送特殊标记的语音流或者通过减少语音流发送的频率,来减少无意义语音的发送。 从而极大的降低B->A的语音流。 下图是Wireshark抓包的两种RTP包,g711编码的占214字节,但是用舒适噪音编码的只有63字节。将近减少了4倍的带宽。 舒适噪音生成器 CNG 舒适噪音(CN stands for Comfort Noise), 是一种模拟的背景环境音。舒适噪音生成器在接收端根据发送到给的参数,来产生类似接收端的舒适噪音, 用来模拟发送方的噪音环境。 CN也是一种RTP包的格式,定义在RFC 3389 舒适噪音的payload, 也被称作静音插入描述帧(SID: a Silence Insertion Descriptor frame), 包括一个字节的数据,用来描述噪音的级别。也可以包含其他的额外的数据。早期版本的舒适噪音的格式定义在RFC 1890中,这个版本的格式只包含一个字段,就是噪音级别。 噪音级别占用一个字节,其中第一个bit必须是0, 因此噪音级别有127中可能。 0 1 2 3 4 5 6 7 +-+-+-+-+-+-+-+-+ |0| level | +-+-+-+-+-+-+-+-+ 跟着噪音级别的后续字节都是声音的频谱信息。 Byte 1 2 3 ... M+1 +-----+-----+-----+-----+-----+ |level| N1 | N2 | ... | NM | +-----+-----+-----+-----+-----+ Figure 2: CN Payload Packing Format 在SIP INVITE的SDP中也可以看到编码,如下面的CN ...

2022-06-01 08:27:53 · 2 min · Eddie Wang
千与千寻

Hugo博客常见问题以及解决方案

如何在markdown中插入图片 在static 目录中创建 images 目录,然后把图片放到images目录中。 在文章中引用的时候 ![](/images/qianxun.jpeg#center) Warning 我之前创建的文件夹的名字叫做 img, 本地可以正常显示,但是部署之后,就无法显示图片了。 最后我把img改成images才能正常在网页上显示。

2022-05-28 21:08:43 · 1 min · Eddie Wang

Shell 教程技巧

复制文本到剪贴板 sudo apt install xclip vim ~/.zshrc alias copy='xclip -selection clipboard' 这样我们就可以用copy命令来考本文件内容到系统剪贴板了。 copy aaa.txt 判断工作区是否clean if [ -z "$(git status --porcelain)" ]; then # Working directory clean else # Uncommitted changes fi

2022-05-28 12:39:50 · 1 min · Eddie Wang

C和gdb调试

开启coredump #如果该命令的返回值是0,则表示不开启coredump ulimit -c # 开启coredump ulimit -c unlimited 准备c文件 #include<stdio.h> void crash() { char * p = NULL; *p = 0; } int main(){ printf("hello world 1"); int phone [4]; phone[232] = 12; crash(); return 0; } 编译执行 gcc -g hello.c -o hello ./hello 之后程序崩溃,产生core文件。 gdb分析 gdb 启动的二进制文件 core文件 gdb ./hello ./core 之后输入: bt full 可以查看到更详细的信息 ➜ c-sandbox gdb ./hello ./core GNU gdb (Raspbian 7.12-6) 7.12.0.20161007-git Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "arm-linux-gnueabihf". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./hello...done. [New LWP 25571] Core was generated by `./hello'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x0001045c in crash () at hello.c:6 6 *p = 0; (gdb) bt full #0 0x0001045c in crash () at hello.c:6 p = 0x0 #1 0x00010490 in main () at hello.c:13 phone = {66328, 0, 0, 0}

2022-05-28 12:35:26 · 1 min · Eddie Wang

Tmux 常见问题以及解决方案

oh my tmux 关闭第二键ctrl-a ctrl-a可以用来移动光标到行首的,不要作为tmux的第二键 set -gu prefix2 unbind C-a Tmux reload config :source-file ~/.tmux.conf tmux 显示时间 ctrl b + t tmux从当前目录打开新的窗口 bind '"' split-window -c "#{pane_current_path}" bind % split-window -h -c "#{pane_current_path}" bind c new-window -c "#{pane_current_path}"

2022-05-28 12:30:58 · 1 min · Eddie Wang

hugo博客增加mermaid 绘图插件

step1 在themes/YourTheme/layouts/partials/extend_footer.html 的最后追加如下内容 {{if .Store.Get "hasMermaid" }} <script type="module"> import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs'; mermaid.initialize({ startOnLoad: true }); </script> {{end }} step2: 在layouts/_default/_markup/render-codeblock-mermaid.html <pre class="mermaid"> {{- .Inner | htmlEscape | safeHTML }} </pre> {{ .Page.Store.Set "hasMermaid" true }} 在blog中增加如下代码 pie title French Words I Know "Merde" : 50 "Oui" : 35 "Alors" : 10 "Non" : 5 sequenceDiagram title French Words I Know autonumber Alice->>Bob: hello Bob-->>Alice: hi Alice->Bob: talking

2022-05-27 11:49:44 · 1 min · Eddie Wang

klogg: 目前我最喜欢的日志查看工具

项目信息 github地址 https://github.com/variar/klogg 1. 安装 klogg是个跨平台软件,windows, mac, linux都可以安装。具体安装方式参考github项目地址 2. 界面布局 文件信息栏 日志栏 过滤器设置栏 过滤后的日志显示栏 3. 文件加载 klogg支持多种方式加载日志文件 将日志文件拖动到klogg中 直接将常见的压缩包文件拖动到klogg中,klogger将会自动将其解压后展示 支持从http url地址下载日志,然后查看 支持从剪贴板复制日志,然后展示 4. 过滤表达式 因为klogg支持正则过滤,所以他的功能就非常强悍了。 逻辑表达式 表达式 例子 备注 与 and “open” and “close” 包含open,并且包含close 或 or “open” or “close” 包含open, 或者 close 非 not not(“open”) 不包含open 与或非同时支持复杂的运算,例如包含open 但是不包含close: "open" and not("close") 5. 快捷方式 klogg的快捷方式很多参考了vim, vim使用者非常高兴。 键 动作 arrows 上下或者左右移动 [number] j/k 支持用j/k上下移动 h/l 支持用h/l左右移动 ^ or $ 滚动到某行的开始或者结尾 [number] g 跳到对应的行 entered G 跳到第一行 Shift+G 跳到最后一行 Alt+G 显示跳到某一行的对话框 ’ or " 在当前屏幕快速搜索 (forward and backward) n or N 向前或者向后跳 * or . search for the next occurrence of the currently selected text / or , search for the previous occurrence of the currently selected text f 流的方式,类似 tail -f m 标记某一行,标记后的行会自动加入过滤结果中 [ or ] 跳转到上一个或者下一标记点 + or - 调整过滤窗口的尺寸 v 循环切换各种显示模式- Matches: 只显式匹配的内容- Marks: 只显式标记的内容- Marks and Matchs:显示匹配和标记的内容 (Marks and Matches -> Marks -> Matches) F5 重新加载文件 Ctrl+S Set focus to search string edit box Ctrl+Shift+O 打开对话框去选择其他文件 参考 https://github.com/variar/klogg/blob/master/DOCUMENTATION.md

2022-04-13 19:41:53 · 1 min · Eddie Wang

macbook pro 使用1664天的感受

我之前写过一篇文章《macbook pro使用三年后的感受》,今天这篇文章是用4.5年的感受。 再次梳理一下,中间遇到过的问题 蝴蝶键盘很早有有些问题了,最近疫情在家,键盘被用坏了,J键直接坏了。只能外接键盘来用 屏幕下方出现淡红色的纹路,不太明显,基本不影响使用 中间我自己给macbook换过一次电池,换电池之前只要不插电,macbook很容易就关机了 风扇经常转,噪音有点吵,我已经觉得无所谓了 17年买这台电脑的时候,应该是9400左右。配置应该是最低配的 i5双核2.3Ghz, 8G内存,128硬盘的。 有些人可能惊讶,128G的硬盘怎么能够用的。但是我的确够用,我的磁盘还有将近50G的剩余空间呢。 我不是视频或者影音工作者,用的软件比较少。整个应用程序所占用的空间才4个多G。剩下的文稿可能大部分是代码。 由于我我基本上都是远程用ssh连上nuc上开发,所以mac上的资料更少。 但是macbook键盘坏了这个问题,是不能忍的。偶尔要移动办工的时候,不可能再带个外接键盘吧。 是时候准备和陪伴我4.5年的电脑说再见了。 本来想买14寸的macbook pro m1的,但是重量的增加以及很丑的刘海也是我不能忍的。 所以我觉得我会买一台轻便点的windows笔记本,而且windows还有一个很吸引我的点,就是linux子系统。这个linux子系统,要比mac的系统更加linux。 各位同学有没有推荐的windows的轻便笔记本呢?

2022-04-04 21:29:13 · 1 min · Eddie Wang