Deleted Added
full compact
alias_nbt.c (190938) alias_nbt.c (259858)
1/*-
2 * Written by Atsushi Murai <amurai@spec.co.jp>
3 * Copyright (c) 1998, System Planning and Engineering Co.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

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

24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 * TODO:
27 * oClean up.
28 * oConsidering for word alignment for other platform.
29 */
30
31#include <sys/cdefs.h>
1/*-
2 * Written by Atsushi Murai <amurai@spec.co.jp>
3 * Copyright (c) 1998, System Planning and Engineering Co.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

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

24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 * TODO:
27 * oClean up.
28 * oConsidering for word alignment for other platform.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/netinet/libalias/alias_nbt.c 190938 2009-04-11 15:19:09Z piso $");
32__FBSDID("$FreeBSD: head/sys/netinet/libalias/alias_nbt.c 259858 2013-12-25 02:06:57Z glebius $");
33
34/*
35 alias_nbt.c performs special processing for NetBios over TCP/IP
36 sessions by UDP.
37
38 Initial version: May, 1998 (Atsushi Murai <amurai@spec.co.jp>)
39
40 See HISTORY file for record of revisions.

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

65#include "alias_local.h"
66#include "alias_mod.h"
67#endif
68
69#define NETBIOS_NS_PORT_NUMBER 137
70#define NETBIOS_DGM_PORT_NUMBER 138
71
72static int
33
34/*
35 alias_nbt.c performs special processing for NetBios over TCP/IP
36 sessions by UDP.
37
38 Initial version: May, 1998 (Atsushi Murai <amurai@spec.co.jp>)
39
40 See HISTORY file for record of revisions.

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

65#include "alias_local.h"
66#include "alias_mod.h"
67#endif
68
69#define NETBIOS_NS_PORT_NUMBER 137
70#define NETBIOS_DGM_PORT_NUMBER 138
71
72static int
73AliasHandleUdpNbt(struct libalias *, struct ip *, struct alias_link *,
73AliasHandleUdpNbt(struct libalias *, struct ip *, struct alias_link *,
74 struct in_addr *, u_short);
75
76static int
77AliasHandleUdpNbtNS(struct libalias *, struct ip *, struct alias_link *,
78 struct in_addr *, u_short *, struct in_addr *, u_short *);
74 struct in_addr *, u_short);
75
76static int
77AliasHandleUdpNbtNS(struct libalias *, struct ip *, struct alias_link *,
78 struct in_addr *, u_short *, struct in_addr *, u_short *);
79static int
79static int
80fingerprint1(struct libalias *la, struct alias_data *ah)
81{
82
80fingerprint1(struct libalias *la, struct alias_data *ah)
81{
82
83 if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL ||
83 if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL ||
84 ah->aaddr == NULL || ah->aport == NULL)
85 return (-1);
86 if (ntohs(*ah->dport) == NETBIOS_DGM_PORT_NUMBER
87 || ntohs(*ah->sport) == NETBIOS_DGM_PORT_NUMBER)
88 return (0);
89 return (-1);
90}
91
84 ah->aaddr == NULL || ah->aport == NULL)
85 return (-1);
86 if (ntohs(*ah->dport) == NETBIOS_DGM_PORT_NUMBER
87 || ntohs(*ah->sport) == NETBIOS_DGM_PORT_NUMBER)
88 return (0);
89 return (-1);
90}
91
92static int
92static int
93protohandler1(struct libalias *la, struct ip *pip, struct alias_data *ah)
94{
95
96 return (AliasHandleUdpNbt(la, pip, ah->lnk, ah->aaddr, *ah->aport));
97}
98
93protohandler1(struct libalias *la, struct ip *pip, struct alias_data *ah)
94{
95
96 return (AliasHandleUdpNbt(la, pip, ah->lnk, ah->aaddr, *ah->aport));
97}
98
99static int
99static int
100fingerprint2(struct libalias *la, struct alias_data *ah)
101{
102
100fingerprint2(struct libalias *la, struct alias_data *ah)
101{
102
103 if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL ||
103 if (ah->dport == NULL || ah->sport == NULL || ah->lnk == NULL ||
104 ah->aaddr == NULL || ah->aport == NULL)
105 return (-1);
106 if (ntohs(*ah->dport) == NETBIOS_NS_PORT_NUMBER
107 || ntohs(*ah->sport) == NETBIOS_NS_PORT_NUMBER)
108 return (0);
109 return (-1);
110}
111
104 ah->aaddr == NULL || ah->aport == NULL)
105 return (-1);
106 if (ntohs(*ah->dport) == NETBIOS_NS_PORT_NUMBER
107 || ntohs(*ah->sport) == NETBIOS_NS_PORT_NUMBER)
108 return (0);
109 return (-1);
110}
111
112static int
112static int
113protohandler2in(struct libalias *la, struct ip *pip, struct alias_data *ah)
114{
115
116 AliasHandleUdpNbtNS(la, pip, ah->lnk, ah->aaddr, ah->aport,
117 ah->oaddr, ah->dport);
118 return (0);
119}
120
113protohandler2in(struct libalias *la, struct ip *pip, struct alias_data *ah)
114{
115
116 AliasHandleUdpNbtNS(la, pip, ah->lnk, ah->aaddr, ah->aport,
117 ah->oaddr, ah->dport);
118 return (0);
119}
120
121static int
121static int
122protohandler2out(struct libalias *la, struct ip *pip, struct alias_data *ah)
123{
124
125 return (AliasHandleUdpNbtNS(la, pip, ah->lnk, &pip->ip_src, ah->sport,
126 ah->aaddr, ah->aport));
127}
128
129/* Kernel module definition. */
130struct proto_handler handlers[] = {
122protohandler2out(struct libalias *la, struct ip *pip, struct alias_data *ah)
123{
124
125 return (AliasHandleUdpNbtNS(la, pip, ah->lnk, &pip->ip_src, ah->sport,
126 ah->aaddr, ah->aport));
127}
128
129/* Kernel module definition. */
130struct proto_handler handlers[] = {
131 {
132 .pri = 130,
133 .dir = IN|OUT,
134 .proto = UDP,
135 .fingerprint = &fingerprint1,
131 {
132 .pri = 130,
133 .dir = IN|OUT,
134 .proto = UDP,
135 .fingerprint = &fingerprint1,
136 .protohandler = &protohandler1
136 .protohandler = &protohandler1
137 },
138 {
139 .pri = 140,
140 .dir = IN,
141 .proto = UDP,
142 .fingerprint = &fingerprint2,
137 },
138 {
139 .pri = 140,
140 .dir = IN,
141 .proto = UDP,
142 .fingerprint = &fingerprint2,
143 .protohandler = &protohandler2in
143 .protohandler = &protohandler2in
144 },
145 {
146 .pri = 140,
147 .dir = OUT,
148 .proto = UDP,
149 .fingerprint = &fingerprint2,
144 },
145 {
146 .pri = 140,
147 .dir = OUT,
148 .proto = UDP,
149 .fingerprint = &fingerprint2,
150 .protohandler = &protohandler2out
150 .protohandler = &protohandler2out
151 },
151 },
152 { EOH }
153};
154
155static int
156mod_handler(module_t mod, int type, void *data)
157{
158 int error;
159

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

168 break;
169 default:
170 error = EINVAL;
171 }
172 return (error);
173}
174
175#ifdef _KERNEL
152 { EOH }
153};
154
155static int
156mod_handler(module_t mod, int type, void *data)
157{
158 int error;
159

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

168 break;
169 default:
170 error = EINVAL;
171 }
172 return (error);
173}
174
175#ifdef _KERNEL
176static
176static
177#endif
178moduledata_t alias_mod = {
179 "alias_nbt", mod_handler, NULL
180};
181
182#ifdef _KERNEL
183DECLARE_MODULE(alias_nbt, alias_mod, SI_SUB_DRIVERS, SI_ORDER_SECOND);
184MODULE_VERSION(alias_nbt, 1);

--- 669 unchanged lines hidden ---
177#endif
178moduledata_t alias_mod = {
179 "alias_nbt", mod_handler, NULL
180};
181
182#ifdef _KERNEL
183DECLARE_MODULE(alias_nbt, alias_mod, SI_SUB_DRIVERS, SI_ORDER_SECOND);
184MODULE_VERSION(alias_nbt, 1);

--- 669 unchanged lines hidden ---