All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
proto_vmps.c
Go to the documentation of this file.
1 /*
2  * proto_vmps.c Handle VMPS traffic.
3  *
4  * Version: $Id: 4198c552210b2161e4ed7d8ac7739ee298b458f1 $
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  * Copyright 2007 The FreeRADIUS server project
21  * Copyright 2007 Alan DeKok <aland@deployingradius.com>
22  */
23 
24 RCSID("$Id: 4198c552210b2161e4ed7d8ac7739ee298b458f1 $")
25 
26 #include <freeradius-devel/radiusd.h>
27 #include <freeradius-devel/protocol.h>
28 #include <freeradius-devel/process.h>
29 #include <freeradius-devel/modules.h>
30 #include <freeradius-devel/rad_assert.h>
31 
32 #include "vqp.h"
33 
34 static int vmps_process(REQUEST *request)
35 {
36  DEBUG2("Doing VMPS");
37  process_post_auth(0, request);
38  DEBUG2("Done VMPS");
39 
40  request->reply->code = PW_CODE_ACCESS_ACCEPT;
41 
42  return 0;
43 }
44 
45 /*
46  * Check if an incoming request is "ok"
47  *
48  * It takes packets, not requests. It sees if the packet looks
49  * OK. If so, it does a number of sanity checks on it.
50  */
51 static int vqp_socket_recv(rad_listen_t *listener)
52 {
53  RADIUS_PACKET *packet;
54  RAD_REQUEST_FUNP fun = NULL;
55  RADCLIENT *client;
56 
57  packet = vqp_recv(listener->fd);
58  if (!packet) {
59  ERROR("%s", fr_strerror());
60  return 0;
61  }
62 
63  if ((client = client_listener_find(listener,
64  &packet->src_ipaddr,
65  packet->src_port)) == NULL) {
66  fr_radius_free(&packet);
67  return 0;
68  }
69 
70  /*
71  * Do new stuff.
72  */
73  fun = vmps_process;
74 
75  if (!request_receive(NULL, listener, packet, client, fun)) {
76  fr_radius_free(&packet);
77  return 0;
78  }
79 
80  return 1;
81 }
82 
83 
84 /*
85  * Send an authentication response packet
86  */
87 static int vqp_socket_send(rad_listen_t *listener, REQUEST *request)
88 {
89  rad_assert(request->listener == listener);
90  rad_assert(listener->send == vqp_socket_send);
91 
92  if (vqp_encode(request->reply, request->packet) < 0) {
93  DEBUG2("Failed encoding packet: %s\n", fr_strerror());
94  return -1;
95  }
96 
97  return vqp_send(request->reply);
98 }
99 
100 
101 static int vqp_socket_encode(UNUSED rad_listen_t *listener, REQUEST *request)
102 {
103  return vqp_encode(request->reply, request->packet);
104 }
105 
106 
107 static int vqp_socket_decode(UNUSED rad_listen_t *listener, REQUEST *request)
108 {
109  return vqp_decode(request->packet);
110 }
111 
113 fr_protocol_t proto_vmps = {
115  .name = "vmps",
116  .inst_size = sizeof(listen_socket_t),
117  .transports = TRANSPORT_UDP,
118  .tls = false,
119  .size = vqp_packet_size,
120  .parse = common_socket_parse,
121  .open = common_socket_open,
122  .recv = vqp_socket_recv,
123  .send = vqp_socket_send,
124  .print = common_socket_print,
125  .debug = common_packet_debug,
126  .encode = vqp_socket_encode,
127  .decode = vqp_socket_decode
128 };
static int vmps_process(REQUEST *request)
Definition: proto_vmps.c:34
int common_socket_parse(CONF_SECTION *cs, rad_listen_t *this)
Definition: listen.c:1274
void common_packet_debug(REQUEST *request, RADIUS_PACKET *packet, bool received)
Definition: listen.c:1153
fr_ipaddr_t src_ipaddr
Src IP address of packet.
Definition: libradius.h:149
rlm_rcode_t process_post_auth(int type, REQUEST *request)
Definition: modules.c:2178
int fd
Definition: listen.h:77
#define UNUSED
Definition: libradius.h:134
#define RLM_MODULE_INIT
Definition: modules.h:86
rad_listen_t * listener
The listener that received the request.
Definition: radiusd.h:218
struct listen_socket_t listen_socket_t
rad_listen_send_t send
Definition: listen.h:96
uint16_t src_port
Src port of packet.
Definition: libradius.h:151
int vqp_send(RADIUS_PACKET *packet)
Definition: vqp.c:229
ssize_t vqp_packet_size(uint8_t const *data, size_t data_len)
See how big of a packet is in the buffer.
Definition: vqp.c:551
#define TRANSPORT_UDP
Definition: protocol.h:62
#define rad_assert(expr)
Definition: rad_assert.h:38
static int vqp_socket_decode(UNUSED rad_listen_t *listener, REQUEST *request)
Definition: proto_vmps.c:107
static int vqp_socket_send(rad_listen_t *listener, REQUEST *request)
Definition: proto_vmps.c:87
int(* RAD_REQUEST_FUNP)(REQUEST *)
Definition: process.h:51
#define DEBUG2(fmt,...)
Definition: log.h:176
static int vqp_socket_recv(rad_listen_t *listener)
Definition: proto_vmps.c:51
unsigned int code
Packet code (type).
Definition: libradius.h:155
RFC2865 - Access-Accept.
Definition: radius.h:93
int common_socket_open(CONF_SECTION *cs, rad_listen_t *this)
Definition: listen.c:1599
RADIUS_PACKET * vqp_recv(int sockfd)
Definition: vqp.c:114
RADIUS_PACKET * reply
Outgoing response.
Definition: radiusd.h:225
char const * fr_strerror(void)
Get the last library error.
Definition: log.c:212
int request_receive(TALLOC_CTX *ctx, rad_listen_t *listener, RADIUS_PACKET *packet, RADCLIENT *client, RAD_REQUEST_FUNP fun)
Definition: process.c:1523
Describes a host allowed to send packets to the server.
Definition: clients.h:35
void fr_radius_free(RADIUS_PACKET **)
Free a RADIUS_PACKET.
Definition: radius.c:1727
RADIUS_PACKET * packet
Incoming request.
Definition: radiusd.h:221
RADCLIENT * client_listener_find(rad_listen_t *listener, fr_ipaddr_t const *ipaddr, uint16_t src_port)
Definition: listen.c:344
int vqp_encode(RADIUS_PACKET *packet, RADIUS_PACKET *original)
Definition: vqp.c:374
int vqp_decode(RADIUS_PACKET *packet)
Definition: vqp.c:247
uint64_t magic
Used to validate loaded library.
Definition: protocol.h:40
Structures and prototypes for Cisco's VLAN Query Protocol.
#define RCSID(id)
Definition: build.h:135
int common_socket_print(rad_listen_t const *this, char *buffer, size_t bufsize)
Definition: listen.c:1021
#define ERROR(fmt,...)
Definition: log.h:145
fr_protocol_t proto_vmps
Definition: proto_vmps.c:113
static int vqp_socket_encode(UNUSED rad_listen_t *listener, REQUEST *request)
Definition: proto_vmps.c:101