Chinaunix首页 | 论坛 | 博客
  • 博客访问: 411426
  • 博文数量: 96
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 415
  • 用 户 组: 普通用户
  • 注册时间: 2015-05-22 09:08
个人简介

最近的研究方向:Nginx

文章分类
文章存档

2017年(2)

2016年(59)

2015年(35)

我的朋友

分类: LINUX

2016-09-08 09:57:33

最近需要在内核态使用正则表达式,所以记录下找到的一些资料。

首先下面是别人移植好的源码:
,很不错,有posixAPI,以后有时间在研究pcre2API。


下面是别人的讨论帖,说的不错,可以参考:

下面是摘录:
Question:
I would like to use regexes in a linux kernel module. I have the regexes ready, and I tested them in user space with regex.h.
I know that regex.h is a user space library, but is there a kernel alternative?
Thanks!
Edit: I am trying to find C code in SMTP connections for a university project.

Answer:
The kernel already has a regexp engine; the functions are declared in kernel/trace/trace.h. It is part of the linux trace framework, and could relatively easily be adapted. You can see where it is currently used (identifier search).
Note also someone has got there before you. The l7-filter kernel component classifies L7 traffic based on (inter-alia) regex matching the packets. Their regex implementation has a man page.
You could also pass the packets to userspace via a socket using libipq, classify them, and pass them back. This is an easier approach, but slower, and apparently isn't what you want (but might be useful to another reader).
阅读(1658) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~