荀子在《劝学》中有道,”不积跬步,无以至千里,不积小流无以成江海“,我们需要不断的积累自己遇到的解决过的一些问题,这样久而久之我们才能会掌握的越来越丰富的东西。
- 东西比较咋还不成系统,暂时先记录下来。
- 方便再次遇到同样的问题方便查找。
2021.08.22
__attribute__((unused))
变量属性(variable attribute)
通常,如果变量被声明但是从未被引用的话,C编译器则是会报出警告⚠️(warnning)。这个属性就是通知编译器你希望某个变量未使用,并且告诉它未使用的时候不要发出警告。
注意:
此变量属性是 ARM 编译器支持的 GNU 编译器扩展。
This variable attribute is a GNU compiler extension that the ARM compiler supports.
示例1:
1 | void Variable_Attribute_unused_0() |
在此示例中,编译器警告bUnused
已声明但从未引用过的 ,但不会警告aUnused
.
参考:https://www.keil.com/support/man/docs/armcc/armcc_chr1359124982981.htm
2021.11.04
- tcudmp过滤条件抓vlan数据包问题。
以前在处理现场项目的时候发现,客户的环境带有vlan数据头的数据包在使用tcpdump加上某个过滤条件之后(比如端口,或者IP)就会出现抓取不到数据包的情况,但是全抓不加过滤条件则是可以正常抓取,当时没在意就过去了。前两天又遇到了,同样的情况决定探一番究竟,在国内翻滚了一圈CSDN全是你抄我我抄你清一色的回答,最终无奈只能查阅官方文档中找到了答案。
vlan [vlan_id]
True if the packet is an IEEE 802.1Q VLAN packet. If the optional vlan_id is specified, only true if the packet has the specified vlan_id. Note that the first vlan keyword encountered in an expression changes the decoding offsets for the remainder of the expression on the assumption that the packet is a VLAN packet. The vlan [vlan_id]
keyword may be used more than once, to filter on VLAN hierarchies. Each use of that keyword increments the filter offsets by 4.
For example:
vlan 100 && vlan 200
filters on VLAN 200 encapsulated within VLAN 100, and
vlan && vlan 300 && ip
filters IPv4 protocol encapsulated in VLAN 300 encapsulated within any higher order VLAN.
- 在过滤vlan报文的过程中,需要加上vlan关键字配合过滤,如果是多层vlan则需要多个vlan关键字配合,例如
tcpdump -ieth0 vlan && port 3306
。 - 对指定的vlan ID的数据包进行过滤则是可以
tcpdump -ieth0 vlan 200 && port 3306
。
2021.11.13
- Gcc编译native选项问题
编译dpdk的时候,有编译不过的地方,按照网上文章指导开启了native选项,然后换了个环境的时候,竟然报错起不来了报SSE4_1指令集不支持,网上查了相关的资料原来才明白其中的原委,官方解释有如下。
‘native’
This selects the CPU to generate code for at compilation time by determining the processor type of the compiling machine. Using -march=native enables all instruction subsets supported by the local machine (hence the result might not run on different machines). Using -mtune=native produces code optimized for the local machine under the constraints of the selected instruction set.
大致意思就是说编译的时候会根据编译环境所支持的CPU指令集进行编译优化,所以如果我们开启了native选项,但是如果在和我们编译环境不一致的运行环境上可能会出现cpu指令集不支持从而导致起不来的现象。
Reference
[1] https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html