aboutsummaryrefslogtreecommitdiff
path: root/net/relayd/files/patch-relayd-relayd.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/relayd/files/patch-relayd-relayd.c')
-rw-r--r--net/relayd/files/patch-relayd-relayd.c274
1 files changed, 164 insertions, 110 deletions
diff --git a/net/relayd/files/patch-relayd-relayd.c b/net/relayd/files/patch-relayd-relayd.c
index 661c23251cc2..5a3e55dce18d 100644
--- a/net/relayd/files/patch-relayd-relayd.c
+++ b/net/relayd/files/patch-relayd-relayd.c
@@ -1,127 +1,181 @@
---- relayd/relayd.c.orig 2011-01-15 00:27:09.020486320 +0100
-+++ relayd/relayd.c 2011-01-15 00:32:43.024188430 +0100
-@@ -26,6 +26,7 @@
+--- relayd/relayd.c.orig 2011-05-19 10:56:49.000000000 +0200
++++ relayd/relayd.c 2011-05-22 10:34:12.913164741 +0200
+@@ -17,7 +17,12 @@
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
++#ifdef __FreeBSD__
++#include <sys/param.h>
++#include <openssl/rand.h>
++#else
+ #include <sys/types.h>
++#endif
#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/wait.h>
-+#include <sys/resource.h>
+@@ -39,7 +44,11 @@
+ #include <unistd.h>
+ #include <ctype.h>
+ #include <pwd.h>
++#ifdef __FreeBSD__
++#include <sha.h>
++#else
+ #include <sha1.h>
++#endif
+ #include <md5.h>
- #include <net/if.h>
- #include <netinet/in.h>
-@@ -113,6 +114,9 @@
- case SIGHUP:
- reconfigure();
- break;
-+ case SIGPIPE:
-+ /* ignore */
-+ break;
- default:
- fatalx("unexpected signal");
- }
-@@ -142,10 +146,6 @@
- #endif
+ #include <openssl/ssl.h>
+@@ -150,6 +159,11 @@
struct relayd *env;
- const char *conffile;
-- struct event ev_sigint;
-- struct event ev_sigterm;
-- struct event ev_sigchld;
-- struct event ev_sighup;
- struct imsgev *iev;
+ struct privsep *ps;
+ const char *conffile = CONF_FILE;
++#ifdef __FreeBSD__
++#if __FreeBSD_version > 800040
++ u_int32_t rnd[256];
++#endif
++#endif
- opts = 0;
-@@ -261,15 +261,17 @@
+ while ((c = getopt(argc, argv, "dD:nf:v")) != -1) {
+ switch (c) {
+@@ -220,6 +234,16 @@
+ else
+ log_info("startup");
- event_init();
-
-- signal_set(&ev_sigint, SIGINT, main_sig_handler, env);
-- signal_set(&ev_sigterm, SIGTERM, main_sig_handler, env);
-- signal_set(&ev_sigchld, SIGCHLD, main_sig_handler, env);
-- signal_set(&ev_sighup, SIGHUP, main_sig_handler, env);
-- signal_add(&ev_sigint, NULL);
-- signal_add(&ev_sigterm, NULL);
-- signal_add(&ev_sigchld, NULL);
-- signal_add(&ev_sighup, NULL);
-- signal(SIGPIPE, SIG_IGN);
-+ signal_set(&env->sc_evsigint, SIGINT, main_sig_handler, env);
-+ signal_set(&env->sc_evsigterm, SIGTERM, main_sig_handler, env);
-+ signal_set(&env->sc_evsigchld, SIGCHLD, main_sig_handler, env);
-+ signal_set(&env->sc_evsighup, SIGHUP, main_sig_handler, env);
-+ signal_set(&env->sc_evsigpipe, SIGPIPE, main_sig_handler, env);
++#ifdef __FreeBSD__
++#if __FreeBSD_version > 800040
++ arc4random_stir();
++ arc4random_buf(rnd, sizeof(rnd));
++ RAND_seed(rnd, sizeof(rnd));
++#else
++ RAND_load_file("/dev/random",2048);
++#endif
++#endif
+
-+ signal_add(&env->sc_evsigint, NULL);
-+ signal_add(&env->sc_evsigterm, NULL);
-+ signal_add(&env->sc_evsigchld, NULL);
-+ signal_add(&env->sc_evsighup, NULL);
-+ signal_add(&env->sc_evsigpipe, NULL);
+ ps->ps_instances[PROC_RELAY] = env->sc_prefork_relay;
+ proc_init(ps, procs, nitems(procs));
+
+@@ -258,7 +282,9 @@
+ if (parent_configure(env) == -1)
+ fatalx("configuration failed");
+
++#ifndef __FreeBSD__
+ init_routes(env);
++#endif
- close(pipe_parent2pfe[1]);
- close(pipe_parent2hce[1]);
-@@ -322,6 +324,8 @@
- #endif
event_dispatch();
-+ main_shutdown(env);
-+ /* NOTREACHED */
- return (0);
- }
+@@ -273,7 +299,9 @@
+ {
+ struct table *tb;
+ struct rdr *rdr;
++#ifndef __FreeBSD__
+ struct router *rt;
++#endif
+ struct protocol *proto;
+ struct relay *rlay;
+ int id;
+@@ -284,8 +312,10 @@
+ config_settable(env, tb);
+ TAILQ_FOREACH(rdr, env->sc_rdrs, entry)
+ config_setrdr(env, rdr);
++#ifndef __FreeBSD__
+ TAILQ_FOREACH(rt, env->sc_rts, rt_entry)
+ config_setrt(env, rt);
++#endif
+ TAILQ_FOREACH(proto, env->sc_protos, entry)
+ config_setproto(env, proto);
+ TAILQ_FOREACH(rlay, env->sc_relays, rl_entry)
+@@ -359,9 +389,11 @@
-@@ -642,6 +646,7 @@
- #ifndef __FreeBSD__
- struct ctl_demote demote;
- #endif
-+ int verbose;
+ proc_kill(env->sc_ps);
+ control_cleanup(&env->sc_ps->ps_csock);
++#ifndef __FreeBSD__
+ carp_demote_shutdown();
+ if (env->sc_flags & F_DEMOTE)
+ carp_demote_reset(env->sc_demote_group, 128);
++#endif
- iev = ptr;
- ibuf = &iev->ibuf;
-@@ -685,6 +690,10 @@
- */
- reconfigure();
- break;
-+ case IMSG_CTL_LOG_VERBOSE:
-+ memcpy(&verbose, imsg.data, sizeof(verbose));
-+ log_verbose(verbose);
-+ break;
- default:
- log_debug("main_dispatch_pfe: unexpected imsg %d",
- imsg.hdr.type);
-@@ -988,6 +997,7 @@
- if (timercmp(&tv_next, &tv, >))
- bcopy(&tv_next, &tv, sizeof(tv));
+ free(env->sc_ps);
+ free(env);
+@@ -375,12 +407,15 @@
+ parent_dispatch_pfe(int fd, struct privsep_proc *p, struct imsg *imsg)
+ {
+ struct relayd *env = p->p_env;
++#ifndef __FreeBSD__
+ struct ctl_demote demote;
+ struct ctl_netroute crt;
++#endif
+ u_int v;
+ char *str = NULL;
-+ event_del(ev);
- event_set(ev, fd, event, fn, arg);
- event_add(ev, &tv);
+ switch (imsg->hdr.type) {
++#ifndef __FreeBSD__
+ case IMSG_DEMOTE:
+ IMSG_SIZE_CHECK(imsg, &demote);
+ memcpy(&demote, imsg->data, sizeof(demote));
+@@ -391,6 +426,7 @@
+ memcpy(&crt, imsg->data, sizeof(crt));
+ pfe_route(env, &crt);
+ break;
++#endif
+ case IMSG_CTL_RESET:
+ IMSG_SIZE_CHECK(imsg, &v);
+ memcpy(&v, imsg->data, sizeof(v));
+@@ -432,9 +468,11 @@
+ proc_compose_imsg(ps, PROC_HCE, -1, IMSG_SCRIPT,
+ -1, &scr, sizeof(scr));
+ break;
++#ifndef __FreeBSD__
+ case IMSG_SNMPSOCK:
+ (void)snmp_setsock(env, p->p_id);
+ break;
++#endif
+ case IMSG_CFG_DONE:
+ if (env->sc_reload)
+ env->sc_reload--;
+@@ -645,6 +683,7 @@
+ return (NULL);
}
-@@ -1145,6 +1155,7 @@
- }
- pn->key = strdup(pk->key);
- if (pn->key == NULL) {
-+ free(pn);
- log_warn("out of memory");
- return (NULL);
- }
-@@ -1370,3 +1381,24 @@
- return (0);
++#ifndef __FreeBSD__
+ struct netroute *
+ route_find(struct relayd *env, objid_t id)
+ {
+@@ -666,6 +705,7 @@
+ return (rt);
+ return (NULL);
}
-+
-+void
-+socket_rlimit(int maxfd)
-+{
-+ struct rlimit rl;
-+
-+ if (getrlimit(RLIMIT_NOFILE, &rl) == -1)
-+ fatal("socket_rlimit: failed to get resource limit");
-+ log_debug("socket_rlimit: max open files %d", rl.rlim_max);
-+
-+ /*
-+ * Allow the maximum number of open file descriptors for this
-+ * login class (which should be the class "daemon" by default).
-+ */
-+ if (maxfd == -1)
-+ rl.rlim_cur = rl.rlim_max;
-+ else
-+ rl.rlim_cur = MAX(rl.rlim_max, (rlim_t)maxfd);
-+ if (setrlimit(RLIMIT_NOFILE, &rl) == -1)
-+ fatal("socket_rlimit: failed to set resource limit");
-+}
++#endif
+
+ struct host *
+ host_findbyname(struct relayd *env, const char *name)
+@@ -840,7 +880,11 @@
+ {
+ switch (type) {
+ case DIGEST_SHA1:
++#ifdef __FreeBSD__
++ return (SHA1_Data(data, len, buf));
++#else
+ return (SHA1Data(data, len, buf));
++#endif
+ break;
+ case DIGEST_MD5:
+ return (MD5Data(data, len, buf));
+@@ -1077,9 +1121,17 @@
+ bnd->bnd_proto == IPPROTO_TCP ? SOCK_STREAM : SOCK_DGRAM,
+ bnd->bnd_proto)) == -1)
+ goto fail;
++#ifdef SO_BINDANY
+ if (setsockopt(s, SOL_SOCKET, SO_BINDANY,
+ &v, sizeof(v)) == -1)
+ goto fail;
++#else
++#ifdef IP_BINDANY
++ if (setsockopt(s, IPPROTO_IP, IP_BINDANY,
++ &v, sizeof(v)) == -1)
++ goto fail;
++#endif
++#endif
+ if (bind(s, (struct sockaddr *)&bnd->bnd_ss,
+ bnd->bnd_ss.ss_len) == -1)
+ goto fail;