Release coccinelle-0.1.9-rc1
[bpt/coccinelle.git] / tests / free.c
1 static int del_from_chain(struct ip_fw *volatile*chainptr, struct ip_fw *frwl)
2 {
3 struct ip_fw *ftmp,*ltmp;
4 unsigned short tport1,tport2,tmpnum;
5 char matches,was_found;
6 unsigned long flags;
7
8 save_flags(flags);
9 cli();
10
11 ftmp=*chainptr;
12
13 if ( ftmp == NULL )
14 {
15 #ifdef DEBUG_IP_FIREWALL
16 printk("ip_fw_ctl: chain is empty\n");
17 #endif
18 restore_flags(flags);
19 return( EINVAL );
20 }
21
22 ltmp=NULL;
23 was_found=0;
24
25 while( !was_found && ftmp != NULL )
26 {
27 matches=1;
28 if (ftmp->fw_src.s_addr!=frwl->fw_src.s_addr
29 || ftmp->fw_dst.s_addr!=frwl->fw_dst.s_addr
30 || ftmp->fw_smsk.s_addr!=frwl->fw_smsk.s_addr
31 || ftmp->fw_dmsk.s_addr!=frwl->fw_dmsk.s_addr
32 || ftmp->fw_via.s_addr!=frwl->fw_via.s_addr
33 || ftmp->fw_flg!=frwl->fw_flg)
34 matches=0;
35
36 tport1=ftmp->fw_nsp+ftmp->fw_ndp;
37 tport2=frwl->fw_nsp+frwl->fw_ndp;
38 if (tport1!=tport2)
39 matches=0;
40 else if (tport1!=0)
41 {
42 for (tmpnum=0;tmpnum < tport1 && tmpnum < IP_FW_MAX_PORTS;tmpnum++)
43 if (ftmp->fw_pts[tmpnum]!=frwl->fw_pts[tmpnum])
44 matches=0;
45 }
46 if (strncmp(ftmp->fw_vianame, frwl->fw_vianame, IFNAMSIZ))
47 matches=0;
48 if(matches)
49 {
50 was_found=1;
51 if (ltmp)
52 {
53 ltmp->fw_next=ftmp->fw_next;
54 kfree(ftmp);
55 ftmp=ltmp->fw_next;
56 }
57 else
58 {
59 *chainptr=ftmp->fw_next;
60 kfree(ftmp);
61 ftmp=*chainptr;
62 }
63 }
64 else
65 {
66 ltmp = ftmp;
67 ftmp = ftmp->fw_next;
68 }
69 }
70 restore_flags(flags);
71 if (was_found)
72 return 0;
73 else
74 return(EINVAL);
75 }