source: mainline/uspace/srv/net/udp/udp_inet.c@ 25525133

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 25525133 was b7fd2a0, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

Use errno_t in all uspace and kernel code.

Change type of every variable, parameter and return value that holds an
<errno.h> constant to either errno_t (the usual case), or sys_errno_t
(some places in kernel). This is for the purpose of self-documentation,
as well as for type-checking with a bit of type definition hackery.

Although this is a massive commit, it is a simple text replacement, and thus
is very easy to verify. Simply do the following:

`
git checkout <this commit's hash>
git reset HEAD
git add .
tools/srepl '\berrno_t\b' int
git add .
tools/srepl '\bsys_errno_t\b' sysarg_t
git reset
git diff
`

While this doesn't ensure that the replacements are correct, it does ensure
that the commit doesn't do anything except those replacements. Since errno_t
is typedef'd to int in the usual case (and sys_errno_t to sysarg_t), even if
incorrect, this commit cannot change behavior.

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[66a272f8]1/*
[2f19103]2 * Copyright (c) 2015 Jiri Svoboda
[66a272f8]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 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup udp
30 * @{
31 */
32
33/**
34 * @file
35 */
36
37#include <errno.h>
38#include <inet/inet.h>
39#include <io/log.h>
40
[92b42442]41#include "assoc.h"
42#include "pdu.h"
[66a272f8]43#include "std.h"
44#include "udp_inet.h"
[ee603c4]45#include "udp_type.h"
[66a272f8]46
[b7fd2a0]47static errno_t udp_inet_ev_recv(inet_dgram_t *dgram);
[92b42442]48static void udp_received_pdu(udp_pdu_t *pdu);
[66a272f8]49
50static inet_ev_ops_t udp_inet_ev_ops = {
51 .recv = udp_inet_ev_recv
52};
53
54/** Received datagram callback */
[b7fd2a0]55static errno_t udp_inet_ev_recv(inet_dgram_t *dgram)
[66a272f8]56{
[92b42442]57 udp_pdu_t *pdu;
[66a272f8]58
[a1a101d]59 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_inet_ev_recv()");
[66a272f8]60
[92b42442]61 pdu = udp_pdu_new();
[8d48c7e]62 pdu->iplink = dgram->iplink;
[92b42442]63 pdu->data = dgram->data;
64 pdu->data_size = dgram->size;
[a2e3ee6]65
66 pdu->src = dgram->src;
67 pdu->dest = dgram->dest;
[92b42442]68
69 udp_received_pdu(pdu);
[f1a8c23]70
71 /* We don't want udp_pdu_delete() to free dgram->data */
72 pdu->data = NULL;
[92b42442]73 udp_pdu_delete(pdu);
[66a272f8]74
75 return EOK;
76}
77
78/** Transmit PDU over network layer. */
[b7fd2a0]79errno_t udp_transmit_pdu(udp_pdu_t *pdu)
[66a272f8]80{
[b7fd2a0]81 errno_t rc;
[66a272f8]82 inet_dgram_t dgram;
83
[a1a101d]84 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_transmit_pdu()");
[92b42442]85
[695b6ff]86 dgram.iplink = pdu->iplink;
[a2e3ee6]87 dgram.src = pdu->src;
88 dgram.dest = pdu->dest;
[66a272f8]89 dgram.tos = 0;
[ee603c4]90 dgram.data = pdu->data;
91 dgram.size = pdu->data_size;
[66a272f8]92
93 rc = inet_send(&dgram, INET_TTL_MAX, 0);
94 if (rc != EOK)
[a1a101d]95 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to transmit PDU.");
[ee603c4]96
97 return rc;
[66a272f8]98}
[ee603c4]99
[66a272f8]100/** Process received PDU. */
[92b42442]101static void udp_received_pdu(udp_pdu_t *pdu)
[66a272f8]102{
[92b42442]103 udp_msg_t *dmsg;
[2f19103]104 inet_ep2_t rident;
[66a272f8]105
[a1a101d]106 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_received_pdu()");
[66a272f8]107
[92b42442]108 if (udp_pdu_decode(pdu, &rident, &dmsg) != EOK) {
[a1a101d]109 log_msg(LOG_DEFAULT, LVL_WARN, "Not enough memory. PDU dropped.");
[66a272f8]110 return;
111 }
[92b42442]112
113 /*
114 * Insert decoded message into appropriate receive queue.
115 * This transfers ownership of dmsg to the callee, we do not
116 * free it.
117 */
118 udp_assoc_received(&rident, dmsg);
[66a272f8]119}
[92b42442]120
[b7fd2a0]121errno_t udp_inet_init(void)
[66a272f8]122{
[b7fd2a0]123 errno_t rc;
[66a272f8]124
[a1a101d]125 log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_inet_init()");
[66a272f8]126
127 rc = inet_init(IP_PROTO_UDP, &udp_inet_ev_ops);
128 if (rc != EOK) {
[a1a101d]129 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed connecting to internet service.");
[66a272f8]130 return ENOENT;
131 }
132
133 return EOK;
134}
135
136/**
137 * @}
138 */
Note: See TracBrowser for help on using the repository browser.