1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
|
/*
* ==[ FILENAME: libebtc.h ]====================================================
*
* Project
*
* Library for ethernet bridge tables.
*
*
* Description
*
* See project.
*
*
* Copyright
*
* Copyright 2005 by Jens Götze
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,
* USA.
*
*
* =============================================================================
*/
#ifndef __LIB_EBTC_H__
#define __LIB_EBTC_H__ 1
#include <sys/socket.h>
#include <netinet/in.h>
#include <linux/netfilter_bridge/ebtables.h>
/* Macros */
#ifndef EBTC_MIN_ALIGN
# define EBTC_MIN_ALIGN (__alignof__(struct ebt_entry_target))
#endif
#define EBTC_ALIGN(s) (((s) + (EBTC_MIN_ALIGN - 1)) & \
~(EBTC_MIN_ALIGN - 1))
#define EBTC_SIZEOF(a) EBTC_ALIGN(sizeof(a))
#define EBTC_NEXT(a) ((char *)(a) + EBTC_ALIGN(sizeof(*(a))))
#define EBTC_ADDOFFSET(a, b) ((char *)(a) + (b))
#define EBTC_INIT 0x0000
#define EBTC_INIT_WITHFLUSH 0x0001
#define EBTC_FALSE -1
#define EBTC_TRUE 0
/* Types */
typedef struct ebtc_handle_st *ebtc_handle_t;
typedef struct ebt_replace ebt_replace_t;
typedef struct ebt_entries ebt_entries_t;
typedef struct ebt_entry ebt_entry_t;
typedef struct ebt_counter ebt_counter_t;
typedef struct ebt_entry_target ebt_entry_target_t;
typedef struct ebt_standard_target ebt_standard_target_t;
/* Functions */
/*
* ==[ FUNCTION: ebtc_is_chain ]================================================
*
* Description
*
* ebtc_is_chain checks chainname for exist.
*
*
* Parameter
*
* I chainname
* C-String with chainname.
*
* I handle
* EBTables handle
*
*
* Return value
*
* Returns 0 if it succeeds, or non-zero for an error.
*
*
* =============================================================================
*/
extern int ebtc_is_chain (const char *chainname, const ebtc_handle_t handle);
/*
* ==[ FUNCTION: ebtc_first_chain ]=============================================
*
* Description
*
* ebtc_first_chain returns the first chain.
*
*
* Parameter
*
* IO handle
* EBTables handle
*
*
* Return value
*
* Returns NULL if it end of list, or non-zero for pointer of chainname.
*
*
* =============================================================================
*/
extern const char *ebtc_first_chain (ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_next_chain ]==============================================
*
* Description
*
* ebtc_next_chain returns the next chain.
*
*
* Parameter
*
* IO handle
* EBTables handle
*
*
* Return value
*
* Returns NULL if it end of list, or non-zero for pointer of chainname.
*
*
* =============================================================================
*/
extern const char *ebtc_next_chain (ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_first_rule ]==============================================
*
* Description
*
* ebtc_first_rule returns the first rule in chain.
*
*
* Parameter
*
* I chainname
* C-String with chainname.
*
* IO handle
* EBTables handle
*
*
* Return value
*
* Returns NULL if it end of list, or non-zero for pointer of entry.
*
*
* =============================================================================
*/
extern const struct ebt_entry *ebtc_first_rule (const char *chainname,
ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_next_rule ]===============================================
*
* Description
*
* ebtc_next_rule returns the next rule in chain.
*
*
* Parameter
*
* I chainname
* C-String with chainname.
*
* IO handle
* EBTables handle
*
*
* Return value
*
* Returns NULL if it end of list, or non-zero for pointer of entry.
*
*
* =============================================================================
*/
extern const struct ebt_entry *ebtc_next_rule (const char *chainname,
ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_get_target ]==============================================
*
* Description
*
* ebtc_get_target returns target of an rule.
*
*
* Parameter
*
* I entry
* Pointer to an ebt_entry object with target.
*
* I handle
* EBTables handle
*
*
* Return value
*
* Returns NULL if it end of list, or non-zero for pointer of entry.
*
*
* =============================================================================
*/
extern const char *ebtc_get_target (const struct ebt_entry *entry,
const ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_is_builtin ]==============================================
*
* Description
*
* ebtc_is_builtin checks a chainname for built-in chain.
*
*
* Parameter
*
* I chainname
* C-String with chainname.
*
* I handle
* EBTables handle
*
*
* Return value
*
* Returns 0 if it's a built-in chain, or non-zero for a non built-in
* chain.
*
*
* =============================================================================
*/
extern int ebtc_is_builtin (const char *chainname, const ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_set_policy ]==============================================
*
* Description
*
* ebtc_set_policy set policy of a chain.
*
*
* Parameter
*
* I chainname
* C-String with chainname.
*
* I policy
* C-String with policy (ACCEPT, DROP, CONTINUE or RETURN).
*
* IO handle
* EBTables handle
*
*
* Return value
*
* Returns 0 if it succeeds, or non-zero for an error.
*
*
* =============================================================================
*/
extern int ebtc_set_policy (const char *chainname, const char *policy,
ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_get_policy ]==============================================
*
* Description
*
* ebtc_get_policy get policy of a chain.
*
*
* Parameter
*
* I chainname
* C-String with chainname.
*
* I handle
* EBTables handle
*
*
* Return value
*
* Returns a c-ctring with policy (ACCEPT, DROP, CONTINUE or RETURN).
*
*
* =============================================================================
*/
extern const char *ebtc_get_policy (const char *chainname,
const ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_insert_entry ]============================================
*
* Description
*
* ebtc_insert_entry insert a entry. You find details for the entry-object
* in linux/netfilter_bridge/ebtables.h.
*
*
* Parameter
*
* I chainname
* C-String with chainname.
*
* I entry
* Pointer for a entry-object.
*
* I rulenum
* Position of new rule.
*
* IO handle
* EBTables handle
*
*
* Return value
*
* Returns 0 if it succeeds, or non-zero for an error.
*
*
* =============================================================================
*/
extern int ebtc_insert_entry (const char *chainname,
const struct ebt_entry *entry,
unsigned int rulenum, ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_replace_entry ]===========================================
*
* Description
*
* ebtc_replace_entry replace a entry. You find details for the entry-object
* in linux/netfilter_bridge/ebtables.h.
*
*
* Parameter
*
* I chainname
* C-String with chainname.
*
* I entry
* Pointer for the new entry-object.
*
* I rulenum
* Position of new rule.
*
* IO handle
* EBTables handle
*
*
* Return value
*
* Returns 0 if it succeeds, or non-zero for an error.
*
*
* =============================================================================
*/
extern int ebtc_replace_entry (const char *chainname,
const struct ebt_entry *entry,
unsigned int rulenum, ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_append_entry ]============================================
*
* Description
*
* ebtc_append_entry append a entry. You find details for the entry-object
* in linux/netfilter_bridge/ebtables.h.
*
*
* Parameter
*
* I chainname
* C-String with chainname.
*
* I entry
* Pointer for a entry-object.
*
* IO handle
* EBTables handle
*
*
* Return value
*
* Returns 0 if it succeeds, or non-zero for an error.
*
*
* =============================================================================
*/
extern int ebtc_append_entry (const char *chainname,
const struct ebt_entry *entry,
ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_delete_entry ]============================================
*
* Description
*
* ebtc_append_entry delete a entry.
*
*
* Parameter
*
* I chainname
* C-String with chainname.
*
* I rulenum
* Position of rule.
*
* IO handle
* EBTables handle
*
*
* Return value
*
* Returns 0 if it succeeds, or non-zero for an error.
*
*
* =============================================================================
*/
extern int ebtc_delete_entry (const char *chainname, unsigned int rulenum,
ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_target_jumptochain ]======================================
*
* Description
*
* ebtc_target_jumptochain initialize standard target for jump to a chain.
*
*
* Parameter
*
* I chainname
* C-String with chainname.
*
* IO handle
* EBTables handle
*
*
* Return value
*
* Returns 0 if it succeeds, or non-zero for an error.
*
*
* =============================================================================
*/
extern int ebtc_target_jumptochain (ebt_standard_target_t *target,
char *chainname, ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_flush_entries ]===========================================
*
* Description
*
* ebtc_flush_entries flush all entries in a chain.
*
*
* Parameter
*
* I chainname
* C-String with chainname.
*
* IO handle
* EBTables handle
*
*
* Return value
*
* Returns 0 if it succeeds, or non-zero for an error.
*
*
* =============================================================================
*/
extern int ebtc_flush_entries (const char *chainname, ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_zero_entries ]============================================
*
* Description
*
* ebtc_zero_entries set all counter in a chain to zero.
*
*
* Parameter
*
* I chainname
* C-String with chainname.
*
* IO handle
* EBTables handle
*
*
* Return value
*
* Returns 0 if it succeeds, or non-zero for an error.
*
*
* =============================================================================
*/
extern int ebtc_zero_entries (const char *chainname, ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_rename_chain ]============================================
*
* Description
*
* ebtc_rename_chain rename a chain. A built-in chain returns an error.
*
*
* Parameter
*
* I chainname_old
* C-String with chainname.
*
* I chainname_new
* C-String with chainname.
*
* IO handle
* EBTables handle
*
*
* Return value
*
* Returns 0 if it succeeds, or non-zero for an error.
*
*
* =============================================================================
*/
extern int ebtc_rename_chain (const char *chainname_old,
const char *chainname_new, ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_create_chain ]============================================
*
* Description
*
* ebtc_create_chain create a chain.
*
*
* Parameter
*
* I chainname
* C-String with chainname.
*
* IO handle
* EBTables handle
*
*
* Return value
*
* Returns 0 if it succeeds, or non-zero for an error.
*
*
* =============================================================================
*/
extern int ebtc_create_chain (const char *chainname, ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_delete_chain ]============================================
*
* Description
*
* ebtc_delete_chain delete a chain. A built-in chain returns a error.
*
*
* Parameter
*
* I chainname
* C-String with chainname.
*
* IO handle
* EBTables handle
*
*
* Return value
*
* Returns 0 if it succeeds, or non-zero for an error.
*
*
* =============================================================================
*/
extern int ebtc_delete_chain (const char *chainname, ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_read_counter ]============================================
*
* Description
*
* ebtc_read_counter returns the current counter for packet and bytes.
*
*
* Parameter
*
* I chainname
* C-String with name of chain.
*
* I rulenum
* Position of rule.
*
* IO handle
* EBTables handle
*
*
* Return value
*
* Returns NULL for an error, or non-zero for the counter.
*
*
* =============================================================================
*/
extern const struct ebt_counter *ebtc_read_counter (const char *chainname,
unsigned int rulenum,
ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_zero_counter ]============================================
*
* Description
*
* ebtc_zero_counter set counter of a rule to zero.
*
*
* Parameter
*
* I chainname
* C-String with chainname.
*
* I rulenum
* Postion of rule.
*
* IO handle
* EBTables handle
*
*
* Return value
*
* Returns 0 if it succeeds, or non-zero for an error.
*
*
* =============================================================================
*/
extern int ebtc_zero_counter (const char *chainname, unsigned int rulenum,
ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_set_counter ]=============================================
*
* Description
*
* ebtc_set_counter set counter to a specific value.
*
*
* Parameter
*
* I chainname
* C-String with chainname.
*
* I rulenum
* Postion of rule.
*
* I counters
* New counter value.
*
* IO handle
* EBTables handle
*
*
* Return value
*
* Returns 0 if it succeeds, or non-zero for an error.
*
*
* =============================================================================
*/
extern int ebtc_set_counter (const char *chainname, unsigned int rulenum,
const struct ebt_counter *counters,
ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_init ]====================================================
*
* Description
*
* ebtc_init create a new handle for the tablename.
*
*
* Parameter
*
* I tablename
* C-String with name of table.
*
* I options
* Options, look at macros with the prefix "EBTC_INIT".
*
*
* Return value
*
* Returns NULL for an error, or non-zero for the handle.
*
*
* =============================================================================
*/
extern ebtc_handle_t ebtc_init (const char *tablename, int options);
/*
* ==[ FUNCTION: ebtc_commit ]==================================================
*
* Description
*
* ebtc_commit submit all changes to kernel. After the submit, handle is
* freed.
*
*
* Parameter
*
* IO handle
* EBTables handle
*
*
* Return value
*
* Returns 0 if it succeeds, or non-zero for an error.
*
*
* =============================================================================
*/
extern int ebtc_commit (ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_free ]====================================================
*
* Description
*
* ebtc_free free a handle.
*
*
* Parameter
*
* IO handle
* EBTables handle
*
*
* Return value
*
* Returns nothing.
*
*
* =============================================================================
*/
extern void ebtc_free (ebtc_handle_t *handle);
/*
* ==[ FUNCTION: ebtc_strerror ]================================================
*
* Description
*
* ebtc_strerror translate error id to a human readable message. If no
* handle exist (ebtc_init or ebtc_free return an error), use NULL. With
* option used ebtc_strerror an global variable. hint, in a
* multi-threading environment can return this method a wrong message.
*
*
* Parameter
*
* I handle
* EBTables handle
*
*
* Return value
*
* Returns NULL if message not exist, or non-zero for the message.
*
*
* =============================================================================
*/
extern const char *ebtc_strerror (const ebtc_handle_t *handle);
#endif
|