makefile学习笔记
Suricata学习笔记

Suricata学习笔记Suricata学习笔记王丽波 2013.9 1.ItemIDS:Intrusion Detection System⼊侵检测系统IPS:Intrusion Prevention System⼊侵防御系统2.Suricata.yaml⽂件Action-orde1) PassIf a signature matches and contains pass, Suricata stops scanning the packet and skips to the end of all rules (only for the current packet).2) DropThis only concerns the IPS/inline mode.If the program finds a signature that matches, containing drop, it stops immediately. The packet will not be sent any further. Drawback: The receiver does not receive a message of what is going on, resulting in a time-out (certainly with TCP). Suricata generates an alert for this packet.3) RejectThis is an active rejection of the packet. Both receiver and sender receive a reject packet. There are two types of reject packets that will be automatically selected. If the offending packet concerns TCP, it will be a Reset-packet. For all other protocols it will be an ICMP-error packet. Suricata also generates an alert. When in Inline/IPS mode, the offending packet will also be dropped like with the 'drop' action.4) AlertIf a signature matches and contains alert, the packet will be treated like any other non-threatening packet, except for this one an alert will be generated by Suricata. Only the system administrator can notice this alert.Inline/IPS can block network traffic in two ways. One way is by drop and the other by reject.Log output for use with Barnyard (unified.log)This log is designed to be stored in a binary format on the hard disc, where it will be further processed by Barnyard. Barnyard can store the output in a database, so Suricata can work on other important tasks. Barnyard can add the files in the Mysql-database, send them to Sguil or several other output options.There is a size-limit to the log-file: If Suricata generates an alert, it stores this alert in a unified-file. Suricata keeps continuing doing that, until the file has reached its limit. Which in the default case is at 32 MB. At that point Suricata generates a new file and the process starts all over again. Barnyard keeps on processing these files. To prevent Suricata from filling up the hard disc, a size limit is enforced. When the limit is reached, the file will 'role-over', creating a new file. Barnyard removes old files. To every file, Suricata adds a time stamp, so it is easy to see which one came first and which one is the latter.A line based log of HTTP requests (http.log)This log keeps track of events happening in the HTTP-traffic. It contains the HTTP request, the host-name, URI and the user-agent. This information will be stored as a http.log file in the default logging directory.Packet log (pcap-log)With the pcap-log option you can save all packets, that are registered by Suricata, in a log file named log.pcap. This way, you can take a look at all packets whenever you want.Threading1The decode module decodes the packets and the stream application layer performs its job here. The stream application layer has three tasks:First: it performs stream-tracking, meaning it is making sure all steps will be taken to make a correct network-connection. Second: TCP-network traffic comes in as packets. The Stream-Assembly engine reconstructs the original stream. Finally: the application layer will be inspected. HTTP and DCERPC will be analyzed.2The detection threads will compare signatures. There can be several detection threads so they can operate simultaneously. Example 7 Balancing workloadcpu_affinity:- management_cpu_set:cpu: [ 0 ] #Set the CPU('s) you want to process this set/thread.- receive_cpu_set:cpu: [ 0 ]- decode_cpu_set:cpu: [ 0, 1 ]mode: "balanced" #Can be set at 'balanced' and 'exclusive'.- stream_cpu_set:cpu: [ "0-1" ]- detect_cpu_set:cpu: [ "all" ]mode: "exclusive"prio:low: [ 0 ]medium: [ "1-2" ]high: [ 3 ]default: "medium"- verdict_cpu_set:cpu: [ 0 ]prio:- reject_cpu_set:cpu: [ 0 ]prio:default: "low"- output_cpu_set:cpu: [ "all" ]prio:default: "medium"IP DefragAt the moment Suricata receives a fragment of a packet, it keeps in memory that other fragments of that packet will appear soon to complete the packet. However, there is a possibility that one of the fragments does not appear. To prevent Suricata for keeping waiting for that packet (thereby using memory) there is a timespan after which Suricata discards the fragments. This occurs by default after 60 seconds.defrag:max-frags: 65535prealloc: yestimeout: 60Packet AcquisitionPf-ringThe Pf_ring is a library that aims to improve packet capture performance over libcap. It performs packet acquisition.There are three options within Pf_ring: interface, cluster-id and cluster-type.pfring:interface: eth0 # In this option you can set the network-interface# on which you want the packets of the network to be read.Pf_ring will load balance packets based on flow. All packet acquisition threads that will participate in the load balancing need to have the same cluster-id. It is important to make sure this ID is unique for this cluster of threads, so that no other engine / program is making use of clusters with the same id.cluster-id: 99Pf_ring can load balance traffic using pf_ring-clusters. All traffic for pf_ring can be load balanced in one of two ways, in a round robin manner or a per flow manner that are part of the same cluster. All traffic for pf_ring will be load balanced across acquisition threads of the same cluster id.The cluster_round_robin manner is a way of distributing packets one at a time to each thread (like distributing playing cards to fellow players). The cluster_flow manner is a way of distributing all packets of the same flow to the same thread. The flows itself will be distributed to the threads in a round-robin manner.cluster-type: cluster_round_robin附录1:AutoMake学习笔记1.安装autoconf⼯具#sudo apt-get install autoconf2.AutoMake的流程1. 在存放源代码的⽬录下执⾏autoscan命令⽣成configure.scan⽂件。
mtkpreloader学习笔记

