Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/blacklist make udp work.
details: https://anonhg.NetBSD.org/src/rev/007a8549281b
branches: trunk
changeset: 805865:007a8549281b
user: christos <christos%NetBSD.org@localhost>
date: Thu Jan 22 05:35:55 2015 +0000
description:
make udp work.
diffstat:
external/bsd/blacklist/bin/blacklistd.c | 16 +++++++++++---
external/bsd/blacklist/include/bl.h | 7 ++++-
external/bsd/blacklist/include/blacklist.h | 10 +++++---
external/bsd/blacklist/lib/bl.c | 21 +++++++++++++++----
external/bsd/blacklist/lib/blacklist.c | 24 ++++++++++++++++++----
external/bsd/blacklist/test/srvtest.c | 31 ++++++++++++++++++++++++++---
6 files changed, 85 insertions(+), 24 deletions(-)
diffs (290 lines):
diff -r 23e1f602a497 -r 007a8549281b external/bsd/blacklist/bin/blacklistd.c
--- a/external/bsd/blacklist/bin/blacklistd.c Thu Jan 22 05:03:52 2015 +0000
+++ b/external/bsd/blacklist/bin/blacklistd.c Thu Jan 22 05:35:55 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: blacklistd.c,v 1.16 2015/01/22 04:13:04 christos Exp $ */
+/* $NetBSD: blacklistd.c,v 1.17 2015/01/22 05:35:55 christos Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
#include "config.h"
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: blacklistd.c,v 1.16 2015/01/22 04:13:04 christos Exp $");
+__RCSID("$NetBSD: blacklistd.c,v 1.17 2015/01/22 05:35:55 christos Exp $");
#include <sys/types.h>
#include <sys/socket.h>
@@ -138,8 +138,16 @@
rsl = sizeof(rss);
memset(&rss, 0, rsl);
if (getpeername(rfd, (void *)&rss, &rsl) == -1) {
- (*lfun)(LOG_ERR, "getsockname failed (%m)");
- goto out;
+ if (errno != ENOTCONN) {
+ (*lfun)(LOG_ERR, "getpeername failed (%m)");
+ goto out;
+ }
+ if (bi->bi_slen == 0) {
+ (*lfun)(LOG_ERR,
+ "unconnected socket with no peer in message");
+ goto out;
+ }
+ memcpy(&rss, &bi->bi_ss, bi->bi_slen);
}
if (state_get(state, &rss, &c, &dbi) == -1)
goto out;
diff -r 23e1f602a497 -r 007a8549281b external/bsd/blacklist/include/bl.h
--- a/external/bsd/blacklist/include/bl.h Thu Jan 22 05:03:52 2015 +0000
+++ b/external/bsd/blacklist/include/bl.h Thu Jan 22 05:35:55 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bl.h,v 1.9 2015/01/22 03:48:07 christos Exp $ */
+/* $NetBSD: bl.h,v 1.10 2015/01/22 05:35:55 christos Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -46,6 +46,8 @@
bl_type_t bi_type;
int bi_fd;
uid_t bi_uid;
+ socklen_t bi_slen;
+ struct sockaddr_storage bi_ss;
char bi_msg[1024];
} bl_info_t;
@@ -61,7 +63,8 @@
bl_t bl_create(bool, const char *, void (*)(int, const char *, ...));
void bl_destroy(bl_t);
-int bl_send(bl_t, bl_type_t, int, const char *);
+int bl_send(bl_t, bl_type_t, int, const struct sockaddr *, socklen_t,
+ const char *);
int bl_getfd(bl_t);
bl_info_t *bl_recv(bl_t);
bool bl_isconnected(bl_t);
diff -r 23e1f602a497 -r 007a8549281b external/bsd/blacklist/include/blacklist.h
--- a/external/bsd/blacklist/include/blacklist.h Thu Jan 22 05:03:52 2015 +0000
+++ b/external/bsd/blacklist/include/blacklist.h Thu Jan 22 05:35:55 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: blacklist.h,v 1.1 2015/01/21 16:16:00 christos Exp $ */
+/* $NetBSD: blacklist.h,v 1.2 2015/01/22 05:35:55 christos Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -32,11 +32,13 @@
#define _BLACKLIST_H
__BEGIN_DECLS
-struct blacklist;
+struct blacklist *blacklist_open(void);
+void blacklist_close(struct blacklist *);
int blacklist(int, int, const char *);
int blacklist_r(struct blacklist *, int, int, const char *);
-struct blacklist *blacklist_open(void);
-void blacklist_close(struct blacklist *);
+int blacklist_sa(int, int, const struct sockaddr *, socklen_t, const char *);
+int blacklist_sa_r(struct blacklist *, int, int,
+ const struct sockaddr *, socklen_t, const char *);
__END_DECLS
#endif /* _BLACKLIST_H */
diff -r 23e1f602a497 -r 007a8549281b external/bsd/blacklist/lib/bl.c
--- a/external/bsd/blacklist/lib/bl.c Thu Jan 22 05:03:52 2015 +0000
+++ b/external/bsd/blacklist/lib/bl.c Thu Jan 22 05:35:55 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bl.c,v 1.14 2015/01/22 04:20:50 christos Exp $ */
+/* $NetBSD: bl.c,v 1.15 2015/01/22 05:35:55 christos Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: bl.c,v 1.14 2015/01/22 04:20:50 christos Exp $");
+__RCSID("$NetBSD: bl.c,v 1.15 2015/01/22 05:35:55 christos Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -50,6 +50,7 @@
#include <unistd.h>
#include <stdint.h>
#include <stdbool.h>
+#include <errno.h>
#include "bl.h"
@@ -57,6 +58,8 @@
uint32_t bl_len;
uint32_t bl_version;
uint32_t bl_type;
+ uint32_t bl_salen;
+ struct sockaddr_storage bl_ss;
char bl_data[];
} bl_message_t;
@@ -207,7 +210,8 @@
}
int
-bl_send(bl_t b, bl_type_t e, int pfd, const char *ctx)
+bl_send(bl_t b, bl_type_t e, int pfd, const struct sockaddr *sa, socklen_t slen,
+ const char *ctx)
{
struct msghdr msg;
struct iovec iov;
@@ -224,14 +228,19 @@
#define NTRIES 5
ctxlen = strlen(ctx);
- if (ctxlen > 256)
- ctxlen = 256;
+ if (ctxlen > 128)
+ ctxlen = 128;
iov.iov_base = ub.buf;
iov.iov_len = sizeof(bl_message_t) + ctxlen;
ub.bl.bl_len = (uint32_t)iov.iov_len;
ub.bl.bl_version = BL_VERSION;
ub.bl.bl_type = (uint32_t)e;
+ if (slen > sizeof(ub.bl.bl_ss))
+ return EINVAL;
+ ub.bl.bl_salen = slen;
+ memset(&ub.bl.bl_ss, 0, sizeof(ub.bl.bl_ss));
+ memcpy(&ub.bl.bl_ss, sa, slen);
memcpy(ub.bl.bl_data, ctx, ctxlen);
msg.msg_name = NULL;
@@ -350,6 +359,8 @@
}
bi->bi_type = ub.bl.bl_type;
+ bi->bi_slen = ub.bl.bl_salen;
+ bi->bi_ss = ub.bl.bl_ss;
strlcpy(bi->bi_msg, ub.bl.bl_data, MIN(sizeof(bi->bi_msg),
((size_t)rlen - sizeof(ub.bl) + 1)));
return bi;
diff -r 23e1f602a497 -r 007a8549281b external/bsd/blacklist/lib/blacklist.c
--- a/external/bsd/blacklist/lib/blacklist.c Thu Jan 22 05:03:52 2015 +0000
+++ b/external/bsd/blacklist/lib/blacklist.c Thu Jan 22 05:35:55 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: blacklist.c,v 1.3 2015/01/22 03:10:49 christos Exp $ */
+/* $NetBSD: blacklist.c,v 1.4 2015/01/22 05:35:55 christos Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: blacklist.c,v 1.3 2015/01/22 03:10:49 christos Exp $");
+__RCSID("$NetBSD: blacklist.c,v 1.4 2015/01/22 05:35:55 christos Exp $");
#include <stdio.h>
#include <bl.h>
@@ -76,21 +76,35 @@
}
int
-blacklist(int action, int rfd, const char *msg)
+blacklist_sa(int action, int rfd, const struct sockaddr *sa, socklen_t salen,
+ const char *msg)
{
struct blacklist *bl;
int rv;
if ((bl = blacklist_open()) == NULL)
return -1;
- rv = blacklist_r(bl, action, rfd, msg);
+ rv = blacklist_sa_r(bl, action, rfd, sa, salen, msg);
blacklist_close(bl);
return rv;
}
int
+blacklist_sa_r(struct blacklist *bl, int action, int rfd,
+ const struct sockaddr *sa, socklen_t slen, const char *msg)
+{
+ return bl_send(bl, action ? BL_ADD : BL_DELETE, rfd, sa, slen, msg);
+}
+
+int
+blacklist(int action, int rfd, const char *msg)
+{
+ return blacklist_sa(action, rfd, NULL, 0, msg);
+}
+
+int
blacklist_r(struct blacklist *bl, int action, int rfd, const char *msg)
{
- return bl_send(bl, action ? BL_ADD : BL_DELETE, rfd, msg);
+ return blacklist_sa_r(bl, action, rfd, NULL, 0, msg);
}
struct blacklist *
diff -r 23e1f602a497 -r 007a8549281b external/bsd/blacklist/test/srvtest.c
--- a/external/bsd/blacklist/test/srvtest.c Thu Jan 22 05:03:52 2015 +0000
+++ b/external/bsd/blacklist/test/srvtest.c Thu Jan 22 05:35:55 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: srvtest.c,v 1.8 2015/01/22 05:03:52 christos Exp $ */
+/* $NetBSD: srvtest.c,v 1.9 2015/01/22 05:35:55 christos Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: srvtest.c,v 1.8 2015/01/22 05:03:52 christos Exp $");
+__RCSID("$NetBSD: srvtest.c,v 1.9 2015/01/22 05:35:55 christos Exp $");
#include <sys/types.h>
#include <sys/socket.h>
@@ -55,7 +55,7 @@
#endif
static void
-process(int afd)
+process_tcp(int afd)
{
ssize_t n;
char buffer[256];
@@ -70,6 +70,26 @@
exit(0);
}
+static void
+process_udp(int afd)
+{
+ ssize_t n;
+ char buffer[256];
+ struct sockaddr_storage ss;
+ socklen_t slen;
+
+ memset(buffer, 0, sizeof(buffer));
+
+ slen = (socklen_t)sizeof(ss);
+ memset(&ss, 0, sizeof(ss));
+ if ((n = recvfrom(afd, buffer, sizeof(buffer), 0, (void *)&ss,
+ &slen)) == -1)
+ err(1, "recvfrom");
+ buffer[sizeof(buffer) - 1] = '\0';
+ printf("%s: sending %d %s\n", getprogname(), afd, buffer);
+ blacklist_sa(1, afd, (void *)&ss, slen, buffer);
+ exit(0);
+}
static int
cr(int af, int type, in_port_t p)
{
@@ -124,7 +144,10 @@
case -1:
err(1, "fork");
case 0:
- process(afd);
+ if (type == SOCK_DGRAM)
+ process_udp(afd);
+ else
+ process_tcp(afd);
break;
default:
close(afd);
Home |
Main Index |
Thread Index |
Old Index