Deleted Added
full compact
alias_dummy.c (190841) alias_dummy.c (259858)
1/*-
2 * Copyright (c) 2005 Paolo Pisati <piso@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2005 Paolo Pisati <piso@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/netinet/libalias/alias_dummy.c 190841 2009-04-08 11:56:49Z piso $");
28__FBSDID("$FreeBSD: head/sys/netinet/libalias/alias_dummy.c 259858 2013-12-25 02:06:57Z glebius $");
29
29
30/*
30/*
31 * Alias_dummy is just an empty skeleton used to demostrate how to write
32 * a module for libalias, that will run unalterated in userland or in
33 * kernel land.
34 */
35
36#ifdef _KERNEL
37#include <sys/param.h>
38#include <sys/kernel.h>

--- 15 unchanged lines hidden (view full) ---

54#else
55#include "alias_local.h"
56#include "alias_mod.h"
57#endif
58
59static void
60AliasHandleDummy(struct libalias *la, struct ip *ip, struct alias_data *ah);
61
31 * Alias_dummy is just an empty skeleton used to demostrate how to write
32 * a module for libalias, that will run unalterated in userland or in
33 * kernel land.
34 */
35
36#ifdef _KERNEL
37#include <sys/param.h>
38#include <sys/kernel.h>

--- 15 unchanged lines hidden (view full) ---

54#else
55#include "alias_local.h"
56#include "alias_mod.h"
57#endif
58
59static void
60AliasHandleDummy(struct libalias *la, struct ip *ip, struct alias_data *ah);
61
62static int
62static int
63fingerprint(struct libalias *la, struct alias_data *ah)
64{
65
63fingerprint(struct libalias *la, struct alias_data *ah)
64{
65
66 /*
67 * Check here all the data that will be used later, if any field
66 /*
67 * Check here all the data that will be used later, if any field
68 * is empy/NULL, return a -1 value.
69 */
68 * is empy/NULL, return a -1 value.
69 */
70 if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL ||
70 if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL ||
71 ah->maxpktsize == 0)
72 return (-1);
71 ah->maxpktsize == 0)
72 return (-1);
73 /*
74 * Fingerprint the incoming packet, if it matches any conditions
73 /*
74 * Fingerprint the incoming packet, if it matches any conditions
75 * return an OK value.
76 */
77 if (ntohs(*ah->dport) == 123
78 || ntohs(*ah->sport) == 456)
79 return (0); /* I know how to handle it. */
80 return (-1); /* I don't recognize this packet. */
81}
82
75 * return an OK value.
76 */
77 if (ntohs(*ah->dport) == 123
78 || ntohs(*ah->sport) == 456)
79 return (0); /* I know how to handle it. */
80 return (-1); /* I don't recognize this packet. */
81}
82
83/*
84 * Wrap in this general purpose function, the real function used to alias the
83/*
84 * Wrap in this general purpose function, the real function used to alias the
85 * packets.
86 */
87
85 * packets.
86 */
87
88static int
88static int
89protohandler(struct libalias *la, struct ip *pip, struct alias_data *ah)
90{
91
92 AliasHandleDummy(la, pip, ah);
93 return (0);
94}
95
89protohandler(struct libalias *la, struct ip *pip, struct alias_data *ah)
90{
91
92 AliasHandleDummy(la, pip, ah);
93 return (0);
94}
95
96/*
97 * NOTA BENE: the next variable MUST NOT be renamed in any case if you want
98 * your module to work in userland, cause it's used to find and use all
96/*
97 * NOTA BENE: the next variable MUST NOT be renamed in any case if you want
98 * your module to work in userland, cause it's used to find and use all
99 * the protocol handlers present in every module.
99 * the protocol handlers present in every module.
100 * So WATCH OUT, your module needs this variables and it needs it with
100 * So WATCH OUT, your module needs this variables and it needs it with
101 * ITS EXACT NAME: handlers.
102 */
103
104struct proto_handler handlers [] = {
101 * ITS EXACT NAME: handlers.
102 */
103
104struct proto_handler handlers [] = {
105 {
106 .pri = 666,
107 .dir = IN|OUT,
108 .proto = UDP|TCP,
109 .fingerprint = &fingerprint,
105 {
106 .pri = 666,
107 .dir = IN|OUT,
108 .proto = UDP|TCP,
109 .fingerprint = &fingerprint,
110 .protohandler = &protohandler
110 .protohandler = &protohandler
111 },
111 },
112 { EOH }
113};
114
115static int
116mod_handler(module_t mod, int type, void *data)
117{
118 int error;
119
112 { EOH }
113};
114
115static int
116mod_handler(module_t mod, int type, void *data)
117{
118 int error;
119
120 switch (type) {
120 switch (type) {
121 case MOD_LOAD:
122 error = 0;
123 LibAliasAttachHandlers(handlers);
124 break;
125 case MOD_UNLOAD:
126 error = 0;
127 LibAliasDetachHandlers(handlers);
128 break;

--- 25 unchanged lines hidden ---
121 case MOD_LOAD:
122 error = 0;
123 LibAliasAttachHandlers(handlers);
124 break;
125 case MOD_UNLOAD:
126 error = 0;
127 LibAliasDetachHandlers(handlers);
128 break;

--- 25 unchanged lines hidden ---