mtkpreloader学习笔记1.先看preloader⽣成过程,mediatek/buid/makemtk.mk⽂件⾥preloader: ...$(hide) cd $(PRELOADER_WD) && \(./build.sh $(PROJECT) $(ACTION) $(DEAL_STDOUT) && \cd $(MKTOPDIR) && \$(call chkImgSize,$(ACTION),$(PROJECT),$(SCATTER_FILE),$(PRELOADER_IMAGES),$(DEAL_STDOUT),&&) \$(SHOWRSLT) $$? $(MODULE_LOG) || \$(SHOWRSLT) $$? $(MODULE_LOG))...执⾏mediatek/source/preloader/build.sh⽣成的。
2.在build.sh⾥有function build_preloader (){ ...make .....}3.执⾏mediatek/source/preloader/Makefile⽂件的make命令。
all: $(ALL)# ELF Generation#$(D_BIN)/$(PL_IMAGE_NAME).elf:$(LD) --gc-sections -Bstatic -T$(MTK_PATH_PLATFORM)/link_descriptor.ld \$(wildcard $(D_OBJ)/*) $(SECURITY_LIB) -Map system.map -o $(D_BIN)/$(PL_IMAGE_NAME).elf@$(OBJCOPY) ${OBJCFLAGS} $(D_BIN)/$(PL_IMAGE_NAME).elf -O binary $(D_BIN)/$(PL_IMAGE_NAME).bincat $(MTK_PATH_CUSTOM)/MTK_Loader_Info.tag >> $(D_BIN)/$(PL_IMAGE_NAME).bin这⼀句会最终解释为:arm-eabi-ld --gc-sections -Bstatic -T/home/chyl411/android/alps/mediatek/platform/mt6573/preloader/link_descriptor.ld \/home/chyl411/android/alps/mediatek/source/preloader/out/assembly.o/home/chyl411/android/alps/mediatek/source/preloader/out/................../home/chyl411/android/alps/mediatek/platform/mt6573/preloader/src/SecLib.a -Map system.map -o /home/chyl411/android/alps/mediatek/source/preloader/bin/preloader_(⼯程名)_gb.elf。
嵌入式学习心得体会(精选8篇)

