192.168.1.1
192.168.1.*
192.168.*.*
192.*.*.*
下面是处理函数
- /************************************************
- str:The IP Address like 192.168.1.1
- start:The pointer to the start IP
- end:The pointer to the end IP
- ***********************************************/
- static int ip_to_unsigned(const char * str,unsigned int * start,unsigned int * end)
- {
- char cache[4][4];
- /*split the IP address*/
- int i;
- int k = 0;
- int j = 0;
- for(i = 0;str[i] != '\0';i++)
- {
- cache[j][k] = str[i];
- if(str[i] == '.')
- {
- cache[j][k] = '\0';
- k = 0;
- j++;
- }
- else k++;
- if(j > 3) return NO;
- }
- cache[3][k] = '\0';
- short int a[4];
- for(i = 0;i < 4;i++)
- {
- if(cache[i][0] != '*')
- {
- a[i] = (short)simple_strtol(cache[i],NULL,0);
- if(a[i] < 0 || a[i] > 255) return NO;
- }
- else
- {
- break;
- }
- }
- switch(i)
- {
- case 4:/*Specific IP Address eg. 192.168.1.1 */
- *start = *end = (a[0]<<24) + (a[1]<<16) + (a[2]<<8 )+a[3];
- break;
- case 3:/* eg. 192.168.1.* */
- *start = (a[0]<<24) + (a[1]<<16) + (a[2]<<8);
- *end = *start + (1<<8) - 1;
- break;
- case 2:/* eg. 192.168.*.* */
- *start = (a[0]<<24) + (a[1]<<16);
- *end = *start + (1<<16) - 1;
- break;
- case 1:/* eg. 192.*.*.* */
- *start = (a[0]<<24);
- *end = *start + (1<<24) - 1;
- break;
- default:
- *start = 0;
- *end = (1<<32) - 1;
- break;
- }
- return YES;
- }
- void remove_firewall()
- {
- free_ip_list(&ip_allowed_in_node_head);
- free_ip_list(&ip_denied_in_node_head);
- free_ip_list(&ip_allowed_out_node_head);
- free_ip_list(&ip_denied_out_node_head);
- free_port_list(&port_allowed_in_node_head);
- free_port_list(&port_denied_in_node_head);
- free_port_list(&port_allowed_out_node_head);
- free_port_list(&port_denied_out_node_head);
- nf_unregister_hook(&my_netfilter[0]);
- nf_unregister_hook(&my_netfilter[1]);
- printk("CLEAN up my firewall OK!\n");
- }
- MODULE_LICENSE("Dual BSD/GPL");
- MODULE_AUTHOR("yming0221@gmail.com");
- static int work_mode = 0;//default mode
- module_param(work_mode,int,S_IRUGO);
可以看到数据包能到达网络层,但由于防火墙启用的相应检查规则,浏览器等应用层软件无法联网,数据包被丢弃。