嵌入式学习心得体会(精选8篇)嵌入式学习心得体会篇1(4622字)从实习到现在搞嵌入式开发快一年了,蓦然回首好像一年过得挺快,挺顺利的。
细细品味,发现这一年还是有很多值得回忆和总结的东西。
至少这一年看书挺多,大概二十几本,当然和那些一年看一百多本书的人没法比,但是我已经超越了自己。
这是我大学毕业的第一年,初次走上社会,很想一展身手,可是.....其实也不用可是了,和很多朋友一样碰了很多钉子,现在我和老板的关系就挺一般的,只是我性格还不错。
呵呵~~,做优秀员工看来还得慢慢学。
今年最大的收获就是做了一个半项目,是在uClinux下面跑的。
半个是SNMP-Agent的实现,因为我去的时候snmpd已经跑起来了,我只是实现部分管理功能;一个是基于Web的管理系统,使公司的主打产品微波通信设备上网。
这个项目是我一手策划,一手实现(界面设计是一位女同事,很优秀的程序员),从中学到的东西也最多,感情不可谓不深。
SNMP即简单网络管理协议,其实一点都不简单。
在我所知的网络协议里面,它仅仅比OSI的CMIP简单一点,而CMIP直到现在还没得到广泛应用。
我们能够实现SNMP-Agent不能不感谢CarnegieMellon大学免费发布的ucd-snmp软件包。
它使得开发人员专注于实现对特定设备的管理功能。
我在项目中的工作主要是扩展MIB,实现相应的管理功能以及网络功能的扩展。
我们公司的MIB库比较庞大,但是程序运行还是挺快的。
因为ucd-snmp软件包中大量使用回调函数,而且它将MIB树以二叉树形式表示,但是每个结点不是单个的MIB结点,而是一个表,包括了多个结点。
回调函数和两层表示法的使用是操作快速的主要因素。
基于Web的管理系统我原本是打算在设备外实现SNMP-Manager 的功能,因为设备中已经嵌入了Agent。
这样管理人员可以在世界各地通过WWW登录公司的管理平台,实现对所有设备的管理。
但是老板想在设备中嵌入一个管理系统,可以通过www管理单个设备就行。
make的主要用法

make的主要用法Make是一个常用的构建工具,它可以自动化地编译程序、生成文档、打包发布等操作。
Make最初是Unix系统下的一个工具,现在已经被广泛地应用于各种平台和语言中。
一、Make的基本概念1.1 MakefileMakefile是Make的配置文件,它描述了如何构建目标文件。
Make会根据Makefile中的规则来判断哪些文件需要重新编译,以及如何编译它们。
1.2 目标文件目标文件是指要生成的文件,可以是可执行程序、静态库、动态库等。
在Makefile中,每个目标都有一个对应的规则来描述如何生成它。
1.3 依赖关系依赖关系指的是目标文件与源文件之间的关系。
如果一个目标文件依赖于另外一个文件,那么在生成这个目标文件之前必须先生成它所依赖的那个文件。
1.4 规则规则描述了如何从源代码生成目标代码。
规则由三部分组成:目标、依赖和命令。
其中,目标表示要生成的文件,依赖表示该目标所依赖的其他文件,命令表示如何从依赖中生成目标。
二、Makefile语法2.1 变量定义变量可以用来存储一些常用的值,比如编译器、编译选项等。
变量的定义格式为:变量名=变量值。
2.2 目标规则目标规则描述了如何生成一个目标文件。
目标规则的格式为:目标: 依赖命令其中,目标表示要生成的文件,依赖表示该目标所依赖的其他文件,命令表示如何从依赖中生成目标。
2.3 伪目标伪目标是指不对应任何实际文件的目标,它们通常用来描述一些特殊的操作,比如清空临时文件、打包发布等。
伪目标的名称前面要加上一个“.”号。
2.4 函数Make提供了一些内置函数来方便我们编写Makefile。
常用的函数有:$(wildcard pattern)、$(patsubst pattern,replacement,text)、$(subst from,to,text)等。
三、Makefile实例下面是一个简单的Makefile示例:CC=gccCFLAGS=-Wall -gLDFLAGS=-lmall: hello_world.exehello_world.exe: hello_world.o$(CC) $(LDFLAGS) $< -o $@hello_world.o: hello_world.c$(CC) $(CFLAGS) -c $< -o $@clean:rm -f *.o *.exe这个Makefile定义了三个变量:CC表示编译器,CFLAGS表示编译选项,LDFLAGS表示链接选项。
Makefile的ifeq逻辑或,逻辑与的变通实现

Makefile的ifeq逻辑或,逻辑与的变通实现(1)ifeq的⽤法ifeq ($(变量名),变量值 )........else ifeq ($(..), ..).........else.........endif(2)最近在学习makefile的过程中遇到需要⽤ifeq进⾏逻辑与判断,但是ifeq并没有像其他编程语⾔那样有逻辑或(||)逻辑与(&&)的符号可⽤。
这时候需要变通⼀下。
1)逻辑与变通实现:举例说明:⽐如需要判断两个变量 VALUE1 和 VALUE2 的值都存在才执⾏某个动作,这需要逻辑与的判断C语⾔的逻辑: if ( VALUE1 && VALUE2){do something....}没有&&符号,我们可以这样变通:将两个变量链接起来再判断ifneq ($(VALUE1)$(VALUE2),)do something....endif如果变量 VALUE1 和 VALUE2 都有具体的值,⽐如需要进⾏这样的判断: VALUE1 == V1 && VALUE2 == V2, 可以按如下的写法;ifeq ($(VALUE1)_$(VALUE2), V1_V2) ### 当然中间的下划线 "_" 可以⽤其他字符代替do something....endif2)逻辑或变通实现,同样是上⾯的两个变量if( VALUE1 == V1 || VALUE2 == V2 ) {...} 可以⽤findstring函数做如下变通实现:#如果VALUE1或者VALUE2为V1或V2,则findstring 不会返回空。
ifneq ($(findstring $(VALUE1)$(VALUE2), V1 V2),)do something...endif。
Linux学习笔记一(文件和目录操作)

Linux学习笔记⼀(⽂件和⽬录操作)1.基本shell操作命令解析器--根据命令的名字,调⽤对应的可执⾏程序shell--unix操作系统bash--Linux操作系统(⽂件系统)Linux⽂件系统的存储单元是块在磁盘上存储的时候每个⽂件都有⼀个inode--i节点,保存了⼀些⽂件信息,通过iNode找到对应的⽂件a.快捷键b.虚拟终端history--查询命令的历史记录ctrl+p == 向上的箭头,查询上⼀个命令ctrl+n == 向下的箭头,查询下⼀个命令ctrl+b 向左移动backctrl+f 向右移动forwardctrl+a 移动到⾏⾸ctrl+e 移动到⾏尾ctrl+h 刪除光标前⾯的字符ctrl+d 刪除光标覆盖的字符ctrl+u 刪除光标前⾯的所有字符ctrl+k 删除光标位置到⾏尾的字符ctrl+l或者clear命令清理屏幕c.命令和路径补齐tab智能提⽰键,按⼀次没反应说明有很多符合条件的命令,再按⼀次出现符合条件的命令列表cd ⽬录 + 连续两次tab,显⽰⽬录下⼀级的所有路径d.centos7防⽕墙操作systemctl start firewalld.service 启动systemctl enable firewalld.service 开机启动systemctl stop firewalld.service 停⽌systemctl disable firewalld.service 禁⽌开机启动systemctl status firewalld.service 查看状态firewall-cmd --state 查看状态2.Linux系统⽬录结构ls 路径(查询当前路径下的所有⽂件)/根⽬录下的⽬录说明:/bin bin是binary的缩写,这个⽬录存放着经常使⽤的命令可执⾏程序/boot 存放的是启动Linux时的⼀些核⼼⽂件,包括⼀些连接⽂件以及镜像⽂件(开机启动项)/dev 是Device(设备)的缩写,该⽬录存放的是Linux的外部设备,在Linux中访问设备的⽅式和访问⽂件的⽅式是相同的(Linux奉⾏⼀切皆⽂件,它会把所有硬件外设抽象成设备⽂件存到dev⽬录之下,⽐如⿏标键盘)/etc ⽤来存放所有系统管理所需要的配置⽂件和⼦⽬录/home ⽤户的主⽬录,在Linux中,每个⽤户都有⼀个⾃⼰的⽬录,⼀般该⽬录名是以⽤户的账号命名。
【重要】调用makefile(多目录嵌套调用、变量使用)

obj2 = main2.o lib.o
all : edit1 edit2
edit1 : $(obj1)
gcc -o./main1/edit1 ./main1/main1.o lib.o
main1.o : main1.c
$(MAKE) -C./main1
gcc -csub2.c
都很简单对吧,就一条正常的编译命令,最后是根目录下的makefile:
VPATH=./sub1 ./sub2
obj=main.o sub1.o sub2.o
edit : $(obj)
gcc -oedit main.o ./sub1/sub1.o ./sub2/sub2.o
$(MAKE) -C$(s1)
lib.o : lib.c
gcc -clib.c
edit2 : $(ob2)/main2.o lib.o
main2.o : $(s2)/main2.c
$(MAKE) -C$(s2)
main1.c和main2.c里都有主函数,需要调用lib.c里的求和函数,只是所传递的参数值不同。要求通过根目录下的makefile嵌套调用子目录下的makefile来编译,最后链接生成可执行文件edit1和edit2,最后执行edit1和edit2应该能得到两个不同的值(也就是lib.c所求得的和)。
好了,我就不贴三个源文件的C代码了,大家自己写用来测试,我就直接贴makefile的编写了。
首先是子目录sub1下的makefile:
sub1.o : sub1.c
gcc-c sub1.c
接下来是子目录sub2下的makefile:
CMake从入门到精通

例子一一个经典的C程序,如何用cmake来进行构建程序呢?//main.c#include <stdio.h>int main(){printf("Hello World!/n");return 0;}编写一个CMakeList.txt 文件(可看做cmake的工程文件):project(HELLO)set(SRC_LIST main.c)add_executable(hello ${SRC_LIST})然后,建立一个任意目录(比如本目录下创建一个build子目录),在该build目录下调用cmake 注意:为了简单起见,我们从一开始就采用cmake的out-of-source 方式来构建(即生成中间产物与源代码分离),并始终坚持这种方法,这也就是此处为什么单独创建一个目录,然后在该目录下执行cmake 的原因cmake .. -G"NMake Makefiles"nmake或者cmake .. -G"MinGW Makefiles"make即可生成可执行程序hello(.exe)目录结构+|+--- main.c+--- CMakeList.txt|/--+ build/|+--- hello.execmake 真的不太好用哈,使用cmake的过程,本身也就是一个编程的过程,只有多练才行。
我们先看看:前面提到的这些都是什么呢?CMakeList.txt第一行project不是强制性的,但最好始终都加上。
这一行会引入两个变量∙HELLO_BINARY_DIR 和HELLO_SOURCE_DIR同时,cmake自动定义了两个等价的变量∙PROJECT_BINARY_DIR和PROJECT_SOURCE_DIR因为是out-of-source方式构建,所以我们要时刻区分这两个变量对应的目录可以通过message来输出变量的值message(${PROJECT_SOURCE_DIR})set命令用来设置变量add_exectuable告诉工程生成一个可执行文件。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
学习了两天的makefile的嵌套调用编写也有一些心得,先声明,我也是初学者写文章只是为了更好的交流,也希望避免其他刚入Linux编程大门的童鞋少走弯路。
以下都是经过我多次测试并跑成功的,如有偏差还请见谅与指正。
我有两个练习例子:
①先来说说第一个例子:生成一个可执行文件edit
top dir(根目录)下有源文件main.c、makefile(主)、文件夹sub1、文件夹sub2;子目录sub1里有源文件sub1.c和makefile(次1);子目录sub2里有源文件sub2.c和makefile(次2)。
main.c里有主函数,需要调用sub1.c里的排序函数(按升序排)和sub2.c里的排序函数(按降序排)。
要求通过根目录下的makefile嵌套调用子目录下的makefile来编译,最后链接生成可执行文件edit。
好了,我就不贴三个源文件的C代码了,大家自己写用来测试,我就直接贴makefile的编写了。
首先是子目录sub1下的makefile:
sub1.o : sub1.c
gcc -c sub1.c
接下来是子目录sub2下的makefile:
sub2.o : sub2.c
gcc -c sub2.c
都很简单对吧,就一条正常的编译命令,最后是根目录下的makefile:
VPATH=./sub1 ./sub2
obj=main.o sub1.o sub2.o
edit : $(obj)
gcc -o edit main.o ./sub1/sub1.o ./sub2/sub2.o
main.o : main.c
gcc -c main.c
sub1.o : sub1.c
$(MAKE) -C ./sub1
sub2.o : sub2.c
$(MAKE) -C ./sub2
.PHONY : clean
clean :
rm edit main.o -fr
rm ./sub1/*.o -fr
rm ./sub2/*.o -fr
②下面就说说我的第二个练习例子:生成两个可执行文件edit1、edit2
top dir(根目录)下有源文件lib.c、makefile(主)、文件夹main1、文件夹main2;子目录main1里有源文件main1.c和makefile(次1);子目录main2里有源文件main2.c和makefile(次2)。
main1.c和main2.c里都有主函数,需要调用lib.c里的求和函数,只是所传
递的参数值不同。
要求通过根目录下的makefile嵌套调用子目录下的makefile 来编译,最后链接生成可执行文件edit1和edit2,最后执行edit1和edit2应该能得到两个不同的值(也就是lib.c所求得的和)。
首先是子目录main1的makefile:
main1.o : main1.c
gcc -c main1.c
接下来是子目录main2的makefile:
main2.o : main2.c
gcc -c main2.c
最后是根目录下的makefile:
VPATH = ./main1 ./main2
obj1 = main1.o lib.o
obj2 = main2.o lib.o
all : edit1 edit2
edit1 : $(obj1)
gcc -o ./main1/edit1 ./main1/main1.o lib.o
main1.o : main1.c
$(MAKE) -C ./main1
lib.o : lib.c
gcc -c lib.c
edit2 : $(obj2)
gcc -o ./main2/edit2 ./main2/main2.o lib.o
main2.o : main2.c
$(MAKE) -C ./main2
.PHONY : clean
clean :
rm *.o -fr
rm ./main1/*.o ./main1/edit1 -fr
rm ./main2/*.o ./main2/edit2 –fr
难道你认为这次学习就结束了吗??当然不!上面这些makefile的确能满足嵌套调用的基本需求,但是你不觉得./sub1/sub1.c,./sub2/sub.2这些路径的表达很烦琐吗?万一这是个大的工程项目,突然要往某个子目录下增加一个源文件,那么修改这些makefile还不弄死你啊,可怕的不是累而是容易遗漏某一处而导致错误,所以对于立志成为一个好的makefile的编写员的人这些还远远不够!下面就让我们来对以上的makefile进行一次改头换面吧!领略一下变量的风采!
①第一个例子的根目录下的makefile修改如下,其余两个makefile不变:
cur-dir:=$(shell pwd)
s1=$(cur-dir)/sub1
s2=$(cur-dir)/sub2
obj=main.o sub1.o sub2.o
edit : $(obj)
gcc -o edit main.o $(s1)/sub1.o $(s2)/sub2.o
main.o : main.c
gcc -c main.c
sub1.o : $(s1)/sub1.c
$(MAKE) -C $(s1)
sub2.o : $(s2)/sub2.c
$(MAKE) -C $(s2)
.PHONY : clean
clean :
rm edit main.o -fr
rm $(s1)/*.o -fr
rm $(s2)/*.o -fr
②第二个例子的根目录下的makefile修改如下,其余两个makefile不变:cur-dir:=$(shell pwd)
s1=$(cur-dir)/main1
s2=$(cur-dir)/main2
obj1 = main1.o lib.o
obj2 = main2.o lib.o
all : edit1 edit2
edit1 : $(obj1)
gcc -o $(s1)/edit1 $(s1)/main1.o lib.o
main1.o : $(s1)/main1.c
$(MAKE) -C $(s1)
lib.o : lib.c
gcc -c lib.c
edit2 : $(obj2)
gcc -o $(s2)/edit2 $(s2)/main2.o lib.o
main2.o : $(s2)/main2.c
$(MAKE) -C $(s2)
.PHONY : clean
clean :
rm *.o -fr
rm $(s1)/*.o $(s1)/edit1 -fr
rm $(s2)/*.o $(s2)/edit2 -fr。