From owner-svn-soc-all@FreeBSD.ORG Sun Aug 10 05:31:09 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B405B534 for ; Sun, 10 Aug 2014 05:31:09 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 84F8E2758 for ; Sun, 10 Aug 2014 05:31:09 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7A5V9pp067679 for ; Sun, 10 Aug 2014 05:31:09 GMT (envelope-from seiya@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7A5V8OW067428 for svn-soc-all@FreeBSD.org; Sun, 10 Aug 2014 05:31:08 GMT (envelope-from seiya@FreeBSD.org) Date: Sun, 10 Aug 2014 05:31:08 GMT Message-Id: <201408100531.s7A5V8OW067428@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to seiya@FreeBSD.org using -f From: seiya@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272156 - in soc2014/seiya/bootsplash/sys: conf modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Aug 2014 05:31:09 -0000 Author: seiya Date: Sun Aug 10 05:31:07 2014 New Revision: 272156 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272156 Log: some enhancements Modified: soc2014/seiya/bootsplash/sys/conf/NOTES soc2014/seiya/bootsplash/sys/conf/files soc2014/seiya/bootsplash/sys/modules/Makefile Modified: soc2014/seiya/bootsplash/sys/conf/NOTES ============================================================================== --- soc2014/seiya/bootsplash/sys/conf/NOTES Sun Aug 10 03:09:35 2014 (r272155) +++ soc2014/seiya/bootsplash/sys/conf/NOTES Sun Aug 10 05:31:07 2014 (r272156) @@ -1393,6 +1393,7 @@ options FB_DEBUG # Frame buffer debugging device splash # Splash screen and screen saver support +device bsplash # Enhanced splash screen # Various screen savers. device blank_saver Modified: soc2014/seiya/bootsplash/sys/conf/files ============================================================================== --- soc2014/seiya/bootsplash/sys/conf/files Sun Aug 10 03:09:35 2014 (r272155) +++ soc2014/seiya/bootsplash/sys/conf/files Sun Aug 10 05:31:07 2014 (r272156) @@ -1375,7 +1375,7 @@ dev/fb/fb_if.m standard dev/fb/splash.c optional sc splash dev/fb/bsplash.c optional sc bsplash -dev/fb/bmp.c optional sc bsplash +dev/fb/bmp.c optional sc splash | sc bsplash dev/fdt/fdt_common.c optional fdt dev/fdt/fdt_slicer.c optional fdt cfi | fdt nand dev/fdt/fdt_static_dtb.S optional fdt fdt_dtb_static \ Modified: soc2014/seiya/bootsplash/sys/modules/Makefile ============================================================================== --- soc2014/seiya/bootsplash/sys/modules/Makefile Sun Aug 10 03:09:35 2014 (r272155) +++ soc2014/seiya/bootsplash/sys/modules/Makefile Sun Aug 10 05:31:07 2014 (r272156) @@ -53,7 +53,7 @@ ${_bktr} \ ${_bm} \ bridgestp \ - bsplash \ + ${_bsplash} \ bwi \ bwn \ cam \ @@ -657,6 +657,7 @@ _arcmsr= arcmsr _asmc= asmc _bktr= bktr +_bsplash= bsplash _bxe= bxe _cardbus= cardbus _cbb= cbb From owner-svn-soc-all@FreeBSD.ORG Sun Aug 10 09:11:45 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8F3CAA38 for ; Sun, 10 Aug 2014 09:11:45 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7B73F2B39 for ; Sun, 10 Aug 2014 09:11:45 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7A9Bjs3083662 for ; Sun, 10 Aug 2014 09:11:45 GMT (envelope-from seiya@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7A9Bjl7083118 for svn-soc-all@FreeBSD.org; Sun, 10 Aug 2014 09:11:45 GMT (envelope-from seiya@FreeBSD.org) Date: Sun, 10 Aug 2014 09:11:45 GMT Message-Id: <201408100911.s7A9Bjl7083118@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to seiya@FreeBSD.org using -f From: seiya@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272163 - soc2014/seiya/bootsplash/sys/boot/forth MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Aug 2014 09:11:45 -0000 Author: seiya Date: Sun Aug 10 09:11:44 2014 New Revision: 272163 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272163 Log: fix default loader.conf Modified: soc2014/seiya/bootsplash/sys/boot/forth/loader.conf Modified: soc2014/seiya/bootsplash/sys/boot/forth/loader.conf ============================================================================== --- soc2014/seiya/bootsplash/sys/boot/forth/loader.conf Sun Aug 10 08:35:42 2014 (r272162) +++ soc2014/seiya/bootsplash/sys/boot/forth/loader.conf Sun Aug 10 09:11:44 2014 (r272163) @@ -38,9 +38,8 @@ bitmap_type="splash_image_data" # and place it on the module_path bsplash_load="NO" # Set this to YES to enable enhanced bootsplash! -# bsplash_first_image="/boot/splash/foo/bg.bmp" # an image drawn before animation -# bsplash_animation_images="/boot/splash/foo/animation%.bmp" # animation images -# bsplash_animation_fps="15" # frame per second +bsplash_image_load="NO" +bsplash_image_type="bsplash_image" ############################################################## From owner-svn-soc-all@FreeBSD.ORG Sun Aug 10 10:09:08 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6269B7AC for ; Sun, 10 Aug 2014 10:09:08 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 449DE212D for ; Sun, 10 Aug 2014 10:09:08 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7AA98xE007812 for ; Sun, 10 Aug 2014 10:09:08 GMT (envelope-from shonali@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7AA97RX007782 for svn-soc-all@FreeBSD.org; Sun, 10 Aug 2014 10:09:07 GMT (envelope-from shonali@FreeBSD.org) Date: Sun, 10 Aug 2014 10:09:07 GMT Message-Id: <201408101009.s7AA97RX007782@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to shonali@FreeBSD.org using -f From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272164 - soc2014/shonali/head/contrib/bsnmp/snmpd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Aug 2014 10:09:08 -0000 Author: shonali Date: Sun Aug 10 10:09:07 2014 New Revision: 272164 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272164 Log: Removed redundant host to network byte order conversion in trap.c Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c Sun Aug 10 09:11:44 2014 (r272163) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c Sun Aug 10 10:09:07 2014 (r272164) @@ -116,13 +116,13 @@ t->version = TRAPSINK_V2; switch (t->index.len) { - /* IPv4 - Check if there is a better way of determining address type */ - case 6: + case SNMP_UDP_ADDR_SIZ: trapsink_create_sock(t); + break; - /* IPv6 - Check if there is a better way of determining address type */ - case 18: + case SNMP_UDP_ADDRv6_SIZ: trapsink_create_sockv6(t); + break; default: return (NULL); @@ -191,11 +191,7 @@ memset(&sa, 0, sizeof(sa)); sa.sin6_len = sizeof(sa); sa.sin6_family = AF_INET6; - /* Host to network byte order not reqd - check */ - *(sa.sin6_addr.s6_addr) = (t->index.subs[0] << 120) | (t->index.subs[1] << 112) | (t->index.subs[2] << 104) | (t->index.subs[3] << 96) | (t->index.subs[4] << 88) | - (t->index.subs[5] << 80) | (t->index.subs[6] << 72) | (t->index.subs[7] << 64) | (t->index.subs[8] << 56) | - (t->index.subs[9] << 48) | (t->index.subs[10] << 40) | (t->index.subs[11] << 32) | (t->index.subs[12] << 24) | - (t->index.subs[13] << 16) | (t->index.subs[14] << 8) | t->index.subs[15]; + inet_pton(AF_INET6, &(t->index.subs), &(sa.sin6_addr.s6_addr)); sa.sin6_port = htons(t->index.subs[16]); char dst[INET6_ADDRSTRLEN]; @@ -810,12 +806,7 @@ memset(&sa6, 0, sizeof(sa6)); sa6.sin6_len = sizeof(sa6); sa6.sin6_family = AF_INET6; - /* Host to network byte order not reqd - check */ - *(sa6.sin6_addr.s6_addr) = (addrs->address.address6[0] << 120) | (addrs->address.address6[1] << 112) | (addrs->address.address6[2] << 104) | - (addrs->address.address6[3] << 96) | (addrs->address.address6[4] << 88) | - (addrs->address.address6[5] << 80) | (addrs->address.address6[6] << 72) | (addrs->address.address6[7] << 64) | (addrs->address.address6[8] << 56) | - (addrs->address.address6[9] << 48) | (addrs->address.address6[10] << 40) | (addrs->address.address6[11] << 32) | (addrs->address.address6[12] << 24) | - (addrs->address.address6[13] << 16) | (addrs->address.address6[14] << 8) | addrs->address.address6[15]; + inet_pton(AF_INET6, &(addrs->address.address6), &(sa6.sin6_addr.s6_addr)); sa6.sin6_port = htons(addrs->address.address6[16]) << 8 | htons(addrs->address.address6[17]) << 0; char dst[INET6_ADDRSTRLEN]; From owner-svn-soc-all@FreeBSD.ORG Sun Aug 10 10:11:34 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A25907DD for ; Sun, 10 Aug 2014 10:11:34 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8F3CF21B2 for ; Sun, 10 Aug 2014 10:11:34 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7AABYf7020847 for ; Sun, 10 Aug 2014 10:11:34 GMT (envelope-from shonali@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7AABYlA020718 for svn-soc-all@FreeBSD.org; Sun, 10 Aug 2014 10:11:34 GMT (envelope-from shonali@FreeBSD.org) Date: Sun, 10 Aug 2014 10:11:34 GMT Message-Id: <201408101011.s7AABYlA020718@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to shonali@FreeBSD.org using -f From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272165 - soc2014/shonali/head/contrib/bsnmp/snmpd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Aug 2014 10:11:34 -0000 Author: shonali Date: Sun Aug 10 10:11:33 2014 New Revision: 272165 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272165 Log: Made corrections in the switch statements(missing a break;) Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c Sun Aug 10 10:09:07 2014 (r272164) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c Sun Aug 10 10:11:33 2014 (r272165) @@ -765,7 +765,6 @@ int target_activate_address(struct target_address *addrs) { - /* XXX - IPv4/IPv6 - Check if there is a better way of determining address type */ struct sockaddr_in sa; struct sockaddr_in6 sa6; @@ -794,7 +793,7 @@ (void)close(addrs->socket); return (SNMP_ERR_GENERR); } - + break; case TransportAddressIPv6 : if ((addrs->socket = socket(PF_INET6, SOCK_DGRAM, 0)) == -1) { @@ -816,7 +815,7 @@ (void)close(addrs->socket); return (SNMP_ERR_GENERR); } - + break; default: return (NULL); From owner-svn-soc-all@FreeBSD.ORG Sun Aug 10 10:42:05 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A9CCEBDC for ; Sun, 10 Aug 2014 10:42:05 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9603824E6 for ; Sun, 10 Aug 2014 10:42:05 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7AAg5Du012321 for ; Sun, 10 Aug 2014 10:42:05 GMT (envelope-from shonali@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7AAg4lh012294 for svn-soc-all@FreeBSD.org; Sun, 10 Aug 2014 10:42:04 GMT (envelope-from shonali@FreeBSD.org) Date: Sun, 10 Aug 2014 10:42:04 GMT Message-Id: <201408101042.s7AAg4lh012294@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to shonali@FreeBSD.org using -f From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272166 - soc2014/shonali/head/contrib/bsnmp/snmpd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Aug 2014 10:42:05 -0000 Author: shonali Date: Sun Aug 10 10:42:04 2014 New Revision: 272166 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272166 Log: Corrections in export.c, trans_udpv6.c & trap.c Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/export.c soc2014/shonali/head/contrib/bsnmp/snmpd/trans_udpv6.c soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/export.c ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/export.c Sun Aug 10 10:11:33 2014 (r272165) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/export.c Sun Aug 10 10:42:04 2014 (r272166) @@ -216,6 +216,7 @@ void ip6_commit(struct snmp_context *ctx __unused) { + free(ctx->scratch->ptr1); } /* Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/trans_udpv6.c ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/trans_udpv6.c Sun Aug 10 10:11:33 2014 (r272165) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/trans_udpv6.c Sun Aug 10 10:42:04 2014 (r272166) @@ -34,7 +34,7 @@ * * $Begemot: bsnmp/snmpd/trans_udpv6.c,v 1.5 2005/10/04 08:46:56 brandt_h Exp $ * - * UDP transport + * UDP transport over IPv6 */ #include #include @@ -238,29 +238,29 @@ static ssize_t udpv6_recv(struct tport *tp, struct port_input *pi) { - struct in6_addr *laddr; - int ret; - struct msghdr msg; - char cbuf[CMSG_SPACE(sizeof(struct in6_addr))]; - struct cmsghdr *cmsgp; - - memset(cbuf, 0, CMSG_SPACE(sizeof(struct in6_addr))); - msg.msg_control = cbuf; - msg.msg_controllen = CMSG_SPACE(sizeof(struct in6_addr)); - cmsgp = CMSG_FIRSTHDR(&msg); - cmsgp->cmsg_len = CMSG_LEN(sizeof(struct in6_addr)); - cmsgp->cmsg_level = IPPROTO_IPV6; - cmsgp->cmsg_type = IP_SENDSRCADDR; /* Check for ipv6 alternative */ - laddr = (struct in6_addr *)CMSG_DATA(cmsgp); + struct in6_addr *laddr; + int ret; + struct msghdr msg; + char cbuf[CMSG_SPACE(sizeof(struct in6_addr))]; + struct cmsghdr *cmsgp; + + memset(cbuf, 0, CMSG_SPACE(sizeof(struct in6_addr))); + msg.msg_control = cbuf; + msg.msg_controllen = CMSG_SPACE(sizeof(struct in6_addr)); + cmsgp = CMSG_FIRSTHDR(&msg); + cmsgp->cmsg_len = CMSG_LEN(sizeof(struct in6_addr)); + cmsgp->cmsg_level = IPPROTO_IPV6; + cmsgp->cmsg_type = IP_SENDSRCADDR; /* Check for ipv6 alternative */ + laddr = (struct in6_addr *)CMSG_DATA(cmsgp); - ret = recv_v6dgram(pi, laddr); + ret = recv_v6dgram(pi, laddr); - if (laddr->s6_addr == 0) { - msg.msg_control = NULL; - msg.msg_controllen = 0; - } + if (laddr->s6_addr == 0) { + msg.msg_control = NULL; + msg.msg_controllen = 0; + } - return (ret); + return (ret); } /* @@ -313,9 +313,9 @@ if (msg.msg_flags & MSG_TRUNC) { /* truncated - drop */ - snmpd_stats.silentDrops++; - snmpd_stats.inTooLong++; - return (-1); + snmpd_stats.silentDrops++; + snmpd_stats.inTooLong++; + return (-1); } pi->length = (size_t)len; Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c Sun Aug 10 10:11:33 2014 (r272165) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c Sun Aug 10 10:42:04 2014 (r272166) @@ -344,7 +344,7 @@ u_int sub, u_int iidx, enum snmp_op op) { struct trapsink *t; - u_char ipa[4]; + u_char ipa[16]; int32_t port; struct asn_oid idx; struct trapsink_dep *tdep; From owner-svn-soc-all@FreeBSD.ORG Sun Aug 10 11:03:57 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 20659DDB for ; Sun, 10 Aug 2014 11:03:57 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0B1842658 for ; Sun, 10 Aug 2014 11:03:57 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7AB3umJ065339 for ; Sun, 10 Aug 2014 11:03:56 GMT (envelope-from shonali@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7AB3uYI065337 for svn-soc-all@FreeBSD.org; Sun, 10 Aug 2014 11:03:56 GMT (envelope-from shonali@FreeBSD.org) Date: Sun, 10 Aug 2014 11:03:56 GMT Message-Id: <201408101103.s7AB3uYI065337@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to shonali@FreeBSD.org using -f From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272167 - soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Aug 2014 11:03:57 -0000 Author: shonali Date: Sun Aug 10 11:03:56 2014 New Revision: 272167 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272167 Log: Exceeding code moved to the next line in bsnmptools.c Modified: soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Modified: soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c ============================================================================== --- soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Sun Aug 10 10:42:04 2014 (r272166) +++ soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Sun Aug 10 11:03:56 2014 (r272167) @@ -1770,7 +1770,9 @@ { if (GET_OUTPUT(snmptoolctx) == OUTPUT_VERBOSE) fprintf(stdout, "%s : ", syntax_strings[SNMP_SYNTAX_IPADDRESS].str); - fprintf(stdout, "%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7], ip[8], ip[9], ip[10], ip[11], ip[12], ip[13], ip[14], ip[15]); + fprintf(stdout, "%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u", + ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7], ip[8], + ip[9], ip[10], ip[11], ip[12], ip[13], ip[14], ip[15]); } static void From owner-svn-soc-all@FreeBSD.ORG Sun Aug 10 15:29:12 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E866C53D for ; Sun, 10 Aug 2014 15:29:11 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D49F82E75 for ; Sun, 10 Aug 2014 15:29:11 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7AFTBvj091797 for ; Sun, 10 Aug 2014 15:29:11 GMT (envelope-from shonali@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7AFT9s6091342 for svn-soc-all@FreeBSD.org; Sun, 10 Aug 2014 15:29:09 GMT (envelope-from shonali@FreeBSD.org) Date: Sun, 10 Aug 2014 15:29:09 GMT Message-Id: <201408101529.s7AFT9s6091342@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to shonali@FreeBSD.org using -f From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272169 - soc2014/shonali/head/contrib/bsnmp/snmpd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Aug 2014 15:29:12 -0000 Author: shonali Date: Sun Aug 10 15:29:09 2014 New Revision: 272169 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272169 Log: Added begemotSnmpdPortv6Table to BEGEMOT-SNMPD for IPv6, full compile Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/BEGEMOT-SNMPD.txt soc2014/shonali/head/contrib/bsnmp/snmpd/config.c soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.config soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.h soc2014/shonali/head/contrib/bsnmp/snmpd/trans_udpv6.c soc2014/shonali/head/contrib/bsnmp/snmpd/tree.def Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/BEGEMOT-SNMPD.txt ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/BEGEMOT-SNMPD.txt Sun Aug 10 14:55:39 2014 (r272168) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/BEGEMOT-SNMPD.txt Sun Aug 10 15:29:09 2014 (r272169) @@ -200,7 +200,7 @@ ::= { begemotTrapSinkEntry 3 } -- --- SNMP port table +-- SNMP port table for IPv4 -- begemotSnmpdPortTable OBJECT-TYPE SYNTAX SEQUENCE OF BegemotSnmpdPortEntry @@ -218,32 +218,23 @@ DESCRIPTION "An entry in the table with descriptions of UDP ports to listen on for SNMP messages." - INDEX { begemotSnmpdPortAddressType, begemotSnmpdPortAddress, begemotSnmpdPortPort } + INDEX { begemotSnmpdPortAddress, begemotSnmpdPortPort } ::= { begemotSnmpdPortTable 1 } BegemotSnmpdPortEntry ::= SEQUENCE { - begemotSnmpdPortAddress InetAddress, - begemotSnmpdPortAddressType InetAddressType, + begemotSnmpdPortAddress InetAddressIPv4, begemotSnmpdPortPort INTEGER, begemotSnmpdPortStatus INTEGER } begemotSnmpdPortAddress OBJECT-TYPE - SYNTAX InetAddress + SYNTAX InetAddressIPv4 MAX-ACCESS not-accessible STATUS current DESCRIPTION - "The IP address to bind to." + "The IPv4 address to bind to." ::= { begemotSnmpdPortEntry 1 } -begemotSnmpdPortAddressType OBJECT-TYPE - SYNTAX InetAddressType - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "The address type of the given host." - ::= { begemotSnmpdPortEntry 4 } - begemotSnmpdPortPort OBJECT-TYPE SYNTAX INTEGER (1..65535) MAX-ACCESS not-accessible @@ -579,4 +570,56 @@ begemotSnmpdTransLsock OBJECT IDENTIFIER ::= { begemotSnmpdTransportMappings 3 } begemotSnmpdTransIpv6Udp OBJECT IDENTIFIER ::= { begemotSnmpdTransportMappings 4 } +-- +-- SNMP port table for IPv6 +-- +begemotSnmpdPortv6Table OBJECT-TYPE + SYNTAX SEQUENCE OF begemotSnmpdPortv6Entry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A table with descriptions of UDP ports to listen on + for SNMP messages over IPv6." + ::= { begemotSnmpdObjects 11 } + +begemotSnmpdPortv6Entry OBJECT-TYPE + SYNTAX begemotSnmpdPortv6Entry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "An entry in the table with descriptions of UDP ports to + listen on for SNMP messages over IPv6." + INDEX { begemotSnmpdPortv6Address, begemotSnmpdPortv6Port } + ::= { begemotSnmpdPortv6Table 1 } + +begemotSnmpdPortv6Entry ::= SEQUENCE { + begemotSnmpdPortv6Address InetAddressIPv6, + begemotSnmpdPortv6Port INTEGER, + begemotSnmpdPortv6Status INTEGER +} + +begemotSnmpdPortv6Address OBJECT-TYPE + SYNTAX InetAddressIPv6 + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "The IPv6 address to bind to." + ::= { begemotSnmpdPortv6Entry 1 } + +begemotSnmpdPortv6Port OBJECT-TYPE + SYNTAX INTEGER (1..65535) + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "The UDP port to listen on for SNMP messages over IPv6." + ::= { begemotSnmpdPortv6Entry 2 } + +begemotSnmpdPortv6Status OBJECT-TYPE + SYNTAX INTEGER { valid(1), invalid(2) } + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "Set status to 1 to create entry, set it to 2 to delete it." + ::= { begemotSnmpdPortv6Entry 3 } + END Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/config.c ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/config.c Sun Aug 10 14:55:39 2014 (r272168) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/config.c Sun Aug 10 15:29:09 2014 (r272169) @@ -892,17 +892,17 @@ gethost(strval, ip); if (addr_type == AF_INET){ - if (oid->len + 4 > ASN_MAXOIDLEN) + if (oid->len + SNMP_IPv4_ADDR_SIZ > ASN_MAXOIDLEN) report("index too long"); - for (i = 0; i < 4; i++) + for (i = 0; i < SNMP_IPv4_ADDR_SIZ; i++) oid->subs[oid->len++] = ip[i]; gettoken(); } else if (addr_type == AF_INET6){ - if (oid->len + 16 > ASN_MAXOIDLEN) + if (oid->len + SNMP_IPv6_ADDR_SIZ > ASN_MAXOIDLEN) report("index too long"); - for (i = 0; i < 16; i++) + for (i = 0; i < SNMP_IPv6_ADDR_SIZ; i++) oid->subs[oid->len++] = ip[i]; gettoken(); } Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.config ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.config Sun Aug 10 14:55:39 2014 (r272168) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.config Sun Aug 10 15:29:09 2014 (r272169) @@ -71,10 +71,10 @@ begemotSnmpdCommunityDisable = 1 # open standard SNMP ports -begemotSnmpdPortStatus.[$(host)].161.1 = 1 -begemotSnmpdPortStatus.127.0.0.1.161.1 = 1 -begemotSnmpdPortStatus.0:0:0:0:0:0:0:0.161.2 = 1 -begemotSnmpdPortStatus.0:0:0:0:0:0:0:1.161.2 = 1 +begemotSnmpdPortStatus.[$(host)].161 = 1 +begemotSnmpdPortStatus.127.0.0.1.161 = 1 +begemotSnmpdPortv6Status.0:0:0:0:0:0:0:0.161 = 1 +begemotSnmpdPortv6Status.0:0:0:0:0:0:0:1.161 = 1 # open a unix domain socket begemotSnmpdLocalPortStatus."/var/run/snmpd.sock" = 1 Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.h ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.h Sun Aug 10 14:55:39 2014 (r272168) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.h Sun Aug 10 15:29:09 2014 (r272169) @@ -180,6 +180,8 @@ * Transport domain */ #define TRANS_NAMELEN 64 +#define SNMP_IPv4_ADDR_SIZ 4 +#define SNMP_IPv6_ADDR_SIZ 16 struct transport_def { const char *name; /* name of this transport */ @@ -239,10 +241,10 @@ int auth_traps; /* source address for V1 traps */ - u_char trap1addr[4]; + u_char trap1addr[SNMP_IPv4_ADDR_SIZ]; /* ipv6 source address for V1 traps */ - u_char trap1addr6[16]; + u_char trap1addr6[SNMP_IPv6_ADDR_SIZ]; /* version enable flags */ uint32_t version_enable; Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/trans_udpv6.c ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/trans_udpv6.c Sun Aug 10 14:55:39 2014 (r272168) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/trans_udpv6.c Sun Aug 10 15:29:09 2014 (r272169) @@ -351,7 +351,7 @@ * Port table */ int -op_snmp_port(struct snmp_context *ctx, struct snmp_value *value, +op_snmp_port_v6(struct snmp_context *ctx, struct snmp_value *value, u_int sub, u_int iidx, enum snmp_op op) { asn_subid_t which = value->var.subs[sub-1]; Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/tree.def ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/tree.def Sun Aug 10 14:55:39 2014 (r272168) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/tree.def Sun Aug 10 15:29:09 2014 (r272169) @@ -130,11 +130,10 @@ # Port table # (4 begemotSnmpdPortTable - (1 begemotSnmpdPortEntry : InetAddressType OCTETSTRING | InetAddress INTEGER op_snmp_port - (1 begemotSnmpdPortAddress OCTETSTRING | InetAddress) + (1 begemotSnmpdPortEntry : OCTETSTRING | InetAddressIPv4 INTEGER op_snmp_port + (1 begemotSnmpdPortAddress OCTETSTRING | InetAddressIPv4) (2 begemotSnmpdPortPort UNSIGNED32) (3 begemotSnmpdPortStatus INTEGER GET SET) - (4 begemotSnmpdPortAddressType InetAddressType) )) # # Community table @@ -192,6 +191,13 @@ (3 begemotSnmpdTransLsock OID op_transport_dummy) (4 begemotSnmpdTransIpv6Udp OID op_transport_dummy) ) + + (11 begemotSnmpdPortv6Table + (1 begemotSnmpdPortv6Entry : OCTETSTRING | InetAddressIPv6 INTEGER op_snmp_port_v6 + (1 begemotSnmpdPortv6Address OCTETSTRING | InetAddressIPv6) + (2 begemotSnmpdPortv6Port UNSIGNED32) + (3 begemotSnmpdPortv6Status INTEGER GET SET) + )) ) (2 begemotSnmpdDefs (1 begemotSnmpdAgent From owner-svn-soc-all@FreeBSD.ORG Sun Aug 10 18:51:07 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 5D6A848B for ; Sun, 10 Aug 2014 18:51:07 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3DE4A22D0 for ; Sun, 10 Aug 2014 18:51:07 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7AIp7t2065459 for ; Sun, 10 Aug 2014 18:51:07 GMT (envelope-from shonali@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7AIp5ei065169 for svn-soc-all@FreeBSD.org; Sun, 10 Aug 2014 18:51:05 GMT (envelope-from shonali@FreeBSD.org) Date: Sun, 10 Aug 2014 18:51:05 GMT Message-Id: <201408101851.s7AIp5ei065169@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to shonali@FreeBSD.org using -f From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272175 - in soc2014/shonali/head: contrib/bsnmp/lib contrib/bsnmp/snmpd usr.sbin/bsnmpd/tools/bsnmptools usr.sbin/bsnmpd/tools/libbsnmptools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Aug 2014 18:51:07 -0000 Author: shonali Date: Sun Aug 10 18:51:05 2014 New Revision: 272175 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272175 Log: Added SNMP_SYNTAX_IP6ADDRESS to snmp_syntax, added calls to ipv6 functions Modified: soc2014/shonali/head/contrib/bsnmp/lib/snmp.h soc2014/shonali/head/contrib/bsnmp/snmpd/export.c soc2014/shonali/head/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Modified: soc2014/shonali/head/contrib/bsnmp/lib/snmp.h ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/lib/snmp.h Sun Aug 10 17:08:28 2014 (r272174) +++ soc2014/shonali/head/contrib/bsnmp/lib/snmp.h Sun Aug 10 18:51:05 2014 (r272175) @@ -57,6 +57,7 @@ SNMP_SYNTAX_COUNTER, SNMP_SYNTAX_GAUGE, /* == UNSIGNED32 */ SNMP_SYNTAX_TIMETICKS, + SNMP_SYNTAX_IP6ADDRESS, /* v2 additions */ SNMP_SYNTAX_COUNTER64, Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/export.c ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/export.c Sun Aug 10 17:08:28 2014 (r272174) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/export.c Sun Aug 10 18:51:05 2014 (r272175) @@ -366,8 +366,8 @@ switch (oid->len) { - case 4: - if (sub + 4 > oid->len) + case SNMP_IPv4_ADDR_SIZ: + if (sub + SNMP_IPv4_ADDR_SIZ > oid->len) goto err; pval = va_arg(ap, u_int8_t *); for (i = 0; i < 4; i++) { @@ -376,8 +376,8 @@ pval[i] = oid->subs[sub++]; } - case 16: - if (sub + 16 > oid->len) + case SNMP_IPv6_ADDR_SIZ: + if (sub + SNMP_IPv6_ADDR_SIZ > oid->len) goto err; pval = va_arg(ap, u_int8_t *); for (i = 0; i < 16; i++) { Modified: soc2014/shonali/head/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c ============================================================================== --- soc2014/shonali/head/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c Sun Aug 10 17:08:28 2014 (r272174) +++ soc2014/shonali/head/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c Sun Aug 10 18:51:05 2014 (r272175) @@ -775,6 +775,8 @@ return (parse_int(value, val)); case SNMP_SYNTAX_IPADDRESS: return (parse_ip(value, val)); + case SNMP_SYNTAX_IP6ADDRESS: + return (parse_ip6(value, val)); case SNMP_SYNTAX_COUNTER: return (parse_counter(value, val)); case SNMP_SYNTAX_GAUGE: @@ -898,6 +900,8 @@ return (parse_int_string(object, str + len)); case SNMP_SYNTAX_IPADDRESS: return (parse_ip(&(object->val), str + len)); + case SNMP_SYNTAX_IP6ADDRESS: + return (parse_ip6(&(object->val), str + len)); case SNMP_SYNTAX_COUNTER: return (parse_counter(&(object->val), str + len)); case SNMP_SYNTAX_GAUGE: @@ -977,7 +981,7 @@ { int8_t i; - dst->syntax = src->syntax; + dst->syntax = SNMP_SYNTAX_IP6ADDRESS; for (i = 0; i < 16; i++) dst->v.ipaddress6[i] = src->v.ipaddress6[i]; @@ -1050,6 +1054,9 @@ case SNMP_SYNTAX_IPADDRESS: add_ip_syntax(dst, src); break; + case SNMP_SYNTAX_IP6ADDRESS: + add_ip6_syntax(dst, src); + break; case SNMP_SYNTAX_OCTETSTRING: add_octstring_syntax(dst, src); break; Modified: soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c ============================================================================== --- soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Sun Aug 10 17:08:28 2014 (r272174) +++ soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Sun Aug 10 18:51:05 2014 (r272175) @@ -1246,6 +1246,8 @@ &(object->val.var))); case SNMP_SYNTAX_IPADDRESS: return (snmp_ip2asn_oid(ptr, &(object->val.var))); + case SNMP_SYNTAX_IP6ADDRESS: + return (snmp_ipv62asn_oid(ptr, &(object->val.var))); case SNMP_SYNTAX_COUNTER: /* FALLTHROUGH */ case SNMP_SYNTAX_GAUGE: @@ -1849,6 +1851,10 @@ case SNMP_SYNTAX_IPADDRESS: snmp_output_ipaddress(snmptoolctx, val->v.ipaddress); break; + + case SNMP_SYNTAX_IP6ADDRESS: + snmp_output_ip6address(snmptoolctx, val->v.ipaddress6); + break; case SNMP_SYNTAX_COUNTER: snmp_output_counter(snmptoolctx, val->v.uint32); @@ -1926,6 +1932,7 @@ snmp_output_index(struct snmp_toolinfo *snmptoolctx, struct index *stx, struct asn_oid *oid) { + uint8_t *ip; uint32_t bytes = 1; uint64_t cnt64; struct asn_oid temp, out; @@ -1963,25 +1970,22 @@ case SNMP_SYNTAX_IPADDRESS: if (temp.len < 4) return (-1); - uint8_t *ip; - switch (temp.len) { - case 4: - ip = malloc(sizeof(u_int8_t)*4); - for (bytes = 0; bytes < 4; bytes++) - ip[bytes] = temp.subs[bytes]; - snmp_output_ipaddress(snmptoolctx, ip); - bytes = 4; - case 16: - ip = malloc(sizeof(u_int8_t)*16); - for (bytes = 0; bytes < 16; bytes++) - ip[bytes] = temp.subs[bytes]; - snmp_output_ipaddress(snmptoolctx, ip); - bytes = 16; - - default: - return (NULL); - } - break; + ip = malloc(sizeof(u_int8_t)*SNMP_IPv4_ADDR_SIZ); + for (bytes = 0; bytes < 4; bytes++) + ip[bytes] = temp.subs[bytes]; + snmp_output_ipaddress(snmptoolctx, ip); + bytes = 4; + break; + + case SNMP_SYNTAX_IP6ADDRESS: + if (temp.len < 16) + return (-1); + ip = malloc(sizeof(u_int8_t)*SNMP_IPv6_ADDR_SIZ); + for (bytes = 0; bytes < 16; bytes++) + ip[bytes] = temp.subs[bytes]; + snmp_output_ip6address(snmptoolctx, ip); + bytes = 16; + break; case SNMP_SYNTAX_COUNTER: snmp_output_counter(snmptoolctx, temp.subs[0]); From owner-svn-soc-all@FreeBSD.ORG Sun Aug 10 19:01:05 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 0A50374A for ; Sun, 10 Aug 2014 19:01:05 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D044A2495 for ; Sun, 10 Aug 2014 19:01:04 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7AJ14AL002288 for ; Sun, 10 Aug 2014 19:01:04 GMT (envelope-from shonali@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7AJ14gu002283 for svn-soc-all@FreeBSD.org; Sun, 10 Aug 2014 19:01:04 GMT (envelope-from shonali@FreeBSD.org) Date: Sun, 10 Aug 2014 19:01:04 GMT Message-Id: <201408101901.s7AJ14gu002283@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to shonali@FreeBSD.org using -f From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272179 - in soc2014/shonali/head/usr.sbin/bsnmpd/tools: bsnmptools libbsnmptools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Aug 2014 19:01:05 -0000 Author: shonali Date: Sun Aug 10 19:01:03 2014 New Revision: 272179 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272179 Log: Corrections in bsnmpget.c & bsnmptools.c Modified: soc2014/shonali/head/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Modified: soc2014/shonali/head/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c ============================================================================== --- soc2014/shonali/head/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c Sun Aug 10 18:13:50 2014 (r272178) +++ soc2014/shonali/head/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c Sun Aug 10 19:01:03 2014 (r272179) @@ -637,7 +637,7 @@ value->v.ipaddress6[i] = (uint8_t) v; } - value->syntax = SNMP_SYNTAX_IPADDRESS; + value->syntax = SNMP_SYNTAX_IP6ADDRESS; return (0); } Modified: soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c ============================================================================== --- soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Sun Aug 10 18:13:50 2014 (r272178) +++ soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Sun Aug 10 19:01:03 2014 (r272179) @@ -116,6 +116,7 @@ { "Counter32", SNMP_SYNTAX_COUNTER }, { "Gauge", SNMP_SYNTAX_GAUGE }, { "TimeTicks", SNMP_SYNTAX_TIMETICKS }, + { "IPv6Address", SNMP_SYNTAX_IP6ADDRESS }, { "Counter64", SNMP_SYNTAX_COUNTER64 }, { "Unknown", SNMP_SYNTAX_UNKNOWN }, }; @@ -1771,7 +1772,7 @@ snmp_output_ip6address(struct snmp_toolinfo *snmptoolctx, uint8_t *ip) { if (GET_OUTPUT(snmptoolctx) == OUTPUT_VERBOSE) - fprintf(stdout, "%s : ", syntax_strings[SNMP_SYNTAX_IPADDRESS].str); + fprintf(stdout, "%s : ", syntax_strings[SNMP_SYNTAX_IP6ADDRESS].str); fprintf(stdout, "%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7], ip[8], ip[9], ip[10], ip[11], ip[12], ip[13], ip[14], ip[15]); From owner-svn-soc-all@FreeBSD.ORG Sun Aug 10 19:07:56 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 874BB88D for ; Sun, 10 Aug 2014 19:07:56 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 732BC24C3 for ; Sun, 10 Aug 2014 19:07:56 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7AJ7uoo007963 for ; Sun, 10 Aug 2014 19:07:56 GMT (envelope-from shonali@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7AJ7uLD007960 for svn-soc-all@FreeBSD.org; Sun, 10 Aug 2014 19:07:56 GMT (envelope-from shonali@FreeBSD.org) Date: Sun, 10 Aug 2014 19:07:56 GMT Message-Id: <201408101907.s7AJ7uLD007960@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to shonali@FreeBSD.org using -f From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272180 - soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Aug 2014 19:07:56 -0000 Author: shonali Date: Sun Aug 10 19:07:55 2014 New Revision: 272180 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272180 Log: Code corrections in bsnmptools.c Modified: soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Modified: soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c ============================================================================== --- soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Sun Aug 10 19:01:03 2014 (r272179) +++ soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Sun Aug 10 19:07:55 2014 (r272180) @@ -1971,7 +1971,7 @@ case SNMP_SYNTAX_IPADDRESS: if (temp.len < 4) return (-1); - ip = malloc(sizeof(u_int8_t)*SNMP_IPv4_ADDR_SIZ); + ip = malloc(sizeof(u_int8_t)*4); for (bytes = 0; bytes < 4; bytes++) ip[bytes] = temp.subs[bytes]; snmp_output_ipaddress(snmptoolctx, ip); @@ -1981,7 +1981,7 @@ case SNMP_SYNTAX_IP6ADDRESS: if (temp.len < 16) return (-1); - ip = malloc(sizeof(u_int8_t)*SNMP_IPv6_ADDR_SIZ); + ip = malloc(sizeof(u_int8_t)*16); for (bytes = 0; bytes < 16; bytes++) ip[bytes] = temp.subs[bytes]; snmp_output_ip6address(snmptoolctx, ip); From owner-svn-soc-all@FreeBSD.ORG Mon Aug 11 10:28:00 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id CBA36FBF for ; Mon, 11 Aug 2014 10:28:00 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B78872090 for ; Mon, 11 Aug 2014 10:28:00 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7BAS0wR048643 for ; Mon, 11 Aug 2014 10:28:00 GMT (envelope-from zkorchev@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7BAS0qD048631 for svn-soc-all@FreeBSD.org; Mon, 11 Aug 2014 10:28:00 GMT (envelope-from zkorchev@FreeBSD.org) Date: Mon, 11 Aug 2014 10:28:00 GMT Message-Id: <201408111028.s7BAS0qD048631@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to zkorchev@FreeBSD.org using -f From: zkorchev@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272199 - soc2014/zkorchev/freebsd_head/lib/libsol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Aug 2014 10:28:00 -0000 Author: zkorchev Date: Mon Aug 11 10:27:59 2014 New Revision: 272199 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272199 Log: libsol basic xml support Modified: soc2014/zkorchev/freebsd_head/lib/libsol/sol.c soc2014/zkorchev/freebsd_head/lib/libsol/sol.h Modified: soc2014/zkorchev/freebsd_head/lib/libsol/sol.c ============================================================================== --- soc2014/zkorchev/freebsd_head/lib/libsol/sol.c Mon Aug 11 08:58:35 2014 (r272198) +++ soc2014/zkorchev/freebsd_head/lib/libsol/sol.c Mon Aug 11 10:27:59 2014 (r272199) @@ -40,7 +40,8 @@ yajl_gen g; struct { - unsigned char stack[SOL_DEPTH_MAX]; + char *stack[SOL_DEPTH_MAX]; + //unsigned char stack[SOL_DEPTH_MAX]; unsigned depth; int first; } c; @@ -51,11 +52,52 @@ // TODO track whether a key or a value is expected and generate error when appropriate? +static void xml_open(struct sol_stream *restrict stream) +{ + const char *tag; + + if (stream->ctx.c.depth == 0) return; + + tag = stream->ctx.c.stack[stream->ctx.c.depth - 1]; + if (!tag && (stream->ctx.c.depth > 1)) + tag = stream->ctx.c.stack[stream->ctx.c.depth - 2]; + + if (tag) + printf("<%s>", tag); + else + printf(""); +} + +static void xml_close(struct sol_stream *restrict stream) +{ + char *tag; + int clean = 0; + + if (stream->ctx.c.depth == 0) return; + + tag = stream->ctx.c.stack[stream->ctx.c.depth - 1]; + if (tag) + { + clean = 1; + stream->ctx.c.depth -= 1; + } + else if (stream->ctx.c.depth > 1) + tag = stream->ctx.c.stack[stream->ctx.c.depth - 2]; + + if (tag) + { + printf("", tag); + if (clean) free(tag); + } + else + printf(""); +} + static void padding(const struct sol_stream *restrict stream) { #define T4 "\t\t\t\t" static const char buf[] = "\n" T4 T4 T4 T4 T4 T4 T4 T4; - printf("%.*s", 1 + stream->ctx.c.depth - stream->ctx.c.stack[0], buf); + printf("%.*s", 1 + stream->ctx.c.depth - (stream->ctx.c.stack[0] != 0), buf); #undef T4 } @@ -89,6 +131,8 @@ else if (!strcmp(format, "xml")) { stream->f = SOL_XML; + stream->ctx.c.depth = 0; + printf("\n"); } else return 0; @@ -149,6 +193,9 @@ break; case SOL_XML: + if (stream->ctx.c.depth == SOL_DEPTH_MAX) + return 1; + stream->ctx.c.stack[stream->ctx.c.depth++] = 0; break; } @@ -158,6 +205,7 @@ int sol_array_end(struct sol_stream *restrict stream) { flush(stream); + switch (stream->f) { case SOL_JSON: @@ -170,6 +218,12 @@ padding(stream); printf("]"); break; + + case SOL_XML: + stream->ctx.c.depth -= 1; + if (stream->ctx.c.stack[stream->ctx.c.depth - 1]) + stream->ctx.c.depth -= 1; + break; } return 0; @@ -190,7 +244,11 @@ padding(stream); printf("{"); } - stream->ctx.c.stack[stream->ctx.c.depth++] = 1; + stream->ctx.c.stack[stream->ctx.c.depth++] = (void *)1; // TODO fix this + break; + + case SOL_XML: + xml_open(stream); break; } @@ -200,6 +258,7 @@ int sol_map_end(struct sol_stream *restrict stream) { flush(stream); + switch (stream->f) { case SOL_JSON: @@ -215,12 +274,16 @@ } stream->ctx.c.first = 0; break; + + case SOL_XML: + xml_close(stream); + break; } return 0; } -int sol_map_key(struct sol_stream *restrict stream, const char *key, size_t length) +int sol_map_key(struct sol_stream *restrict stream, const char *restrict key, size_t length) { switch (stream->f) { @@ -232,6 +295,26 @@ padding(stream); printf("%s", key); // TODO escape special chars break; + + case SOL_XML: + { + char *copy; + + if (stream->ctx.c.depth == SOL_DEPTH_MAX) + return 1; + + copy = malloc(length + 1); + if (!copy) return 1; + memcpy(copy, key, length); + copy[length] = 0; + + stream->ctx.c.stack[stream->ctx.c.depth] = copy; + if (stream->ctx.c.stack[stream->ctx.c.depth]) + stream->ctx.c.depth += 1; + else + return 1; + } + break; } return 0; @@ -264,6 +347,34 @@ printf("\"%s\"", data); } break; + + case SOL_XML: + { + size_t i; + + xml_open(stream); + for(i = 0; i < length; ++i) + switch (data[i]) + { + case '<': + fputs("<", stdout); + break; + + case '>': + fputs(">", stdout); + break; + + case '&': + fputs("&", stdout); + break; + + default: + putchar(data[i]); + break; + } + xml_close(stream); + } + break; } return 0; @@ -287,6 +398,12 @@ printf("%s", (value ? "true" : "false")); } break; + + case SOL_XML: + xml_open(stream); + printf(value ? "true" : "false"); + xml_close(stream); + break; } return 0; @@ -310,6 +427,12 @@ printf("%" PRId64, value); } break; + + case SOL_XML: + xml_open(stream); + printf("%" PRId64, value); + xml_close(stream); + break; } return 0; @@ -337,6 +460,12 @@ printf("%" PRIx64, value); } break; + + case SOL_XML: + xml_open(stream); + printf("%" PRIx64, value); + xml_close(stream); + break; } return 0; @@ -361,6 +490,12 @@ printf("%f", value); } break; + + case SOL_XML: + xml_open(stream); + printf("%f", value); + xml_close(stream); + break; } return 0; Modified: soc2014/zkorchev/freebsd_head/lib/libsol/sol.h ============================================================================== --- soc2014/zkorchev/freebsd_head/lib/libsol/sol.h Mon Aug 11 08:58:35 2014 (r272198) +++ soc2014/zkorchev/freebsd_head/lib/libsol/sol.h Mon Aug 11 10:27:59 2014 (r272199) @@ -35,7 +35,8 @@ enum sol_format f; struct { - unsigned char stack[SOL_DEPTH_MAX]; + char *stack[SOL_DEPTH_MAX]; + //unsigned char stack[SOL_DEPTH_MAX]; unsigned depth; int first; } c; @@ -51,7 +52,7 @@ int sol_map_start(struct sol_stream *restrict stream); int sol_map_end(struct sol_stream *restrict stream); -int sol_map_key(struct sol_stream *restrict stream, const char *key, size_t length); +int sol_map_key(struct sol_stream *restrict stream, const char *restrict key, size_t length); int sol_map_keyi(struct sol_stream *restrict stream, intmax_t number); int sol_boolean(struct sol_stream *restrict stream, unsigned char value); From owner-svn-soc-all@FreeBSD.ORG Mon Aug 11 12:35:06 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 022B6588 for ; Mon, 11 Aug 2014 12:35:06 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E3CDE2071 for ; Mon, 11 Aug 2014 12:35:05 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7BCZ5FY028244 for ; Mon, 11 Aug 2014 12:35:05 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7BCZ53j027848 for svn-soc-all@FreeBSD.org; Mon, 11 Aug 2014 12:35:05 GMT (envelope-from dpl@FreeBSD.org) Date: Mon, 11 Aug 2014 12:35:05 GMT Message-Id: <201408111235.s7BCZ53j027848@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272200 - soc2014/dpl/netmap-ipfwjit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Aug 2014 12:35:06 -0000 Author: dpl Date: Mon Aug 11 12:35:05 2014 New Revision: 272200 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272200 Log: Added flag to avoid warning with certain compatibility problems. Modified: soc2014/dpl/netmap-ipfwjit/Makefile.kipfw Modified: soc2014/dpl/netmap-ipfwjit/Makefile.kipfw ============================================================================== --- soc2014/dpl/netmap-ipfwjit/Makefile.kipfw Mon Aug 11 10:27:59 2014 (r272199) +++ soc2014/dpl/netmap-ipfwjit/Makefile.kipfw Mon Aug 11 12:35:05 2014 (r272200) @@ -75,7 +75,7 @@ #Flags needed for jit.cc J_CFLAGS += $(INCDIRS) $(NETMAP_FLAGS) J_CFLAGS += -DINET -D_KERNEL -D_BSD_SOURCE -DKERNEL_SIDE -DUSERSPACE -J_CFLAGS += -I ../extra/ +J_CFLAGS += -I ../extra/ -Wno-extern-c-compat #ipfw + dummynet section, other parts are not compiled in SRCS_IPFW = ip_fw2.c ip_fw_pfil.c ip_fw_sockopt.c From owner-svn-soc-all@FreeBSD.ORG Mon Aug 11 12:35:42 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1F2C25A7 for ; Mon, 11 Aug 2014 12:35:42 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0C5D02076 for ; Mon, 11 Aug 2014 12:35:42 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7BCZfqB052568 for ; Mon, 11 Aug 2014 12:35:41 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7BCZfmO052123 for svn-soc-all@FreeBSD.org; Mon, 11 Aug 2014 12:35:41 GMT (envelope-from dpl@FreeBSD.org) Date: Mon, 11 Aug 2014 12:35:41 GMT Message-Id: <201408111235.s7BCZfmO052123@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272201 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Aug 2014 12:35:42 -0000 Author: dpl Date: Mon Aug 11 12:35:41 2014 New Revision: 272201 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272201 Log: Moved JIT compilation to beggining of function. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c Mon Aug 11 12:35:05 2014 (r272200) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c Mon Aug 11 12:35:41 2014 (r272201) @@ -264,6 +264,20 @@ int ipfw_chk(struct ip_fw_args *args) { + struct ip_fw_chain *chain = &V_layer3_chain; + + /* If we haven't, JIT-compile the actions to be executed per-rule */ + if (compiledfuncptr == 0) { + IPFW_PF_RLOCK(chain); + if (! V_ipfw_vnet_ready) { /* shutting down, leave NOW. */ + IPFW_PF_RUNLOCK(chain); + return (IP_FW_PASS); /* accept */ + } + compiledfuncptr = compile_code(args, chain); + IPFW_PF_RUNLOCK(chain); + } else + return compiledfuncptr(args, chain); + /* * Local variables holding state while processing a packet: * @@ -363,19 +377,6 @@ */ int dyn_dir = MATCH_UNKNOWN; ipfw_dyn_rule *q = NULL; - struct ip_fw_chain *chain = &V_layer3_chain; - - /* If we haven't, JIT-compile the actions to be executed per-rule */ - if (compiledfuncptr == 0) { - IPFW_PF_RLOCK(chain); - if (! V_ipfw_vnet_ready) { /* shutting down, leave NOW. */ - IPFW_PF_RUNLOCK(chain); - return (IP_FW_PASS); /* accept */ - } - compiledfuncptr = compile_code(args, chain); - IPFW_PF_RUNLOCK(chain); - } else - return compiledfuncptr(args, chain); /* * We store in ulp a pointer to the upper layer protocol header. From owner-svn-soc-all@FreeBSD.ORG Mon Aug 11 13:25:54 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1D9DD94E for ; Mon, 11 Aug 2014 13:25:54 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0A32C2765 for ; Mon, 11 Aug 2014 13:25:54 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7BDPrJv094996 for ; Mon, 11 Aug 2014 13:25:53 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7BDPrXC094994 for svn-soc-all@FreeBSD.org; Mon, 11 Aug 2014 13:25:53 GMT (envelope-from dpl@FreeBSD.org) Date: Mon, 11 Aug 2014 13:25:53 GMT Message-Id: <201408111325.s7BDPrXC094994@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272204 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Aug 2014 13:25:54 -0000 Author: dpl Date: Mon Aug 11 13:25:53 2014 New Revision: 272204 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272204 Log: Improved comments, added struct types to be used by the compiler, and removed the __inline attribute of auxiliary functions. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Mon Aug 11 12:59:55 2014 (r272203) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Mon Aug 11 13:25:53 2014 (r272204) @@ -1,4 +1,3 @@ -/* Includes dpl XXX -- we have to clean them up*/ #include __FBSDID("$FreeBSD: head/sys/netpfil/ipfw/ip_fw2.c 243711 2012-11-30 19:36:55Z melifaro $"); @@ -30,8 +29,7 @@ #include /* XXX for in_cksum */ -// dpl XXX. The real function will be inserted by the JIT. -// dpl XXX. For now, we put the chain there, that could change, tough. +// The real function will be inserted by the JIT. int ipfw_chk_jit(struct ip_fw_args *args, struct ip_fw_chain *chain); // Functions used by JIT, external to our code. @@ -40,10 +38,21 @@ // Declarations of some needed structs. struct mbuf; +struct ifnet; +struct in_addr; +struct ip; struct ip_fw_args; struct ip_fw_chain; struct ip_fw; struct ipfw_insn; +ipfw_insn_if; +ipfw_dyn_rule; + +#ifndef __FreeBSD__ + struct bsd_ucred; +#else + struct ucred; +#endif /* * Some macros used in the various matching options. @@ -60,13 +69,31 @@ /* This macro needs the calling function to have a tablearg argument */ #define IP_FW_ARG_TABLEARG(a) (((a) == IP_FW_TABLEARG) ? tablearg : (a)) +/* + * PULLUP_TO(len, p, T) makes sure that len + sizeof(T) is contiguous, + * then it sets p to point at the offset "len" in the mbuf. WARNING: the + * pointer might become stale after other pullups (but we never use it + * this way). + */ +#define PULLUP_TO(_len, p, T) PULLUP_LEN(_len, p, sizeof(T)) +#define PULLUP_LEN(_len, p, T) \ +do { \ + int x = (_len) + T; \ + if ((m)->m_len < x) { \ + args->m = m = m_pullup(m, x); \ + if (m == NULL) \ + goto pullup_failed; \ + } \ + p = (mtod(m, char *) + (_len)); \ +} while (0) + /* Needed vars defined at ip_fw2.c */ VNET_DECLARE(int, V_ipfw_vnet_ready); /* * Auxiliar functions. */ -static __inline int +static int icmptype_match(struct icmphdr *icmp, ipfw_insn_u32 *cmd) { int type = icmp->icmp_type; @@ -316,7 +343,7 @@ /* * ipv6 specific aux funtions here... */ -static __inline int +static int icmp6type_match (int type, ipfw_insn_u32 *cmd) { return (type <= ICMP6_MAXTYPE && (cmd->d[type/32] & (1<<(type%32)) ) ); @@ -1134,12 +1161,7 @@ static IPFW_RULES_INLINE int rule_tcpopts(int *match, u_int hlen, void *ulp, uint8_t proto, u_short offset, ipfw_insn *cmd, struct mbuf *m, struct ip_fw_args *args) { - /* - * PULLUP_TO(len, p, T) makes sure that len + sizeof(T) is contiguous, - * then it sets p to point at the offset "len" in the mbuf. WARNING: the - * pointer might become stale after other pullups (but we never use it - * this way). - */ + /* Modified PULLUP_TO, returns 1 if error */ do { int x = (hlen) + (TCP(ulp)->th_off << 2); if ((m)->m_len < x) { @@ -1278,7 +1300,6 @@ verify_path(*src_ip, NULL, args->f_id.fib))); } -/* dpl XXX We could pass pointers to struct in_addr at in_localaddr() */ static IPFW_RULES_INLINE void rule_antispoof(int *match, struct ifnet *oif, u_int hlen, int is_ipv4, int is_ipv6, struct in_addr *src_ip, struct ip_fw_args *args, struct mbuf *m) { From owner-svn-soc-all@FreeBSD.ORG Mon Aug 11 16:00:16 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 63F2FEEA for ; Mon, 11 Aug 2014 16:00:16 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 507F22C7E for ; Mon, 11 Aug 2014 16:00:16 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7BG0G9W080038 for ; Mon, 11 Aug 2014 16:00:16 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7BG0FHx079652 for svn-soc-all@FreeBSD.org; Mon, 11 Aug 2014 16:00:15 GMT (envelope-from dpl@FreeBSD.org) Date: Mon, 11 Aug 2014 16:00:15 GMT Message-Id: <201408111600.s7BG0FHx079652@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272213 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Aug 2014 16:00:16 -0000 Author: dpl Date: Mon Aug 11 16:00:15 2014 New Revision: 272213 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272213 Log: Moved functions to a place where structs that could be used are already defined. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Mon Aug 11 15:41:55 2014 (r272212) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Mon Aug 11 16:00:15 2014 (r272213) @@ -32,9 +32,6 @@ // The real function will be inserted by the JIT. int ipfw_chk_jit(struct ip_fw_args *args, struct ip_fw_chain *chain); -// Functions used by JIT, external to our code. -int printf(const char * restrict format, ...); - // Declarations of some needed structs. struct mbuf; @@ -54,6 +51,10 @@ struct ucred; #endif +// Functions used by JIT, external to our code. +int printf(const char * restrict format, ...); + + /* * Some macros used in the various matching options. * L3HDR maps an ipv4 pointer into a layer3 header pointer of type T From owner-svn-soc-all@FreeBSD.ORG Mon Aug 11 16:05:23 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7AA7FF96 for ; Mon, 11 Aug 2014 16:05:23 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 673A02D79 for ; Mon, 11 Aug 2014 16:05:23 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7BG5NQ7087129 for ; Mon, 11 Aug 2014 16:05:23 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7BG5MtB087127 for svn-soc-all@FreeBSD.org; Mon, 11 Aug 2014 16:05:22 GMT (envelope-from dpl@FreeBSD.org) Date: Mon, 11 Aug 2014 16:05:22 GMT Message-Id: <201408111605.s7BG5MtB087127@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272214 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Aug 2014 16:05:23 -0000 Author: dpl Date: Mon Aug 11 16:05:22 2014 New Revision: 272214 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272214 Log: Comment Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Mon Aug 11 16:00:15 2014 (r272213) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Mon Aug 11 16:05:22 2014 (r272214) @@ -51,7 +51,7 @@ struct ucred; #endif -// Functions used by JIT, external to our code. +// Functions used by JIT, external. int printf(const char * restrict format, ...); From owner-svn-soc-all@FreeBSD.ORG Mon Aug 11 16:20:56 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A22296B7 for ; Mon, 11 Aug 2014 16:20:56 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 82ED82EF5 for ; Mon, 11 Aug 2014 16:20:56 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7BGKu4x027793 for ; Mon, 11 Aug 2014 16:20:56 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7BGKuoO027791 for svn-soc-all@FreeBSD.org; Mon, 11 Aug 2014 16:20:56 GMT (envelope-from dpl@FreeBSD.org) Date: Mon, 11 Aug 2014 16:20:56 GMT Message-Id: <201408111620.s7BGKuoO027791@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272215 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Aug 2014 16:20:56 -0000 Author: dpl Date: Mon Aug 11 16:20:55 2014 New Revision: 272215 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272215 Log: Setting up the JIT compilation env. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Mon Aug 11 16:05:22 2014 (r272214) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Mon Aug 11 16:20:55 2014 (r272215) @@ -35,7 +35,6 @@ using namespace llvm; class ipfwJIT { - private: Module *mod; Function *func; LLVMContext con; @@ -47,16 +46,80 @@ Type *int8Ty; Type *int16Ty; Type *int32Ty; + PointerType *int8PtrTy; // JIT Compiled Vars + // Loop control. Value *match; Value *l; Value *done; Value *f_pos; Value *retval; - // Functions used by our JITed code. + // Packet matching variables. + Value *mbuf; + Value *ip; + Value *ucred; + Value *ucred_lookup; + Value *oif; + Value *hlen; //unsigned + Value *offset; //unsigned + Value *ip6f_mf; //unsigned + + // Local copies of vars. + // On optimization, unused ones will not be included. + Value *proto; //unsigned + Value *src_port; //unsigned + Value *dst_port; //unsigned + Value *src_ip; + Value *dest_ip; + Value *iplen; //unsigned + Value *pktlen; + Value *etype; //unsigned + Value *dyn_dir; + Value *q; + Value *ulp; + + Value *is_ipv4; + Value *is_ipv6; + Value *icmp6_type; //unsigned + Value *ext_hd; //unsigned + + // This sets up some vars, at star time. + Function *look_pkt; + + // Auxiliary functions used by our JITed code. + Function *is_icmp_query; + Function *flags_match; + Function *ipopts_match; + Function *tcpopts_match; Function *iface_match; + Function *verify_path; +#ifdef INET6 + Function *icmp6type_match; + Function *search_ip6_addr_net; + Function *flow6id_match; + Function *verify_path6; + Function *is_icmp6_query; + Function *send_reject6; +#endif /* INET6 */ + Function *send_reject; + Function *check_uidgid; + Function *set_match; + Function *jump_fast; + + // Used structs + StructType *ifnetTy; + StructType *in_addrTy; + StructType *ipTy; + StructType *ip_fw_argsTy; + StructType *ip_fw_chainTy; + StructType *ip_fwTy; + StructType *ip_fw_insnTy; + StructType *ipfw_dyn_ruleTy; + StructType *ipfw_insn_ifTy; + StructType *mbufTy; + StructType *ucredTy; // Load the bc for JIT compilation. Module *loadbc(std::string name) @@ -79,32 +142,131 @@ // Create the needed variables to perform pkt filtering. int - setEnv() + setEnv(struct ip_fw_args *args, struct ip_fw_chain *chain) { // Get Type objects int8Ty = Type::getInt8Ty(con); int16Ty = Type::getInt16Ty(con); int32Ty = Type::getInt32Ty(con); + int8PtrTy = PointerType::getUnqual(int8Ty); // Get StrucType from bitcode. + ipfw_dyn_ruleTy = mod->getTypeByName("ipfw_dyn_rule"); + ifnetTy = mod->getTypeByName("ifnet"); + in_addrTy = mod->getTypeByName("in_addr"); + ipTy = mod->getTypeByName("ip"); + ip_fw_argsTy = mod->getTypeByName("ip_fw_args"); + ip_fw_chainTy = mod->getTypeByName("ip_fw_chain"); + ip_fwTy = mod->getTypeByName("ip_fw"); + ip_fw_insnTy = mod->getTypeByName("ip_fw_insn"); + ipfw_insn_ifTy = mod->getTypeByName("ipfw_insn_if"); + mbufTy = mod->getTypeByName("mbuf"); +#ifndef __FreeBSD__ + ucredTy = mod->getTypeByName("bsd_ucred"); +#else + ucredTy = mod->getTypeByName("ucred"); +#endif /* __FreeBSD__ */ - // Store vars. + // Allocate vars. match = irb.CreateAlloca(int32Ty); l = irb.CreateAlloca(int32Ty); done = irb.CreateAlloca(int32Ty); + irb.CreateStore(ConstantInt::get(int32Ty, 0), done); f_pos = irb.CreateAlloca(int32Ty); + irb.CreateStore(ConstantInt::get(int32Ty, 0), f_pos); retval = irb.CreateAlloca(int32Ty); + irb.CreateStore(ConstantInt::get(int32Ty, 0), retval); + + mbuf = irb.CreateAlloca(mbufTy); // Init: args->m + // ip = mtod(m, struct ip *) + // #define mtod(m, t) ((t)((m)->m_data)) + ip = irb.CreateAlloca(ipTy); + + ucred = irb.CreateAlloca(ucredTy); // Init: NULL if type ucred. +#ifdef __FreeBSD__ + irb.CreateStore(ConstantPointerNull::get(null), ucred); +#endif + + ucred_lookup = irb.CreateAlloca(int32Ty); + irb.CreateStore(ConstantInt::get(int32Ty, 0), ucred_lookup); + + oif = irb.CreateAlloca(ifnetTy); // Init: args->oif + + hlen = irb.CreateAlloca(int32Ty); + irb.CreateStore(ConstantInt::get(int32Ty, 0), hlen); + + offset = irb.CreateAlloca(int16Ty); + irb.CreateStore(ConstantInt::get(int16Ty, 0), offset); + + ip6f_mf = irb.CreateAlloca(int16Ty); + irb.CreateStore(ConstantInt::get(int16Ty, 0), ip6f_mf); + + proto = irb.CreateAlloca(int8Ty); + + src_port = irb.CreateAlloca(int16Ty); + irb.CreateStore(ConstantInt::get(int16Ty, 0), src_port); + dst_port = irb.CreateAlloca(int16Ty); + irb.CreateStore(ConstantInt::get(int16Ty, 0), dst_port); + + src_ip = irb.CreateAlloca(in_addrTy); + dest_ip = irb.CreateAlloca(in_addrTy); + + iplen = irb.CreateAlloca(int16Ty); + irb.CreateStore(ConstantInt::get(int16Ty, 0), iplen); - // Create needed GlobalVariables. + pktlen = irb.CreateAlloca(int32Ty); + + etype = irb.CreateAlloca(int16Ty); + irb.CreateStore(ConstantInt::get(int32Ty, 0), etype); + + dyn_dir = irb.CreateAlloca(int32Ty); + irb.CreateStore(ConstantInt::get(int32Ty, MATCH_UNKNOWN), dyn_dir); + + q = irb.CreateAlloca(ipfw_dyn_ruleTy); + irb.CreateStore(ConstantPointerNull::get(null), q); + + // There are no (void *), we use i8* + ulp = irb.CreateAlloca(int8PtrTy); //Init: NULL + irb.CreateStore(ConstantPointerNull::get(null), ulp); + + is_ipv4 = irb.CreateAlloca(int32Ty); + irb.CreateStore(ConstantInt::get(int32Ty, 0), is_ipv4); + is_ipv6 = irb.CreateAlloca(int32Ty); + irb.CreateStore(ConstantInt::get(int32Ty, 0), is_ipv6); + icmp6_type = irb.CreateAlloca(int8Ty); + irb.CreateStore(ConstantInt::get(int8Ty, 0), icmp6_type); + ext_hd = irb.CreateAlloca(int16Ty); + irb.CreateStore(ConstantInt::get(int16Ty, 0), ext_hd); // Get Function defs from bitcode. + // All of them are auxiliary functions. + look_pkt = mod->getFunction("look_pkt"); + is_icmp_query = mod->getFunction("is_icmp_query"); + flags_match = mod->getFunction("flags_match"); + ipopts_match = mod->getFunction("ipopts_match"); + tcpopts_match = mod->getFunction("tcpopts_match"); iface_match = mod->getFunction("iface_match"); + verify_path = mod->getFunction("verify_path"); + +#ifdef INET6 + icmp6type_match = mod->getFunction("icmp6type_match"); + search_ip6_addr_net = mod->getFunction("search_ip6_addr_net"); + flow6id_match = mod->getFunction("flow6id_match"); + verify_path6 = mod->getFunction("verify_path6"); + is_icmp6_query = mod->getFunction("is_icmp6_query"); + send_reject6 = mod->getFunction("send_reject6"); +#endif /* INET6 */ + + send_reject = mod->getFunction("send_reject"); + check_uidgid = mod->getFunction("check_uidgid"); + set_match = mod->getFunction("set_match"); + jump_fast = mod->getFunction("jump_fast"); return (0); } public: - ipfwJIT(): irb(con) + ipfwJIT(struct ip_fw_args *args, struct ip_fw_chain *chain): irb(con) { // Create the module and load the code. mod = loadbc("ip_fw_rules.bc"); @@ -118,8 +280,8 @@ // Set the IRBuilder to insert instructions after the basic block. irb.SetInsertPoint(entry); // Get struct types, and store vars - setEnv(); - // From on on, it's just a matter of emitting the code for each rule/action. + setEnv(args, chain); + // Emitting the code for each rule/action now-> } ~ipfwJIT() { @@ -212,15 +374,15 @@ extern "C" funcptr compile_code(struct ip_fw_args *args, struct ip_fw_chain *chain) { - int res; - ipfwJIT comp; + ipfwJIT comp(args, chain); + int res; int f_pos = 0; - int retval = 0; - // Iterate through the rules. + // Fill up needed variables type. + comp.emit_lookpkt(); - int done = 0; /* flag to exit the outer loop */ + // Iterate through the rules. int pktlen = args->m->m_pkthdr.len; // For all the number of rules. From owner-svn-soc-all@FreeBSD.ORG Mon Aug 11 16:36:19 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B8A13F12 for ; Mon, 11 Aug 2014 16:36:19 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9928C217B for ; Mon, 11 Aug 2014 16:36:19 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7BGaJ5k065271 for ; Mon, 11 Aug 2014 16:36:19 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7BGaJd4065259 for svn-soc-all@FreeBSD.org; Mon, 11 Aug 2014 16:36:19 GMT (envelope-from dpl@FreeBSD.org) Date: Mon, 11 Aug 2014 16:36:19 GMT Message-Id: <201408111636.s7BGaJd4065259@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272216 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Aug 2014 16:36:19 -0000 Author: dpl Date: Mon Aug 11 16:36:18 2014 New Revision: 272216 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272216 Log: Corrected some wrong first drafts of the emit_* functions. Removed some of the firewall's logic to iterate the rules, and moved some comments to avoid errors. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Mon Aug 11 16:20:55 2014 (r272215) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Mon Aug 11 16:36:18 2014 (r272216) @@ -289,26 +289,25 @@ delete mod; } + // Returns the pointer to the compiled function. funcptr - functionPtr() + getFuncPtr() { - MachineCodeInfo machinf; - - ExecutionEngine::runJITOnFunction(func, &machinf); - return ((funcptr)machinf.address()); + return ((funcptr)NULL); } + // Emits all the code necessary to fill in some vars. + // XXX Should we emit that? Or should we create a function call instead? int - emit_nop(int *matchptr) + emit_lookpkt() { - // static IPFW_RULES_INLINE void - // rule_nop(int *match) - // { - // *match = 1; - // } - - *matchptr = 1; + //irb.CreateCall(); + return (0); + } + int + emit_nop() + { irb.CreateStore(ConstantInt::get(int32Ty, 1), match); return (0); } @@ -316,56 +315,21 @@ int emit_forward_mac(u_int8_t opcode) { - // printf("ipfw: opcode %d unimplemented\n", - // opcode); - - Function *printf; - - printf = mod->getFunction("printf"); - irb.CreateCall(printf, "ipfw: opcode %d unimplemented\n", opcode); + printf("Compilation error:\n"); + printf("ipfwjitter: opcode %d unimplemented\n", opcode); + printf("Compilation continues.\n"); return (0); } int emit_jail() { - // static IPFW_RULES_INLINE void - // rule_jail(int * match, u_short offset, uint8_t proto, ipfw_insn *cmd, struct ip_fw_args *args, int ucred_lookup, void *ucred_cache) - // { - // /* - // * We only check offset == 0 && proto != 0, - // * as this ensures that we have a - // * packet with the ports info. - // */ - // if (offset != 0) - // return; - // if (proto == IPPROTO_TCP || - // proto == IPPROTO_UDP) - // *match = check_uidgid( - // (ipfw_insn_u32 *)cmd, - // args, &ucred_lookup, - // #ifdef __FreeBSD__ - // //(struct bsd_ucred **)&ucred_cache); - // (struct ucred **)&ucred_cache); - // #else - // (void *)&ucred_cache); - // #endif - // } - return (0); } int emit_recv() { - // static IPFW_RULES_INLINE void - // rule_recv(int *match, ipfw_insn *cmd, struct mbuf *m, struct ip_fw_chain *chain, uint32_t *tablearg) - // { - // *match = iface_match(m->m_pkthdr.rcvif, (ipfw_insn_if *)cmd, chain, tablearg); - // } - - irb.CreateStore(irb.CreateCall4(/*STUFF GOING HERE*/ match); - return (0); } @@ -392,39 +356,15 @@ struct ip_fw *f; f = chain->map[f_pos]; - if (V_set_disable & (1 << f->set) ) - continue; - skip_or = 0; // For each different command. for (l = f->cmd_len, cmd = f->cmd ; l > 0 ; l -= cmdlen, cmd += cmdlen) { - int match; - /* - * check_body is a jump target used when we find a - * CHECK_STATE, and need to jump to the body of - * the target rule. - */ - /* check_body: */ cmdlen = F_LEN(cmd); - /* - * An OR block (insn_1 || .. || insn_n) has the - * F_OR bit set in all but the last instruction. - * The first match will set "skip_or", and cause - * the following instructions to be skipped until - * past the one with the F_OR bit clear. - */ - if (skip_or) { /* skip this instruction */ - if ((cmd->len & F_OR) == 0) - skip_or = 0; /* next one is good */ - continue; - } - match = 0; /* set to 1 if we succeed */ - switch (cmd->opcode) { case O_NOP: - comp.emit_nop(&match); + comp.emit_nop(); break; case O_FORWARD_MAC: @@ -437,11 +377,11 @@ comp.emit_jail(); break; -/* XXX case O_RECV: comp.emit_recv(); break; +/* XXX case O_XMIT: comp.emit_xmit(); break; @@ -537,8 +477,7 @@ comp.emit_icmp6type(); break; #endif /* INET6 */ - -/* XXX +/* case O_IPOPT: comp.emit_ipopt(); break; @@ -574,9 +513,6 @@ break; case O_TCPOPTS: - /* if (rule_tcpopts(&match, hlen, ulp, proto, offset, cmd, m, args)) - goto pullup_failed; */ -/* XXX comp.emit_tcpopts(); break; @@ -625,9 +561,9 @@ comp.emit_ipsec(); #endif /* otherwise no match */ -/* XXX break; +/* XXX #ifdef INET6 case O_IP6_SRC: comp.emit_ip6_src(); @@ -750,14 +686,14 @@ comp.emit_skipto(); continue; break; /* NOTREACHED */ -/* XXX +/* XXX case O_CALLRETURN: comp.emit_callreturn(); continue; break; /* NOTREACHED */ - /* XXX + case O_REJECT: comp.emit_reject(); /* FALLTHROUGH */ @@ -803,44 +739,13 @@ comp.emit_reass(); break; + */ default: panic("-- unknown opcode %d\n", cmd->opcode); } /* end of switch() on opcodes */ - /* - * if we get here with l=0, then match is irrelevant. - */ - - if (cmd->len & F_NOT) - match = !match; - - if (match) { - if (cmd->len & F_OR) - skip_or = 1; - } else { - if (!(cmd->len & F_OR)) /* not an OR block, */ - break; /* try next rule */ - } - } /* end of inner loop, scan opcodes */ - - if (done) - break; - -/* next_rule:; */ /* try next rule */ - } /* end of outer for, scan rules */ - if (done) { - struct ip_fw *rule = chain->map[f_pos]; - /* Update statistics */ - IPFW_INC_RULE_COUNTER(rule, pktlen); - } else { - retval = IP_FW_DENY; - printf("ipfw: ouch!, skip past end of rules, denying packet\n"); - } - // Once we're done iterating through the rules, return the pointer. - - return (0); -} + return (comp.getFuncPtr()); } From owner-svn-soc-all@FreeBSD.ORG Mon Aug 11 18:39:02 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 904BA498 for ; Mon, 11 Aug 2014 18:39:02 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 79906215E for ; Mon, 11 Aug 2014 18:39:02 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7BId2hr032417 for ; Mon, 11 Aug 2014 18:39:02 GMT (envelope-from shonali@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7BId1BP032404 for svn-soc-all@FreeBSD.org; Mon, 11 Aug 2014 18:39:01 GMT (envelope-from shonali@FreeBSD.org) Date: Mon, 11 Aug 2014 18:39:01 GMT Message-Id: <201408111839.s7BId1BP032404@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to shonali@FreeBSD.org using -f From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272224 - in soc2014/shonali/head: contrib/bsnmp/snmpd usr.sbin/bsnmpd/tools/libbsnmptools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Aug 2014 18:39:02 -0000 Author: shonali Date: Mon Aug 11 18:39:00 2014 New Revision: 272224 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272224 Log: Added switch case SNMP_SYNTAX_IP6ADDRESS and calls to ipv6 functions in config.c & export.c Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/config.c soc2014/shonali/head/contrib/bsnmp/snmpd/export.c soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/config.c ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/config.c Mon Aug 11 17:45:41 2014 (r272223) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/config.c Mon Aug 11 18:39:00 2014 (r272224) @@ -801,41 +801,12 @@ sain = (struct sockaddr_in *)(void *)res->ai_addr; sain->sin_addr.s_addr = ntohl(sain->sin_addr.s_addr); inet_ntop(AF_INET, &(sain->sin_addr), *ip, INET_ADDRSTRLEN); - - /* - ip[0] = sain->sin_addr.s_addr >> 24; - ip[1] = sain->sin_addr.s_addr >> 16; - ip[2] = sain->sin_addr.s_addr >> 8; - ip[3] = sain->sin_addr.s_addr >> 0; - */ - break; case AF_INET6 : addr_type = AF_INET6; sain6 = (struct sockaddr_in6 *)(void *)res->ai_addr; - - /* ipv6 implementation of network to host byte order function */ - /* - unsigned char tmp[16]; - if (BYTE_ORDER == LITTLE_ENDIAN) { - tmp[3] = (sain6->sin6_addr.s6_addr[0] << 24) | (sain6->sin6_addr.s6_addr[1] << 16) | (sain6->sin6_addr.s6_addr[2] << 8) | sain6->sin6_addr.s6_addr[3]; - tmp[2] = (sain6->sin6_addr.s6_addr[4] << 24) | (sain6->sin6_addr.s6_addr[5] << 16) | (sain6->sin6_addr.s6_addr[6] << 8) | sain6->sin6_addr.s6_addr[7]; - tmp[1] = (sain6->sin6_addr.s6_addr[8] << 24) | (sain6->sin6_addr.s6_addr[9] << 16) | (sain6->sin6_addr.s6_addr[10] << 8) | sain6->sin6_addr.s6_addr[11]; - tmp[0] = (sain6->sin6_addr.s6_addr[12] << 24) | (sain6->sin6_addr.s6_addr[13] << 16) | (sain6->sin6_addr.s6_addr[14] << 8) | sain6->sin6_addr.s6_addr[15]; - } - - else { - tmp[0] = (sain6->sin6_addr.s6_addr[0] << 24) | (sain6->sin6_addr.s6_addr[1] << 16) | (sain6->sin6_addr.s6_addr[2] << 8) | sain6->sin6_addr.s6_addr[3]; - tmp[1] = (sain6->sin6_addr.s6_addr[4] << 24) | (sain6->sin6_addr.s6_addr[5] << 16) | (sain6->sin6_addr.s6_addr[6] << 8) | sain6->sin6_addr.s6_addr[7]; - tmp[2] = (sain6->sin6_addr.s6_addr[8] << 24) | (sain6->sin6_addr.s6_addr[9] << 16) | (sain6->sin6_addr.s6_addr[10] << 8) | sain6->sin6_addr.s6_addr[11]; - tmp[3] = (sain6->sin6_addr.s6_addr[12] << 24) | (sain6->sin6_addr.s6_addr[13] << 16) | (sain6->sin6_addr.s6_addr[14] << 8) | sain6->sin6_addr.s6_addr[15]; - } - strcpy(sain6->sin6_addr.s6_addr, (unsigned char *)tmp) ; - */ - inet_ntop(AF_INET6, &(sain6->sin6_addr), *ip, INET6_ADDRSTRLEN); - } freeaddrinfo(res); @@ -1025,56 +996,61 @@ parse_syntax_ipaddress(struct snmp_value *value) { int i; + u_char ip[4]; + + if (token == TOK_NUM) { + /* numerical address */ + i = 0; + for (;;) { + if (numval >= 256) + report("ip address part too large"); + value->v.ipaddress[i++] = numval; + if (i == 4) + break; + if (gettoken() != '.') + report("expecting '.' in ip address"); + } + gettoken(); + + } else if (token == TOK_HOST) { + /* host name */ + gethost(strval, ip); + for (i = 0; i < 4; i++) + value->v.ipaddress[i] = ip[i]; + gettoken(); + + } else + report("bad ip address syntax"); +} + +static void +parse_syntax_ip6address(struct snmp_value *value) +{ + int i; u_char ip[16]; - + if (token == TOK_NUM) { /* numerical address */ i = 0; for (;;) { - if (!isxdigit(numval)) { - if (numval >= 256) - report("ip address part too large"); - value->v.ipaddress[i++] = numval; - if (i == 4) - break; - if (gettoken() != '.') - report("expecting '.' in ip address"); - } - - else { - value->v.ipaddress[i++] = numval; - if (i == 16) - break; - if (gettoken() != ':') - report("expecting ':' in ip address"); - } - + value->v.ipaddress6[i++] = numval; + if (i == 16) + break; + if (gettoken() != ':') + report("expecting ':' in ip address"); } gettoken(); - if (i == 4) { - struct in_addr dst; - if (!inet_pton(AF_INET,value->v.ipaddress[i++],(void *)&dst)) - report("ip address not valid"); - } - else if (i == 16) { - struct in6_addr dst; - if (!inet_pton(AF_INET6,value->v.ipaddress[i++],(void *)&dst)) - report("ipv6 address not valid"); - } + + struct in6_addr dst; + if (!inet_pton(AF_INET6, value->v.ipaddress6[i++],(void *)&dst)) + report("ipv6 address not valid"); } else if (token == TOK_HOST) { /* host name */ gethost(strval, ip); - if (addr_type == AF_INET){ - for (i = 0; i < 4; i++) - value->v.ipaddress[i] = ip[i]; - gettoken(); - } - if (addr_type == AF_INET6){ - for (i = 0; i < 16; i++) - value->v.ipaddress[i] = ip[i]; - gettoken(); - } + for (i = 0; i < 16; i++) + value->v.ipaddress6[i] = ip[i]; + gettoken(); } else report("bad ip address syntax"); @@ -1142,6 +1118,10 @@ parse_syntax_ipaddress(&value); break; + case SNMP_SYNTAX_IP6ADDRESS: + parse_syntax_ip6address(&value); + break; + case SNMP_SYNTAX_COUNTER: case SNMP_SYNTAX_GAUGE: case SNMP_SYNTAX_TIMETICKS: Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/export.c ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/export.c Mon Aug 11 17:45:41 2014 (r272223) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/export.c Mon Aug 11 18:39:00 2014 (r272224) @@ -363,34 +363,28 @@ { u_int8_t *pval; u_int i; - - switch (oid->len) { - - case SNMP_IPv4_ADDR_SIZ: - if (sub + SNMP_IPv4_ADDR_SIZ > oid->len) - goto err; - pval = va_arg(ap, u_int8_t *); - for (i = 0; i < 4; i++) { - if (oid->subs[sub] > 0xff) - goto err; - pval[i] = oid->subs[sub++]; - } - - case SNMP_IPv6_ADDR_SIZ: - if (sub + SNMP_IPv6_ADDR_SIZ > oid->len) - goto err; - pval = va_arg(ap, u_int8_t *); - for (i = 0; i < 16; i++) { - pval[i] = oid->subs[sub++]; - } - - default: - return (NULL); - } - + if (sub + SNMP_IPv4_ADDR_SIZ > oid->len) + goto err; + pval = va_arg(ap, u_int8_t *); + for (i = 0; i < 4; i++) { + if (oid->subs[sub] > 0xff) + goto err; + pval[i] = oid->subs[sub++]; + } + break; + } + case SNMP_SYNTAX_IP6ADDRESS: + { + u_int8_t *pval; + u_int i; + if (sub + SNMP_IPv6_ADDR_SIZ > oid->len) + goto err; + pval = va_arg(ap, u_int8_t *); + for (i = 0; i < 16; i++) { + pval[i] = oid->subs[sub++]; + } break; } - case SNMP_SYNTAX_COUNTER: case SNMP_SYNTAX_GAUGE: case SNMP_SYNTAX_TIMETICKS: Modified: soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c ============================================================================== --- soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Mon Aug 11 17:45:41 2014 (r272223) +++ soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Mon Aug 11 18:39:00 2014 (r272224) @@ -1763,8 +1763,9 @@ snmp_output_ipaddress(struct snmp_toolinfo *snmptoolctx, uint8_t *ip) { if (GET_OUTPUT(snmptoolctx) == OUTPUT_VERBOSE) - fprintf(stdout, "%s : ", syntax_strings[SNMP_SYNTAX_IPADDRESS].str); - fprintf(stdout, "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]); + fprintf(stdout, "%s : ", syntax_strings[SNMP_SYNTAX_IPADDRESS].str); + + fprintf(stdout, "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]); } @@ -1772,10 +1773,11 @@ snmp_output_ip6address(struct snmp_toolinfo *snmptoolctx, uint8_t *ip) { if (GET_OUTPUT(snmptoolctx) == OUTPUT_VERBOSE) - fprintf(stdout, "%s : ", syntax_strings[SNMP_SYNTAX_IP6ADDRESS].str); - fprintf(stdout, "%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u", - ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7], ip[8], - ip[9], ip[10], ip[11], ip[12], ip[13], ip[14], ip[15]); + fprintf(stdout, "%s : ", syntax_strings[SNMP_SYNTAX_IP6ADDRESS].str); + + fprintf(stdout, "%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u", + ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7], ip[8], + ip[9], ip[10], ip[11], ip[12], ip[13], ip[14], ip[15]); } static void From owner-svn-soc-all@FreeBSD.ORG Mon Aug 11 19:59:14 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C4A7C3C7 for ; Mon, 11 Aug 2014 19:59:14 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id AF93A2B27 for ; Mon, 11 Aug 2014 19:59:14 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7BJxEI4008627 for ; Mon, 11 Aug 2014 19:59:14 GMT (envelope-from kczekirda@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7BJxDPN008606 for svn-soc-all@FreeBSD.org; Mon, 11 Aug 2014 19:59:13 GMT (envelope-from kczekirda@FreeBSD.org) Date: Mon, 11 Aug 2014 19:59:13 GMT Message-Id: <201408111959.s7BJxDPN008606@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to kczekirda@FreeBSD.org using -f From: kczekirda@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272230 - in soc2014/kczekirda/pxe-fai-head/tools/mfsbsd: conf customfiles/etc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Aug 2014 19:59:14 -0000 Author: kczekirda Date: Mon Aug 11 19:59:13 2014 New Revision: 272230 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272230 Log: fai is ready Added: soc2014/kczekirda/pxe-fai-head/tools/mfsbsd/customfiles/etc/dhclient.conf Modified: soc2014/kczekirda/pxe-fai-head/tools/mfsbsd/conf/rc.local.sample soc2014/kczekirda/pxe-fai-head/tools/mfsbsd/customfiles/etc/installerconfig Modified: soc2014/kczekirda/pxe-fai-head/tools/mfsbsd/conf/rc.local.sample ============================================================================== --- soc2014/kczekirda/pxe-fai-head/tools/mfsbsd/conf/rc.local.sample Mon Aug 11 18:57:22 2014 (r272229) +++ soc2014/kczekirda/pxe-fai-head/tools/mfsbsd/conf/rc.local.sample Mon Aug 11 19:59:13 2014 (r272230) @@ -1,13 +1,6 @@ #!/bin/sh # $FreeBSD: head/release/rc.local 259686 2013-12-21 16:43:40Z dteske $ -: ${DIALOG_OK=0} -: ${DIALOG_CANCEL=1} -: ${DIALOG_HELP=2} -: ${DIALOG_EXTRA=3} -: ${DIALOG_ITEM_HELP=4} -: ${DIALOG_ESC=255} - MACHINE=`uname -m` kbdcontrol -d >/dev/null 2>&1 @@ -49,14 +42,62 @@ fi export TERM -if [ -f /etc/installerconfig ]; then - if bsdinstall script /etc/installerconfig; then - dialog --backtitle "FreeBSD Installer" --title "Complete" --no-cancel --ok-label "Reboot" --pause "Installation of FreeBSD complete! Rebooting in 10 seconds" 10 30 10 - reboot - else - dialog --backtitle "FreeBSD Installer" --title "Error" --textbox /tmp/bsdinstall_log 0 0 - fi - exit +echo "FAI FreeBSD installer" + +file="/etc/installerconfig" + +if [ -f "$file" ] && [ `head -n 1 "$file"` == "#!fai" ]; then + method="installerconfig" +fi + +preseed=`cat /var/db/dhclient.leases.* | grep bootfile-name | head -n 1 | awk '{print $3}' | tr -d '";'` + +if [ ! -z "$preseed" ]; then + input="/tmp/fai.conf" + + # default config + + fetch "$preseed"/default -o "$input".default + if [ `head -n "$input".default` == "#!fai" ]; then + method="default"; + fi + + # mac based config + + macs=`ifconfig | grep ether | awk '{print $2}'` + + for mac in $macs + do + fetch "$preseed"/"$mac" -o "$input".$mac + if [ `head -n 1 "$input"."$mac"` == "#!fai" ]; then + method="mac" + rightmac="$mac" + break + fi + done fi +case "$method" in + installerconfig) + input="$file" + ;; + default) + input="$input".default + ;; + mac) + input="$input"."$rightmac" + ;; + *) + echo "No installation method detected, run bsdinstall manually" + exit + ;; +esac + +if bsdinstall script "$input"; then + dialog --backtitle "FreeBSD Installer" --title "Complete" --no-cancel --ok-label "Reboot" --pause "Installation of FreeBSD complete! Rebooting in 10 seconds" 10 30 10 + reboot +else + dialog --backtitle "FreeBSD Installer" --title "Error" --textbox /tmp/bsdinstall_log 0 0 +fi +exit Added: soc2014/kczekirda/pxe-fai-head/tools/mfsbsd/customfiles/etc/dhclient.conf ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/kczekirda/pxe-fai-head/tools/mfsbsd/customfiles/etc/dhclient.conf Mon Aug 11 19:59:13 2014 (r272230) @@ -0,0 +1,2 @@ +request bootfile-name subnet-mask, broadcast-address, time-offset, routers, + domain-search, domain-name, domain-name-servers, host-name; Modified: soc2014/kczekirda/pxe-fai-head/tools/mfsbsd/customfiles/etc/installerconfig ============================================================================== --- soc2014/kczekirda/pxe-fai-head/tools/mfsbsd/customfiles/etc/installerconfig Mon Aug 11 18:57:22 2014 (r272229) +++ soc2014/kczekirda/pxe-fai-head/tools/mfsbsd/customfiles/etc/installerconfig Mon Aug 11 19:59:13 2014 (r272230) @@ -1,3 +1,5 @@ +#!fai + PARTITIONS="ada0 { auto freebsd-ufs /}" DISTRIBUTIONS="kernel.txz base.txz" MIRROR="ftp://dell740" From owner-svn-soc-all@FreeBSD.ORG Mon Aug 11 19:59:21 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 843923D9 for ; Mon, 11 Aug 2014 19:59:21 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 646812B29 for ; Mon, 11 Aug 2014 19:59:21 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7BJxL2X008680 for ; Mon, 11 Aug 2014 19:59:21 GMT (envelope-from kczekirda@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7BJxK8W008673 for svn-soc-all@FreeBSD.org; Mon, 11 Aug 2014 19:59:20 GMT (envelope-from kczekirda@FreeBSD.org) Date: Mon, 11 Aug 2014 19:59:20 GMT Message-Id: <201408111959.s7BJxK8W008673@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to kczekirda@FreeBSD.org using -f From: kczekirda@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272231 - soc2014/kczekirda/pxe-fai-head/head/usr.sbin/bsdinstall/scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Aug 2014 19:59:21 -0000 Author: kczekirda Date: Mon Aug 11 19:59:19 2014 New Revision: 272231 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272231 Log: network tofile with problems Modified: soc2014/kczekirda/pxe-fai-head/head/usr.sbin/bsdinstall/scripts/netconfig soc2014/kczekirda/pxe-fai-head/head/usr.sbin/bsdinstall/scripts/netconfig_ipv4 soc2014/kczekirda/pxe-fai-head/head/usr.sbin/bsdinstall/scripts/netconfig_ipv6 Modified: soc2014/kczekirda/pxe-fai-head/head/usr.sbin/bsdinstall/scripts/netconfig ============================================================================== --- soc2014/kczekirda/pxe-fai-head/head/usr.sbin/bsdinstall/scripts/netconfig Mon Aug 11 19:59:13 2014 (r272230) +++ soc2014/kczekirda/pxe-fai-head/head/usr.sbin/bsdinstall/scripts/netconfig Mon Aug 11 19:59:19 2014 (r272231) @@ -107,6 +107,7 @@ exec $0 else IPV4_AVAIL=0 + [ ! -z "$TOFILE" ] && echo IPV4=\"NO\" >> "$TOFILE" fi fi # In case wlanconfig left an option and we do not support IPv4 we need to write @@ -121,6 +122,7 @@ bsdinstall netconfig_ipv6 ${INTERFACE} || exec $0 else IPV6_AVAIL=0 + [ ! -z "$TOFILE" ] && echo IPV6=\"NO\" >> "$TOFILE" fi fi @@ -187,30 +189,60 @@ if [ $? -eq $DIALOG_CANCEL ]; then exec $0; fi exec 3>&- -echo ${RESOLV} | tr ' ' '\n' | \ -awk ' +if [ -z "$TOFILE" ]; then + echo ${RESOLV} | tr ' ' '\n' | \ + awk ' + BEGIN { + search=-1; + } + { + if (/^[[:space:]]+$/) { + next; + } + if (/^Nameserver$/) { + printf "\n"; + search=0; + next; + } + if (search == -1) { + printf "search "; + search=1; + } + if (search > 0) { + printf "%s%s", (search > 1) ? " " : "", $1; + search++; + next; + } + printf "nameserver %s\n", $1; + }' > ${BSDINSTALL_TMPETC}/resolv.conf + mv $BSDINSTALL_TMPETC/._rc.conf.net $BSDINSTALL_TMPETC/rc.conf.net +else + echo ${RESOLV} >> "$TOFILE" + echo resolv >> "$TOFILE" + echo ${RESOLV} | tr ' ' '\n' | \ + awk ' BEGIN { - search=-1; +>---search=-1; } { - if (/^[[:space:]]+$/) { - next; - } - if (/^Nameserver$/) { - printf "\n"; - search=0; - next; - } - if (search == -1) { - printf "search "; - search=1; - } - if (search > 0) { - printf "%s%s", (search > 1) ? " " : "", $1; - search++; - next; - } - printf "nameserver %s\n", $1; -}' > ${BSDINSTALL_TMPETC}/resolv.conf - -mv $BSDINSTALL_TMPETC/._rc.conf.net $BSDINSTALL_TMPETC/rc.conf.net +>---if (/^[[:space:]]+$/) { +>--->---next; +>---} +>---if (/^Nameserver$/) { +>--->---printf "\n"; +>--->---search=0; +>--->---next; +>---} +>---if (search == -1) { +>--->---printf "search "; +>--->---search=1; +>---} +>---if (search > 0) { +printf "DOMAIN=\""; +>--->---printf "%s%s", (search > 1) ? " " : "", $1; +>--->---search++; +>--->---next; +>---} +>---printf "DNS=\"%s\n\"", $1; +}' >> "$TOFILE" +fi Modified: soc2014/kczekirda/pxe-fai-head/head/usr.sbin/bsdinstall/scripts/netconfig_ipv4 ============================================================================== --- soc2014/kczekirda/pxe-fai-head/head/usr.sbin/bsdinstall/scripts/netconfig_ipv4 Mon Aug 11 19:59:13 2014 (r272230) +++ soc2014/kczekirda/pxe-fai-head/head/usr.sbin/bsdinstall/scripts/netconfig_ipv4 Mon Aug 11 19:59:19 2014 (r272231) @@ -66,6 +66,8 @@ exit 0 fi +[ -z "$TOFILE" ] && echo DHCP=\"NO\" >> "$TOFILE" + IP_ADDRESS=`ifconfig $INTERFACE inet | awk '/inet/ {printf("%s\n", $2); }'` NETMASK=`ifconfig $INTERFACE inet | awk '/inet/ {printf("%s\n", $4); }'` ROUTER=`netstat -rn -f inet | awk '/default/ {printf("%s\n", $2);}'` Modified: soc2014/kczekirda/pxe-fai-head/head/usr.sbin/bsdinstall/scripts/netconfig_ipv6 ============================================================================== --- soc2014/kczekirda/pxe-fai-head/head/usr.sbin/bsdinstall/scripts/netconfig_ipv6 Mon Aug 11 19:59:13 2014 (r272230) +++ soc2014/kczekirda/pxe-fai-head/head/usr.sbin/bsdinstall/scripts/netconfig_ipv6 Mon Aug 11 19:59:19 2014 (r272231) @@ -150,8 +150,34 @@ printf("ifconfig_%s_ipv6=\"inet6 %s\"\n", iface, $1); }' >> $BSDINSTALL_TMPETC/._rc.conf.net else - echo $IF_CONFIG - echo "static ip6" >> "$TOFILE" + echo ${IF_CONFIG} | tr ' ' '\n' | \ + awk -v iface="${INTERFACE}" ' + BEGIN { + >---dfr=0; + >---count=0; + } + { + >---if (/^[[:space:]]+$/) { + >--->---next; + >---} + >---if (/DefaultRouter/) { + >--->---dfr=1; + >--->---next; + >---} + >---if (dfr == 1) { + >--->---printf("ipv6_defaultrouter=\"%s\"\n", $1); + >--->---next; + >---} + >---if (count > 0) { + >--->---# Ignore all but the first IP address for now. + >--->---next; + >---} + >---count++; + >---if (!match($1, "/")) { + >--->---sub("$", "/64", $1); + >---} + >---printf("ifconfig_%s_ipv6=\"inet6 %s\"\n", iface, $1); + }' >> "$TOFILE" fi if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then From owner-svn-soc-all@FreeBSD.ORG Tue Aug 12 08:41:16 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6FBCE902 for ; Tue, 12 Aug 2014 08:41:16 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 41CF12A8A for ; Tue, 12 Aug 2014 08:41:16 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7C8fGEs059579 for ; Tue, 12 Aug 2014 08:41:16 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7C8fFdU059562 for svn-soc-all@FreeBSD.org; Tue, 12 Aug 2014 08:41:15 GMT (envelope-from dpl@FreeBSD.org) Date: Tue, 12 Aug 2014 08:41:15 GMT Message-Id: <201408120841.s7C8fFdU059562@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272256 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Aug 2014 08:41:16 -0000 Author: dpl Date: Tue Aug 12 08:41:15 2014 New Revision: 272256 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272256 Log: Moved all the packet matching part into a function to be used as compiled bitcode. As a side effect, we now have taken out PULLUP_TO/PULLUP_LEN out of ip_fw2.c. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Tue Aug 12 02:09:00 2014 (r272255) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Tue Aug 12 08:41:15 2014 (r272256) @@ -42,8 +42,8 @@ struct ip_fw_chain; struct ip_fw; struct ipfw_insn; -ipfw_insn_if; -ipfw_dyn_rule; +struct _ipfw_insn_if; +struct _ipfw_dyn_rule; #ifndef __FreeBSD__ struct bsd_ucred; @@ -54,6 +54,11 @@ // Functions used by JIT, external. int printf(const char * restrict format, ...); +static VNET_DEFINE(int, fw_deny_unknown_exthdrs); +#define V_fw_deny_unknown_exthdrs VNET(fw_deny_unknown_exthdrs) + +static VNET_DEFINE(int, fw_permit_single_frag6) = 1; +#define V_fw_permit_single_frag6 VNET(fw_permit_single_frag6) /* * Some macros used in the various matching options. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Tue Aug 12 02:09:00 2014 (r272255) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Tue Aug 12 08:41:15 2014 (r272256) @@ -158,8 +158,8 @@ ip_fw_argsTy = mod->getTypeByName("ip_fw_args"); ip_fw_chainTy = mod->getTypeByName("ip_fw_chain"); ip_fwTy = mod->getTypeByName("ip_fw"); - ip_fw_insnTy = mod->getTypeByName("ip_fw_insn"); - ipfw_insn_ifTy = mod->getTypeByName("ipfw_insn_if"); + ip_fw_insnTy = mod->getTypeByName("_ip_fw_insn"); + ipfw_insn_ifTy = mod->getTypeByName("_ipfw_insn_if"); mbufTy = mod->getTypeByName("mbuf"); #ifndef __FreeBSD__ ucredTy = mod->getTypeByName("bsd_ucred"); From owner-svn-soc-all@FreeBSD.ORG Tue Aug 12 08:49:59 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A244EB2C for ; Tue, 12 Aug 2014 08:49:59 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 848672B74 for ; Tue, 12 Aug 2014 08:49:59 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7C8nxiG065285 for ; Tue, 12 Aug 2014 08:49:59 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7C8nwgD065281 for svn-soc-all@FreeBSD.org; Tue, 12 Aug 2014 08:49:58 GMT (envelope-from dpl@FreeBSD.org) Date: Tue, 12 Aug 2014 08:49:58 GMT Message-Id: <201408120849.s7C8nwgD065281@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272257 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Aug 2014 08:49:59 -0000 Author: dpl Date: Tue Aug 12 08:49:58 2014 New Revision: 272257 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272257 Log: Moved all the packet matching part into a function to be used as compiled bitcode. As a side effect, we now have taken out PULLUP_TO/PULLUP_LEN out of ip_fw2.c Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Tue Aug 12 08:41:15 2014 (r272256) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Tue Aug 12 08:49:58 2014 (r272257) @@ -13,10 +13,16 @@ #include #include +#include +#include #include #include #include +#include +#include +#include #include +#include #include #ifdef INET6 @@ -80,6 +86,8 @@ * then it sets p to point at the offset "len" in the mbuf. WARNING: the * pointer might become stale after other pullups (but we never use it * this way). + * + * This is a modified version, since returns 1, insteaf of goto pullup_failed. */ #define PULLUP_TO(_len, p, T) PULLUP_LEN(_len, p, sizeof(T)) #define PULLUP_LEN(_len, p, T) \ @@ -88,7 +96,7 @@ if ((m)->m_len < x) { \ args->m = m = m_pullup(m, x); \ if (m == NULL) \ - goto pullup_failed; \ + return (1); \ } \ p = (mtod(m, char *) + (_len)); \ } while (0) @@ -96,6 +104,249 @@ /* Needed vars defined at ip_fw2.c */ VNET_DECLARE(int, V_ipfw_vnet_ready); + +int +inspect_pkt(struct ip_fw_args *args, struct ip *ip, struct mbuf *m, struct in_addr *src_ip, struct in_addr *dst_ip, uint16_t *src_port, uint16_t *dst_port, uint16_t *etype, uint16_t *ext_hd, uint16_t *iplen, int *pktlen, int *is_ipv4, int *is_ipv6, u_int *hlen, uint8_t *proto, uint8_t *icmp6_type, u_short *ip6f_mf, u_short *offset, void *ulp) +{ + /* + * if we have an ether header, + */ + if (args->eh) + *etype = ntohs(args->eh->ether_type); + + /* Identify IP packets and fill up variables. */ + if ((*pktlen) >= sizeof(struct ip6_hdr) && + (args->eh == NULL || (*etype) == ETHERTYPE_IPV6) && ip->ip_v == 6) { + struct ip6_hdr *ip6 = (struct ip6_hdr *)ip; + *is_ipv6 = 1; + args->f_id.addr_type = 6; + (*hlen) = sizeof(struct ip6_hdr); + *proto = ip6->ip6_nxt; + + /* Search extension headers to find upper layer protocols */ + while (ulp == NULL && (*offset) == 0) { + switch (*proto) { + case IPPROTO_ICMPV6: + PULLUP_TO((*hlen), ulp, struct icmp6_hdr); + *icmp6_type = ICMP6(ulp)->icmp6_type; + break; + + case IPPROTO_TCP: + PULLUP_TO((*hlen), ulp, struct tcphdr); + *dst_port = TCP(ulp)->th_dport; + *src_port = TCP(ulp)->th_sport; + /* save flags for dynamic rules */ + args->f_id._flags = TCP(ulp)->th_flags; + break; + + case IPPROTO_SCTP: + PULLUP_TO((*hlen), ulp, struct sctphdr); + *src_port = SCTP(ulp)->src_port; + *dst_port = SCTP(ulp)->dest_port; + break; + + case IPPROTO_UDP: + PULLUP_TO((*hlen), ulp, struct udphdr); + *dst_port = UDP(ulp)->uh_dport; + *src_port = UDP(ulp)->uh_sport; + break; + + case IPPROTO_HOPOPTS: /* RFC 2460 */ + PULLUP_TO((*hlen), ulp, struct ip6_hbh); + *ext_hd |= EXT_HOPOPTS; + (*hlen) += (((struct ip6_hbh *)ulp)->ip6h_len + 1) << 3; + *proto = ((struct ip6_hbh *)ulp)->ip6h_nxt; + ulp = NULL; + break; + + case IPPROTO_ROUTING: /* RFC 2460 */ + PULLUP_TO((*hlen), ulp, struct ip6_rthdr); + switch (((struct ip6_rthdr *)ulp)->ip6r_type) { + case 0: + *ext_hd |= EXT_RTHDR0; + break; + case 2: + *ext_hd |= EXT_RTHDR2; + break; + default: + if (V_fw_verbose) + printf("IPFW2: IPV6 - Unknown " + "Routing Header type(%d)\n", + ((struct ip6_rthdr *) + ulp)->ip6r_type); + if (V_fw_deny_unknown_exthdrs) + return (IP_FW_DENY); + break; + } + *ext_hd |= EXT_ROUTING; + (*hlen) += (((struct ip6_rthdr *)ulp)->ip6r_len + 1) << 3; + *proto = ((struct ip6_rthdr *)ulp)->ip6r_nxt; + ulp = NULL; + break; + + case IPPROTO_FRAGMENT: /* RFC 2460 */ + PULLUP_TO((*hlen), ulp, struct ip6_frag); + *ext_hd |= EXT_FRAGMENT; + (*hlen) += sizeof (struct ip6_frag); + *proto = ((struct ip6_frag *)ulp)->ip6f_nxt; + *offset = ((struct ip6_frag *)ulp)->ip6f_offlg & + IP6F_OFF_MASK; + *ip6f_mf = ((struct ip6_frag *)ulp)->ip6f_offlg & + IP6F_MORE_FRAG; + if (V_fw_permit_single_frag6 == 0 && + *offset == 0 && *ip6f_mf == 0) { + if (V_fw_verbose) + printf("IPFW2: IPV6 - Invalid " + "Fragment Header\n"); + if (V_fw_deny_unknown_exthdrs) + return (IP_FW_DENY); + break; + } + args->f_id.extra = + ntohl(((struct ip6_frag *)ulp)->ip6f_ident); + ulp = NULL; + break; + + case IPPROTO_DSTOPTS: /* RFC 2460 */ + PULLUP_TO((*hlen), ulp, struct ip6_hbh); + *ext_hd |= EXT_DSTOPTS; + (*hlen) += (((struct ip6_hbh *)ulp)->ip6h_len + 1) << 3; + *proto = ((struct ip6_hbh *)ulp)->ip6h_nxt; + ulp = NULL; + break; + + case IPPROTO_AH: /* RFC 2402 */ + PULLUP_TO((*hlen), ulp, struct ip6_ext); + *ext_hd |= EXT_AH; + (*hlen) += (((struct ip6_ext *)ulp)->ip6e_len + 2) << 2; + *proto = ((struct ip6_ext *)ulp)->ip6e_nxt; + ulp = NULL; + break; + + case IPPROTO_ESP: /* RFC 2406 */ + PULLUP_TO((*hlen), ulp, uint32_t); /* SPI, Seq# */ + /* Anything past Seq# is variable length and + * data past this ext. header is encrypted. */ + *ext_hd |= EXT_ESP; + break; + + case IPPROTO_NONE: /* RFC 2460 */ + /* + * Packet ends here, and IPv6 header has + * already been pulled up. If ip6e_len!=0 + * then octets must be ignored. + */ + ulp = ip; /* non-NULL to get out of loop. */ + break; + + case IPPROTO_OSPFIGP: + /* XXX OSPF header check? */ + PULLUP_TO((*hlen), ulp, struct ip6_ext); + break; + + case IPPROTO_PIM: + /* XXX PIM header check? */ + PULLUP_TO((*hlen), ulp, struct pim); + break; + + case IPPROTO_CARP: + PULLUP_TO((*hlen), ulp, struct carp_header); + if (((struct carp_header *)ulp)->carp_version != + CARP_VERSION) + return (IP_FW_DENY); + if (((struct carp_header *)ulp)->carp_type != + CARP_ADVERTISEMENT) + return (IP_FW_DENY); + break; + + case IPPROTO_IPV6: /* RFC 2893 */ + PULLUP_TO((*hlen), ulp, struct ip6_hdr); + break; + + case IPPROTO_IPV4: /* RFC 2893 */ + PULLUP_TO((*hlen), ulp, struct ip); + break; + + default: + if (V_fw_verbose) + printf("IPFW2: IPV6 - Unknown " + "Extension Header(%d), ext_hd=%x\n", + *proto, *ext_hd); + if (V_fw_deny_unknown_exthdrs) + return (IP_FW_DENY); + PULLUP_TO((*hlen), ulp, struct ip6_ext); + break; + } /*switch */ + } + ip = mtod(m, struct ip *); + ip6 = (struct ip6_hdr *)ip; + args->f_id.src_ip6 = ip6->ip6_src; + args->f_id.dst_ip6 = ip6->ip6_dst; + args->f_id.src_ip = 0; + args->f_id.dst_ip = 0; + args->f_id.flow_id6 = ntohl(ip6->ip6_flow); + } else if ((*pktlen) >= sizeof(struct ip) && + (args->eh == NULL || (*etype) == ETHERTYPE_IP) && ip->ip_v == 4) { + *is_ipv4 = 1; + (*hlen) = ip->ip_hl << 2; + args->f_id.addr_type = 4; + + /* + * Collect parameters into local variables for faster matching. + */ + *proto = ip->ip_p; + *src_ip = ip->ip_src; + *dst_ip = ip->ip_dst; + *offset = ntohs(ip->ip_off) & IP_OFFMASK; + *iplen = ntohs(ip->ip_len); + *pktlen = *iplen < (*pktlen) ? *iplen : (*pktlen); + + if (*offset == 0) { + switch (*proto) { + case IPPROTO_TCP: + PULLUP_TO((*hlen), ulp, struct tcphdr); + *dst_port = TCP(ulp)->th_dport; + *src_port = TCP(ulp)->th_sport; + /* save flags for dynamic rules */ + args->f_id._flags = TCP(ulp)->th_flags; + break; + + case IPPROTO_SCTP: + PULLUP_TO((*hlen), ulp, struct sctphdr); + *src_port = SCTP(ulp)->src_port; + *dst_port = SCTP(ulp)->dest_port; + break; + + case IPPROTO_UDP: + PULLUP_TO((*hlen), ulp, struct udphdr); + *dst_port = UDP(ulp)->uh_dport; + *src_port = UDP(ulp)->uh_sport; + break; + + case IPPROTO_ICMP: + PULLUP_TO((*hlen), ulp, struct icmphdr); + //args->f_id.flags = ICMP(ulp)->icmp_type; + break; + + default: + break; + } + } + + ip = mtod(m, struct ip *); + args->f_id.src_ip = ntohl((*src_ip).s_addr); + args->f_id.dst_ip = ntohl((*dst_ip).s_addr); + } + + if (*proto) { /* we may have port numbers, store them */ + args->f_id.proto = *proto; + args->f_id.src_port = *src_port = ntohs(*src_port); + args->f_id.dst_port = *dst_port = ntohs(*dst_port); + } + + return (0); +} + /* * Auxiliar functions. */ @@ -1167,16 +1418,7 @@ static IPFW_RULES_INLINE int rule_tcpopts(int *match, u_int hlen, void *ulp, uint8_t proto, u_short offset, ipfw_insn *cmd, struct mbuf *m, struct ip_fw_args *args) { - /* Modified PULLUP_TO, returns 1 if error */ - do { - int x = (hlen) + (TCP(ulp)->th_off << 2); - if ((m)->m_len < x) { - args->m = m = m_pullup(m, x); - if (m == NULL) - return (1); - } - ulp = (mtod(m, char *) + (hlen)); - } while (0); + PULLUP_TO(hlen, ulp , (TCP(ulp)->th_off << 2)); *match = (proto == IPPROTO_TCP && offset == 0 && tcpopts_match(TCP(ulp), cmd)); Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Tue Aug 12 08:41:15 2014 (r272256) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Tue Aug 12 08:49:58 2014 (r272257) @@ -86,7 +86,7 @@ Value *ext_hd; //unsigned // This sets up some vars, at star time. - Function *look_pkt; + Function *inspect_pkt; // Auxiliary functions used by our JITed code. Function *is_icmp_query; @@ -240,7 +240,7 @@ // Get Function defs from bitcode. // All of them are auxiliary functions. - look_pkt = mod->getFunction("look_pkt"); + inspect_pkt = mod->getFunction("inspect_pkt"); is_icmp_query = mod->getFunction("is_icmp_query"); flags_match = mod->getFunction("flags_match"); ipopts_match = mod->getFunction("ipopts_match"); @@ -296,12 +296,12 @@ return ((funcptr)NULL); } - // Emits all the code necessary to fill in some vars. - // XXX Should we emit that? Or should we create a function call instead? + // Call the function that fills in some vars. int emit_lookpkt() { - //irb.CreateCall(); + // If it returns zero, we have to goto pullup_failed. + irb.CreateCall(inspect_pkt); return (0); } From owner-svn-soc-all@FreeBSD.ORG Tue Aug 12 09:23:47 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1780E8D1 for ; Tue, 12 Aug 2014 09:23:47 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0321C20EE for ; Tue, 12 Aug 2014 09:23:47 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7C9NkwD077971 for ; Tue, 12 Aug 2014 09:23:46 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7C9NkQ5077728 for svn-soc-all@FreeBSD.org; Tue, 12 Aug 2014 09:23:46 GMT (envelope-from dpl@FreeBSD.org) Date: Tue, 12 Aug 2014 09:23:46 GMT Message-Id: <201408120923.s7C9NkQ5077728@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272258 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Aug 2014 09:23:47 -0000 Author: dpl Date: Tue Aug 12 09:23:45 2014 New Revision: 272258 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272258 Log: Use inspect_pkt() Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c Tue Aug 12 08:49:58 2014 (r272257) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c Tue Aug 12 09:23:45 2014 (r272258) @@ -406,259 +406,8 @@ proto = args->f_id.proto = 0; /* mark f_id invalid */ /* XXX 0 is a valid proto: IP/IPv6 Hop-by-Hop Option */ -/* - * PULLUP_TO(len, p, T) makes sure that len + sizeof(T) is contiguous, - * then it sets p to point at the offset "len" in the mbuf. WARNING: the - * pointer might become stale after other pullups (but we never use it - * this way). - */ -#define PULLUP_TO(_len, p, T) PULLUP_LEN(_len, p, sizeof(T)) -#define PULLUP_LEN(_len, p, T) \ -do { \ - int x = (_len) + T; \ - if ((m)->m_len < x) { \ - args->m = m = m_pullup(m, x); \ - if (m == NULL) \ - goto pullup_failed; \ - } \ - p = (mtod(m, char *) + (_len)); \ -} while (0) - - /* - * if we have an ether header, - */ - if (args->eh) - etype = ntohs(args->eh->ether_type); - - /* Identify IP packets and fill up variables. */ - if (pktlen >= sizeof(struct ip6_hdr) && - (args->eh == NULL || etype == ETHERTYPE_IPV6) && ip->ip_v == 6) { - struct ip6_hdr *ip6 = (struct ip6_hdr *)ip; - is_ipv6 = 1; - args->f_id.addr_type = 6; - hlen = sizeof(struct ip6_hdr); - proto = ip6->ip6_nxt; - - /* Search extension headers to find upper layer protocols */ - while (ulp == NULL && offset == 0) { - switch (proto) { - case IPPROTO_ICMPV6: - PULLUP_TO(hlen, ulp, struct icmp6_hdr); - icmp6_type = ICMP6(ulp)->icmp6_type; - break; - - case IPPROTO_TCP: - PULLUP_TO(hlen, ulp, struct tcphdr); - dst_port = TCP(ulp)->th_dport; - src_port = TCP(ulp)->th_sport; - /* save flags for dynamic rules */ - args->f_id._flags = TCP(ulp)->th_flags; - break; - - case IPPROTO_SCTP: - PULLUP_TO(hlen, ulp, struct sctphdr); - src_port = SCTP(ulp)->src_port; - dst_port = SCTP(ulp)->dest_port; - break; - - case IPPROTO_UDP: - PULLUP_TO(hlen, ulp, struct udphdr); - dst_port = UDP(ulp)->uh_dport; - src_port = UDP(ulp)->uh_sport; - break; - - case IPPROTO_HOPOPTS: /* RFC 2460 */ - PULLUP_TO(hlen, ulp, struct ip6_hbh); - ext_hd |= EXT_HOPOPTS; - hlen += (((struct ip6_hbh *)ulp)->ip6h_len + 1) << 3; - proto = ((struct ip6_hbh *)ulp)->ip6h_nxt; - ulp = NULL; - break; - - case IPPROTO_ROUTING: /* RFC 2460 */ - PULLUP_TO(hlen, ulp, struct ip6_rthdr); - switch (((struct ip6_rthdr *)ulp)->ip6r_type) { - case 0: - ext_hd |= EXT_RTHDR0; - break; - case 2: - ext_hd |= EXT_RTHDR2; - break; - default: - if (V_fw_verbose) - printf("IPFW2: IPV6 - Unknown " - "Routing Header type(%d)\n", - ((struct ip6_rthdr *) - ulp)->ip6r_type); - if (V_fw_deny_unknown_exthdrs) - return (IP_FW_DENY); - break; - } - ext_hd |= EXT_ROUTING; - hlen += (((struct ip6_rthdr *)ulp)->ip6r_len + 1) << 3; - proto = ((struct ip6_rthdr *)ulp)->ip6r_nxt; - ulp = NULL; - break; - - case IPPROTO_FRAGMENT: /* RFC 2460 */ - PULLUP_TO(hlen, ulp, struct ip6_frag); - ext_hd |= EXT_FRAGMENT; - hlen += sizeof (struct ip6_frag); - proto = ((struct ip6_frag *)ulp)->ip6f_nxt; - offset = ((struct ip6_frag *)ulp)->ip6f_offlg & - IP6F_OFF_MASK; - ip6f_mf = ((struct ip6_frag *)ulp)->ip6f_offlg & - IP6F_MORE_FRAG; - if (V_fw_permit_single_frag6 == 0 && - offset == 0 && ip6f_mf == 0) { - if (V_fw_verbose) - printf("IPFW2: IPV6 - Invalid " - "Fragment Header\n"); - if (V_fw_deny_unknown_exthdrs) - return (IP_FW_DENY); - break; - } - args->f_id.extra = - ntohl(((struct ip6_frag *)ulp)->ip6f_ident); - ulp = NULL; - break; - - case IPPROTO_DSTOPTS: /* RFC 2460 */ - PULLUP_TO(hlen, ulp, struct ip6_hbh); - ext_hd |= EXT_DSTOPTS; - hlen += (((struct ip6_hbh *)ulp)->ip6h_len + 1) << 3; - proto = ((struct ip6_hbh *)ulp)->ip6h_nxt; - ulp = NULL; - break; - - case IPPROTO_AH: /* RFC 2402 */ - PULLUP_TO(hlen, ulp, struct ip6_ext); - ext_hd |= EXT_AH; - hlen += (((struct ip6_ext *)ulp)->ip6e_len + 2) << 2; - proto = ((struct ip6_ext *)ulp)->ip6e_nxt; - ulp = NULL; - break; - - case IPPROTO_ESP: /* RFC 2406 */ - PULLUP_TO(hlen, ulp, uint32_t); /* SPI, Seq# */ - /* Anything past Seq# is variable length and - * data past this ext. header is encrypted. */ - ext_hd |= EXT_ESP; - break; - - case IPPROTO_NONE: /* RFC 2460 */ - /* - * Packet ends here, and IPv6 header has - * already been pulled up. If ip6e_len!=0 - * then octets must be ignored. - */ - ulp = ip; /* non-NULL to get out of loop. */ - break; - - case IPPROTO_OSPFIGP: - /* XXX OSPF header check? */ - PULLUP_TO(hlen, ulp, struct ip6_ext); - break; - - case IPPROTO_PIM: - /* XXX PIM header check? */ - PULLUP_TO(hlen, ulp, struct pim); - break; - - case IPPROTO_CARP: - PULLUP_TO(hlen, ulp, struct carp_header); - if (((struct carp_header *)ulp)->carp_version != - CARP_VERSION) - return (IP_FW_DENY); - if (((struct carp_header *)ulp)->carp_type != - CARP_ADVERTISEMENT) - return (IP_FW_DENY); - break; - - case IPPROTO_IPV6: /* RFC 2893 */ - PULLUP_TO(hlen, ulp, struct ip6_hdr); - break; - - case IPPROTO_IPV4: /* RFC 2893 */ - PULLUP_TO(hlen, ulp, struct ip); - break; - - default: - if (V_fw_verbose) - printf("IPFW2: IPV6 - Unknown " - "Extension Header(%d), ext_hd=%x\n", - proto, ext_hd); - if (V_fw_deny_unknown_exthdrs) - return (IP_FW_DENY); - PULLUP_TO(hlen, ulp, struct ip6_ext); - break; - } /*switch */ - } - ip = mtod(m, struct ip *); - ip6 = (struct ip6_hdr *)ip; - args->f_id.src_ip6 = ip6->ip6_src; - args->f_id.dst_ip6 = ip6->ip6_dst; - args->f_id.src_ip = 0; - args->f_id.dst_ip = 0; - args->f_id.flow_id6 = ntohl(ip6->ip6_flow); - } else if (pktlen >= sizeof(struct ip) && - (args->eh == NULL || etype == ETHERTYPE_IP) && ip->ip_v == 4) { - is_ipv4 = 1; - hlen = ip->ip_hl << 2; - args->f_id.addr_type = 4; - - /* - * Collect parameters into local variables for faster matching. - */ - proto = ip->ip_p; - src_ip = ip->ip_src; - dst_ip = ip->ip_dst; - offset = ntohs(ip->ip_off) & IP_OFFMASK; - iplen = ntohs(ip->ip_len); - pktlen = iplen < pktlen ? iplen : pktlen; - - if (offset == 0) { - switch (proto) { - case IPPROTO_TCP: - PULLUP_TO(hlen, ulp, struct tcphdr); - dst_port = TCP(ulp)->th_dport; - src_port = TCP(ulp)->th_sport; - /* save flags for dynamic rules */ - args->f_id._flags = TCP(ulp)->th_flags; - break; - - case IPPROTO_SCTP: - PULLUP_TO(hlen, ulp, struct sctphdr); - src_port = SCTP(ulp)->src_port; - dst_port = SCTP(ulp)->dest_port; - break; - - case IPPROTO_UDP: - PULLUP_TO(hlen, ulp, struct udphdr); - dst_port = UDP(ulp)->uh_dport; - src_port = UDP(ulp)->uh_sport; - break; - - case IPPROTO_ICMP: - PULLUP_TO(hlen, ulp, struct icmphdr); - //args->f_id.flags = ICMP(ulp)->icmp_type; - break; - - default: - break; - } - } - - ip = mtod(m, struct ip *); - args->f_id.src_ip = ntohl(src_ip.s_addr); - args->f_id.dst_ip = ntohl(dst_ip.s_addr); - } -#undef PULLUP_TO - if (proto) { /* we may have port numbers, store them */ - args->f_id.proto = proto; - args->f_id.src_port = src_port = ntohs(src_port); - args->f_id.dst_port = dst_port = ntohs(dst_port); - } + // Fill in some variables. + inspect_pkt(args, ip, m, scr_ip, dst_ip, src_port, dst_port, &etype, &ext_hd, &iplen, &pktlen, &is_ipv4, &is_ipv6, &hlen, &proto, &icmp6_type, &ip6f_mf, &offset, &ulp); IPFW_PF_RLOCK(chain); if (! V_ipfw_vnet_ready) { /* shutting down, leave NOW. */ Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Tue Aug 12 08:49:58 2014 (r272257) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Tue Aug 12 09:23:45 2014 (r272258) @@ -281,7 +281,7 @@ irb.SetInsertPoint(entry); // Get struct types, and store vars setEnv(args, chain); - // Emitting the code for each rule/action now-> + // Create the code related to the pullup_failed Basic Block. } ~ipfwJIT() { @@ -300,8 +300,8 @@ int emit_lookpkt() { - // If it returns zero, we have to goto pullup_failed. - irb.CreateCall(inspect_pkt); + // If it returns one, we have to goto pullup_failed. + CreateCondBr(CreateICmpEQ(irb.CreateCall(inspect_pkt), ConstantInt::get(int32Ty, 1)), pullup_failed, startiter); return (0); } From owner-svn-soc-all@FreeBSD.ORG Tue Aug 12 09:25:08 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BC510945 for ; Tue, 12 Aug 2014 09:25:08 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A902F2108 for ; Tue, 12 Aug 2014 09:25:08 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7C9P8eS095884 for ; Tue, 12 Aug 2014 09:25:08 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7C9P80c095766 for svn-soc-all@FreeBSD.org; Tue, 12 Aug 2014 09:25:08 GMT (envelope-from dpl@FreeBSD.org) Date: Tue, 12 Aug 2014 09:25:08 GMT Message-Id: <201408120925.s7C9P80c095766@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272259 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Aug 2014 09:25:08 -0000 Author: dpl Date: Tue Aug 12 09:25:07 2014 New Revision: 272259 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272259 Log: Unneeded declaration. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Tue Aug 12 09:23:45 2014 (r272258) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Tue Aug 12 09:25:07 2014 (r272259) @@ -101,10 +101,6 @@ p = (mtod(m, char *) + (_len)); \ } while (0) -/* Needed vars defined at ip_fw2.c */ -VNET_DECLARE(int, V_ipfw_vnet_ready); - - int inspect_pkt(struct ip_fw_args *args, struct ip *ip, struct mbuf *m, struct in_addr *src_ip, struct in_addr *dst_ip, uint16_t *src_port, uint16_t *dst_port, uint16_t *etype, uint16_t *ext_hd, uint16_t *iplen, int *pktlen, int *is_ipv4, int *is_ipv6, u_int *hlen, uint8_t *proto, uint8_t *icmp6_type, u_short *ip6f_mf, u_short *offset, void *ulp) { From owner-svn-soc-all@FreeBSD.ORG Tue Aug 12 10:37:04 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 58700101 for ; Tue, 12 Aug 2014 10:37:04 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 447B428D3 for ; Tue, 12 Aug 2014 10:37:04 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7CAb4KD074258 for ; Tue, 12 Aug 2014 10:37:04 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7CAb3if074243 for svn-soc-all@FreeBSD.org; Tue, 12 Aug 2014 10:37:03 GMT (envelope-from dpl@FreeBSD.org) Date: Tue, 12 Aug 2014 10:37:03 GMT Message-Id: <201408121037.s7CAb3if074243@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272264 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Aug 2014 10:37:04 -0000 Author: dpl Date: Tue Aug 12 10:37:03 2014 New Revision: 272264 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272264 Log: Added the pullup_failed basic block Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Tue Aug 12 09:48:54 2014 (r272263) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Tue Aug 12 10:37:03 2014 (r272264) @@ -48,6 +48,11 @@ Type *int32Ty; PointerType *int8PtrTy; + // Basic blocks used + BasicBlock *entry; + BasicBlock *pullup_failed; + BasicBlock *startiter; + // JIT Compiled Vars // Loop control. Value *match; @@ -108,6 +113,9 @@ Function *set_match; Function *jump_fast; + // Not pkg-filtering related funcs. + Function *printf; + // Used structs StructType *ifnetTy; StructType *in_addrTy; @@ -122,7 +130,8 @@ StructType *ucredTy; // Load the bc for JIT compilation. - Module *loadbc(std::string name) + Module * + loadbc(std::string name) { error_code ec = MemoryBuffer::getFile(name, buffer); if (ec) { @@ -141,7 +150,7 @@ } // Create the needed variables to perform pkt filtering. - int + void setEnv(struct ip_fw_args *args, struct ip_fw_chain *chain) { // Get Type objects @@ -265,6 +274,37 @@ return (0); } + void + emit_pullup_failed() + { + GlobalValue *is_verbose, *str; + BasicBlock *print, *ret; + + // VNET_DECLARE(int, fw_verbose); + // #define V_fw_verbose VNET(fw_verbose) + // We should be fine getting that from the Module. + + // pullup_failed: + // if (V_fw_verbose) + // printf("ipfw: pullup failed\n"); + // return (IP_FW_DENY); + + irb.SetInsertPoint(pullup_failed); + is_verbose = mod.getGlobalVariable("fw_verbose"); + str = irb.CreateGlobalString("ipfw: pullup failed\n"); + + // if (V_fw_verbose) + CreateCondBr(CreateICmpEQ(is_verbose, ConstantInt::get(int32Ty, 0)), ret, print); + // printf("ipfw: pullup failed\n"); + irb.SetInsertPoint(print); + irb.CreateCall(printf, str); + irb.CreateBr(ret); + + // return (IP_FW_DENY); + irb.SetInsertPoint(ret); + irb.CreateRet(ConstantInt::get(int32Ty, IP_FW_DENY)); + } + public: ipfwJIT(struct ip_fw_args *args, struct ip_fw_chain *chain): irb(con) { @@ -273,15 +313,22 @@ func = mod->getFunction("ipfw_chk_jit"); func->setLinkage(GlobalValue::ExternalLinkage); - // Create the entry point of the function - BasicBlock *entry = BasicBlock::Create(con, "entry", func); - // Add the entry block to ArrayRef - blocks.push_back(entry); - // Set the IRBuilder to insert instructions after the basic block. + + printf = mod->getFunction("printf"); + + // Create first BasicBlocks. + entry = BasicBlock::Create(con, "entry", func); + pullup_failed = BasicBlock::Create(con, "pullup_failed", func); + startiter = BasicBlock::Create(con, "startiter", func); + + // Create the code related to the pullup_failed Basic Block. + emit_pullup_failed(); + + // Set the IRBuilder to insert instructions after the entry BB. irb.SetInsertPoint(entry); + // Get struct types, and store vars setEnv(args, chain); - // Create the code related to the pullup_failed Basic Block. } ~ipfwJIT() { From owner-svn-soc-all@FreeBSD.ORG Tue Aug 12 11:05:17 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 799A7694 for ; Tue, 12 Aug 2014 11:05:17 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4C5072C86 for ; Tue, 12 Aug 2014 11:05:17 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7CB5H74004069 for ; Tue, 12 Aug 2014 11:05:17 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7CB5GnX004066 for svn-soc-all@FreeBSD.org; Tue, 12 Aug 2014 11:05:16 GMT (envelope-from dpl@FreeBSD.org) Date: Tue, 12 Aug 2014 11:05:16 GMT Message-Id: <201408121105.s7CB5GnX004066@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272267 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Aug 2014 11:05:17 -0000 Author: dpl Date: Tue Aug 12 11:05:16 2014 New Revision: 272267 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272267 Log: Added the pointer to struct types Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Tue Aug 12 10:31:31 2014 (r272266) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Tue Aug 12 11:05:16 2014 (r272267) @@ -116,7 +116,7 @@ // Not pkg-filtering related funcs. Function *printf; - // Used structs + // Used structs. StructType *ifnetTy; StructType *in_addrTy; StructType *ipTy; @@ -129,6 +129,19 @@ StructType *mbufTy; StructType *ucredTy; + // Pointer to structs type. + PointerType *ifnetTy; + PointerType *in_addrTy; + PointerType *ipTy; + PointerType *ip_fw_argsTy; + PointerType *ip_fw_chainTy; + PointerType *ip_fwTy; + PointerType *ip_fw_insnTy; + PointerType *ipfw_dyn_ruleTy; + PointerType *ipfw_insn_ifTy; + PointerType *mbufTy; + PointerType *ucredTy; + // Load the bc for JIT compilation. Module * loadbc(std::string name) @@ -170,12 +183,27 @@ ip_fw_insnTy = mod->getTypeByName("_ip_fw_insn"); ipfw_insn_ifTy = mod->getTypeByName("_ipfw_insn_if"); mbufTy = mod->getTypeByName("mbuf"); -#ifndef __FreeBSD__ - ucredTy = mod->getTypeByName("bsd_ucred"); -#else +#ifdef __FreeBSD__ ucredTy = mod->getTypeByName("ucred"); +#else + ucredTy = mod->getTypeByName("bsd_ucred"); #endif /* __FreeBSD__ */ + // Create Pointer to StructType types. + ipfw_dyn_rulePtrTy = PointerType::get(ipfw_dyn_ruleTy); + ifnetPtrTy = PointerType::get(ifnetTy); + in_addrPtrTy = PointerType::get(in_addrTy); + ipPtrTy = PointerType::get(ipTy); + ip_fw_argsPtrTy = PointerType::get(ip_fw_argsTy); + ip_fw_chainPtrTy = PointerType::get(ip_fw_chainTy); + ip_fwPtrTy = PointerType::get(ip_fwTy); + ip_fw_insnPtrTy = PointerType::get(_ip_fw_insnTy); + ipfw_insn_ifPtrTy = PointerType::get(_ipfw_insn_ifTy); + mbufPtrTy = PointerType::get(mbufTy); +#ifdef __FreeBSD__ + ucredPtrTy = PointerType::get(ucredTy); +#endif + // Allocate vars. match = irb.CreateAlloca(int32Ty); l = irb.CreateAlloca(int32Ty); From owner-svn-soc-all@FreeBSD.ORG Tue Aug 12 11:15:17 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 02FDA875 for ; Tue, 12 Aug 2014 11:15:17 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C92522DDF for ; Tue, 12 Aug 2014 11:15:16 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7CBFG5x014716 for ; Tue, 12 Aug 2014 11:15:16 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7CBFGnW014714 for svn-soc-all@FreeBSD.org; Tue, 12 Aug 2014 11:15:16 GMT (envelope-from dpl@FreeBSD.org) Date: Tue, 12 Aug 2014 11:15:16 GMT Message-Id: <201408121115.s7CBFGnW014714@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272268 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Aug 2014 11:15:17 -0000 Author: dpl Date: Tue Aug 12 11:15:15 2014 New Revision: 272268 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272268 Log: Corrected some wrong allocas and the PointerTypes names. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Tue Aug 12 11:05:16 2014 (r272267) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Tue Aug 12 11:15:15 2014 (r272268) @@ -62,7 +62,7 @@ Value *retval; // Packet matching variables. - Value *mbuf; + Value *m; Value *ip; Value *ucred; Value *ucred_lookup; @@ -130,17 +130,17 @@ StructType *ucredTy; // Pointer to structs type. - PointerType *ifnetTy; - PointerType *in_addrTy; - PointerType *ipTy; - PointerType *ip_fw_argsTy; - PointerType *ip_fw_chainTy; - PointerType *ip_fwTy; - PointerType *ip_fw_insnTy; - PointerType *ipfw_dyn_ruleTy; - PointerType *ipfw_insn_ifTy; - PointerType *mbufTy; - PointerType *ucredTy; + PointerType *ifnetPtrTy; + PointerType *in_addrPtrTy; + PointerType *ipPtrTy; + PointerType *ip_fw_argsPtrTy; + PointerType *ip_fw_chainPtrTy; + PointerType *ip_fwPtrTy; + PointerType *ip_fw_insnPtrTy; + PointerType *ipfw_dyn_rulePtrTy; + PointerType *ipfw_insn_ifPtrTy; + PointerType *mbufPtrTy; + PointerType *ucredPtrTy; // Load the bc for JIT compilation. Module * @@ -214,20 +214,22 @@ retval = irb.CreateAlloca(int32Ty); irb.CreateStore(ConstantInt::get(int32Ty, 0), retval); - mbuf = irb.CreateAlloca(mbufTy); // Init: args->m + m = irb.CreateAlloca(mbufPtrTy); // Init: args->m // ip = mtod(m, struct ip *) // #define mtod(m, t) ((t)((m)->m_data)) - ip = irb.CreateAlloca(ipTy); + ip = irb.CreateAlloca(ipPtrTy); - ucred = irb.CreateAlloca(ucredTy); // Init: NULL if type ucred. #ifdef __FreeBSD__ + ucred = irb.CreateAlloca(ucredPtrTy); // Init: NULL if type ucred. irb.CreateStore(ConstantPointerNull::get(null), ucred); +#else + ucred = irb.CreateAlloca(ucredTy); // Init: NULL if type ucred. #endif ucred_lookup = irb.CreateAlloca(int32Ty); irb.CreateStore(ConstantInt::get(int32Ty, 0), ucred_lookup); - oif = irb.CreateAlloca(ifnetTy); // Init: args->oif + oif = irb.CreateAlloca(ifnetPtrTy); // Init: args->oif hlen = irb.CreateAlloca(int32Ty); irb.CreateStore(ConstantInt::get(int32Ty, 0), hlen); @@ -259,7 +261,7 @@ dyn_dir = irb.CreateAlloca(int32Ty); irb.CreateStore(ConstantInt::get(int32Ty, MATCH_UNKNOWN), dyn_dir); - q = irb.CreateAlloca(ipfw_dyn_ruleTy); + q = irb.CreateAlloca(ipfw_dyn_rulePtrTy); irb.CreateStore(ConstantPointerNull::get(null), q); // There are no (void *), we use i8* From owner-svn-soc-all@FreeBSD.ORG Tue Aug 12 13:59:32 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 0F4EC96B for ; Tue, 12 Aug 2014 13:59:32 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EF24223F5 for ; Tue, 12 Aug 2014 13:59:31 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7CDxVV7084973 for ; Tue, 12 Aug 2014 13:59:31 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7CDxV67084946 for svn-soc-all@FreeBSD.org; Tue, 12 Aug 2014 13:59:31 GMT (envelope-from dpl@FreeBSD.org) Date: Tue, 12 Aug 2014 13:59:31 GMT Message-Id: <201408121359.s7CDxV67084946@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272284 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Aug 2014 13:59:32 -0000 Author: dpl Date: Tue Aug 12 13:59:30 2014 New Revision: 272284 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272284 Log: Corrected the NULL pointers, added a optimize function, and moved some of the code out of compile-time, to make our lifes easier. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c Tue Aug 12 12:45:30 2014 (r272283) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c Tue Aug 12 13:59:30 2014 (r272284) @@ -266,6 +266,15 @@ { struct ip_fw_chain *chain = &V_layer3_chain; + /* Read comment below about this variable. */ + struct mbuf *m = args->m; + + if (m->m_flags & M_SKIP_FIREWALL || (! V_ipfw_vnet_ready)) + return (IP_FW_PASS); /* accept */ + + args->f_id.fib = M_GETFIB(m); /* note mbuf not altered) */ + + /* If we haven't, JIT-compile the actions to be executed per-rule */ if (compiledfuncptr == 0) { IPFW_PF_RLOCK(chain); @@ -302,7 +311,6 @@ * (Until we start using L3offset, the packet is * supposed to start with the ip header). */ - struct mbuf *m = args->m; struct ip *ip = mtod(m, struct ip *); /* @@ -396,13 +404,9 @@ int done = 0; /* flag to exit the outer loop */ - if (m->m_flags & M_SKIP_FIREWALL || (! V_ipfw_vnet_ready)) - return (IP_FW_PASS); /* accept */ - dst_ip.s_addr = 0; /* make sure it is initialized */ src_ip.s_addr = 0; /* make sure it is initialized */ pktlen = m->m_pkthdr.len; - args->f_id.fib = M_GETFIB(m); /* note mbuf not altered) */ proto = args->f_id.proto = 0; /* mark f_id invalid */ /* XXX 0 is a valid proto: IP/IPv6 Hop-by-Hop Option */ Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Tue Aug 12 12:45:30 2014 (r272283) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Tue Aug 12 13:59:30 2014 (r272284) @@ -40,6 +40,9 @@ LLVMContext con; OwningPtr buffer; IRBuilder<> irb; + + // We'll store the BasicBlock objects for each rule here. + int rule_number; std::vector blocks; // Vars Types @@ -51,7 +54,7 @@ // Basic blocks used BasicBlock *entry; BasicBlock *pullup_failed; - BasicBlock *startiter; + BasicBlock *startrules; // JIT Compiled Vars // Loop control. @@ -77,7 +80,7 @@ Value *src_port; //unsigned Value *dst_port; //unsigned Value *src_ip; - Value *dest_ip; + Value *dst_ip; Value *iplen; //unsigned Value *pktlen; Value *etype; //unsigned @@ -114,7 +117,7 @@ Function *jump_fast; // Not pkg-filtering related funcs. - Function *printf; + Function *printfFunc; // Used structs. StructType *ifnetTy; @@ -190,18 +193,18 @@ #endif /* __FreeBSD__ */ // Create Pointer to StructType types. - ipfw_dyn_rulePtrTy = PointerType::get(ipfw_dyn_ruleTy); - ifnetPtrTy = PointerType::get(ifnetTy); - in_addrPtrTy = PointerType::get(in_addrTy); - ipPtrTy = PointerType::get(ipTy); - ip_fw_argsPtrTy = PointerType::get(ip_fw_argsTy); - ip_fw_chainPtrTy = PointerType::get(ip_fw_chainTy); - ip_fwPtrTy = PointerType::get(ip_fwTy); - ip_fw_insnPtrTy = PointerType::get(_ip_fw_insnTy); - ipfw_insn_ifPtrTy = PointerType::get(_ipfw_insn_ifTy); - mbufPtrTy = PointerType::get(mbufTy); + ipfw_dyn_rulePtrTy = PointerType::get(ipfw_dyn_ruleTy, 0); + ifnetPtrTy = PointerType::get(ifnetTy, 0); + in_addrPtrTy = PointerType::get(in_addrTy, 0); + ipPtrTy = PointerType::get(ipTy, 0); + ip_fw_argsPtrTy = PointerType::get(ip_fw_argsTy, 0); + ip_fw_chainPtrTy = PointerType::get(ip_fw_chainTy, 0); + ip_fwPtrTy = PointerType::get(ip_fwTy, 0); + ip_fw_insnPtrTy = PointerType::get(ip_fw_insnTy, 0); + ipfw_insn_ifPtrTy = PointerType::get(ipfw_insn_ifTy, 0); + mbufPtrTy = PointerType::get(mbufTy, 0); #ifdef __FreeBSD__ - ucredPtrTy = PointerType::get(ucredTy); + ucredPtrTy = PointerType::get(ucredTy, 0); #endif // Allocate vars. @@ -215,15 +218,16 @@ irb.CreateStore(ConstantInt::get(int32Ty, 0), retval); m = irb.CreateAlloca(mbufPtrTy); // Init: args->m - // ip = mtod(m, struct ip *) - // #define mtod(m, t) ((t)((m)->m_data)) + // XXX m = args->m + ip = irb.CreateAlloca(ipPtrTy); + // XXX ip = (struct ip *)((m)->m_data); #ifdef __FreeBSD__ ucred = irb.CreateAlloca(ucredPtrTy); // Init: NULL if type ucred. - irb.CreateStore(ConstantPointerNull::get(null), ucred); + irb.CreateStore(ConstantPointerNull::get(ucredPtrTy), ucred); #else - ucred = irb.CreateAlloca(ucredTy); // Init: NULL if type ucred. + ucred = irb.CreateAlloca(ucredTy); #endif ucred_lookup = irb.CreateAlloca(int32Ty); @@ -241,6 +245,8 @@ irb.CreateStore(ConstantInt::get(int16Ty, 0), ip6f_mf); proto = irb.CreateAlloca(int8Ty); + irb.CreateStore(ConstantInt::get(int8Ty, 0), proto); + // XXX proto = args->f_id.proto = 0 src_port = irb.CreateAlloca(int16Ty); irb.CreateStore(ConstantInt::get(int16Ty, 0), src_port); @@ -248,12 +254,16 @@ irb.CreateStore(ConstantInt::get(int16Ty, 0), dst_port); src_ip = irb.CreateAlloca(in_addrTy); - dest_ip = irb.CreateAlloca(in_addrTy); + dst_ip = irb.CreateAlloca(in_addrTy); + // XXX + //dst_ip.s_addr = 0; + //src_ip.s_addr = 0; iplen = irb.CreateAlloca(int16Ty); irb.CreateStore(ConstantInt::get(int16Ty, 0), iplen); pktlen = irb.CreateAlloca(int32Ty); + //XXX pktlen = m->m_pkthdr.len; etype = irb.CreateAlloca(int16Ty); irb.CreateStore(ConstantInt::get(int32Ty, 0), etype); @@ -262,11 +272,11 @@ irb.CreateStore(ConstantInt::get(int32Ty, MATCH_UNKNOWN), dyn_dir); q = irb.CreateAlloca(ipfw_dyn_rulePtrTy); - irb.CreateStore(ConstantPointerNull::get(null), q); + irb.CreateStore(ConstantPointerNull::get(ipfw_dyn_rulePtrTy), q); // There are no (void *), we use i8* - ulp = irb.CreateAlloca(int8PtrTy); //Init: NULL - irb.CreateStore(ConstantPointerNull::get(null), ulp); + ulp = irb.CreateAlloca(int8PtrTy); + irb.CreateStore(ConstantPointerNull::get(int8PtrTy), ulp); is_ipv4 = irb.CreateAlloca(int32Ty); irb.CreateStore(ConstantInt::get(int32Ty, 0), is_ipv4); @@ -300,14 +310,12 @@ check_uidgid = mod->getFunction("check_uidgid"); set_match = mod->getFunction("set_match"); jump_fast = mod->getFunction("jump_fast"); - - return (0); } void emit_pullup_failed() { - GlobalValue *is_verbose, *str; + Value *is_verbose, *str; BasicBlock *print, *ret; // VNET_DECLARE(int, fw_verbose); @@ -320,14 +328,14 @@ // return (IP_FW_DENY); irb.SetInsertPoint(pullup_failed); - is_verbose = mod.getGlobalVariable("fw_verbose"); + is_verbose = mod->getGlobalVariable("fw_verbose"); str = irb.CreateGlobalString("ipfw: pullup failed\n"); // if (V_fw_verbose) - CreateCondBr(CreateICmpEQ(is_verbose, ConstantInt::get(int32Ty, 0)), ret, print); + irb.CreateCondBr(irb.CreateICmpEQ(is_verbose, ConstantInt::get(int32Ty, 0)), ret, print); // printf("ipfw: pullup failed\n"); irb.SetInsertPoint(print); - irb.CreateCall(printf, str); + irb.CreateCall(printfFunc, str); irb.CreateBr(ret); // return (IP_FW_DENY); @@ -344,12 +352,12 @@ func = mod->getFunction("ipfw_chk_jit"); func->setLinkage(GlobalValue::ExternalLinkage); - printf = mod->getFunction("printf"); + printfFunc = mod->getFunction("printf"); // Create first BasicBlocks. entry = BasicBlock::Create(con, "entry", func); pullup_failed = BasicBlock::Create(con, "pullup_failed", func); - startiter = BasicBlock::Create(con, "startiter", func); + startrules = BasicBlock::Create(con, "startrules", func); // Create the code related to the pullup_failed Basic Block. emit_pullup_failed(); @@ -366,6 +374,12 @@ delete mod; } + void + optimize() + { + return; + } + // Returns the pointer to the compiled function. funcptr getFuncPtr() @@ -377,11 +391,13 @@ int emit_lookpkt() { - // If it returns one, we have to goto pullup_failed. - CreateCondBr(CreateICmpEQ(irb.CreateCall(inspect_pkt), ConstantInt::get(int32Ty, 1)), pullup_failed, startiter); + // If it returns one, goto pullup_failed. + // Else, goto starrules. + irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateCall(inspect_pkt), ConstantInt::get(int32Ty, 1)), pullup_failed, startrules); return (0); } + // Rules int emit_nop() { @@ -638,9 +654,9 @@ comp.emit_ipsec(); #endif /* otherwise no match */ +/* XXX break; -/* XXX #ifdef INET6 case O_IP6_SRC: comp.emit_ip6_src(); @@ -824,5 +840,6 @@ } /* end of outer for, scan rules */ // Once we're done iterating through the rules, return the pointer. + comp.optimize(); return (comp.getFuncPtr()); } From owner-svn-soc-all@FreeBSD.ORG Tue Aug 12 14:00:37 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 75E8F9A6 for ; Tue, 12 Aug 2014 14:00:37 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 605C02483 for ; Tue, 12 Aug 2014 14:00:37 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7CE0bso090624 for ; Tue, 12 Aug 2014 14:00:37 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7CE0a57090605 for svn-soc-all@FreeBSD.org; Tue, 12 Aug 2014 14:00:36 GMT (envelope-from dpl@FreeBSD.org) Date: Tue, 12 Aug 2014 14:00:36 GMT Message-Id: <201408121400.s7CE0a57090605@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272288 - soc2014/dpl/llvm_examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Aug 2014 14:00:37 -0000 Author: dpl Date: Tue Aug 12 14:00:35 2014 New Revision: 272288 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272288 Log: Created a dir with llvm examples to be taken for compiling. Added: soc2014/dpl/llvm_examples/ soc2014/dpl/llvm_examples/general.c soc2014/dpl/llvm_examples/general.ll soc2014/dpl/llvm_examples/structs.c Added: soc2014/dpl/llvm_examples/general.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/dpl/llvm_examples/general.c Tue Aug 12 14:00:35 2014 (r272288) @@ -0,0 +1,37 @@ +#include +#include +#include + +int +addone(int n) +{ + return (n+1); +} + +int +main(int argc, char *argv[]) +{ + int num; + + if (argc != 2) + err(1, "Usage: %s number", argv[0]); + + if (addone(1) != 2) + printf("what!"); + + num = atoi(argv[1]); + + switch (num) { + case 42: + case 1: + num = addone(num); + break; + case 10: + printf("Ten!\n"); + break; + default: + printf("Waaaat\n"); + } + + return (num); +} Added: soc2014/dpl/llvm_examples/general.ll ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/dpl/llvm_examples/general.ll Tue Aug 12 14:00:35 2014 (r272288) @@ -0,0 +1,96 @@ +; ModuleID = 'test.c' +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-freebsd11.0" + +@.str = private unnamed_addr constant [17 x i8] c"Usage: %s number\00", align 1 +@.str1 = private unnamed_addr constant [6 x i8] c"what!\00", align 1 +@.str2 = private unnamed_addr constant [6 x i8] c"Ten!\0A\00", align 1 +@.str3 = private unnamed_addr constant [8 x i8] c"Waaaat\0A\00", align 1 + +; Function Attrs: nounwind uwtable +define i32 @addone(i32 %n) #0 { +entry: + %n.addr = alloca i32, align 4 + store i32 %n, i32* %n.addr, align 4 + %0 = load i32* %n.addr, align 4 + %add = add nsw i32 %0, 1 + ret i32 %add +} + +; Function Attrs: nounwind uwtable +define i32 @main(i32 %argc, i8** %argv) #0 { +entry: + %retval = alloca i32, align 4 + %argc.addr = alloca i32, align 4 + %argv.addr = alloca i8**, align 8 + %num = alloca i32, align 4 + store i32 0, i32* %retval + store i32 %argc, i32* %argc.addr, align 4 + store i8** %argv, i8*** %argv.addr, align 8 + %0 = load i32* %argc.addr, align 4 + %cmp = icmp ne i32 %0, 2 + br i1 %cmp, label %if.then, label %if.end + +if.then: ; preds = %entry + %1 = load i8*** %argv.addr, align 8 + %arrayidx = getelementptr inbounds i8** %1, i64 0 + %2 = load i8** %arrayidx, align 8 + call void (i32, i8*, ...)* @err(i32 1, i8* getelementptr inbounds ([17 x i8]* @.str, i32 0, i32 0), i8* %2) #3 + unreachable + +if.end: ; preds = %entry + %call = call i32 @addone(i32 1) + %cmp1 = icmp ne i32 %call, 2 + br i1 %cmp1, label %if.then2, label %if.end4 + +if.then2: ; preds = %if.end + %call3 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([6 x i8]* @.str1, i32 0, i32 0)) + br label %if.end4 + +if.end4: ; preds = %if.then2, %if.end + %3 = load i8*** %argv.addr, align 8 + %arrayidx5 = getelementptr inbounds i8** %3, i64 1 + %4 = load i8** %arrayidx5, align 8 + %call6 = call i32 @atoi(i8* %4) + store i32 %call6, i32* %num, align 4 + %5 = load i32* %num, align 4 + switch i32 %5, label %sw.default [ + i32 42, label %sw.bb + i32 1, label %sw.bb + i32 10, label %sw.bb8 + ] + +sw.bb: ; preds = %if.end4, %if.end4 + %6 = load i32* %num, align 4 + %call7 = call i32 @addone(i32 %6) + store i32 %call7, i32* %num, align 4 + br label %sw.epilog + +sw.bb8: ; preds = %if.end4 + %call9 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([6 x i8]* @.str2, i32 0, i32 0)) + br label %sw.epilog + +sw.default: ; preds = %if.end4 + %call10 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([8 x i8]* @.str3, i32 0, i32 0)) + br label %sw.epilog + +sw.epilog: ; preds = %sw.default, %sw.bb8, %sw.bb + %7 = load i32* %num, align 4 + ret i32 %7 +} + +; Function Attrs: noreturn +declare void @err(i32, i8*, ...) #1 + +declare i32 @printf(i8*, ...) #2 + +declare i32 @atoi(i8*) #2 + +attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { noreturn "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #2 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #3 = { noreturn } + +!llvm.ident = !{!0} + +!0 = metadata !{metadata !"FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512"} Added: soc2014/dpl/llvm_examples/structs.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/dpl/llvm_examples/structs.c Tue Aug 12 14:00:35 2014 (r272288) @@ -0,0 +1,21 @@ +#include +#include +#include +#include + +#include + +struct mbuf gmbuf; + +int +main() +{ + struct mbuf *m; + int pktlen; + struct ip *ip = mtod(m, struct ip *); + + m = &gmbuf; + pktlen = m->pkthdr.len; + + return (0); +} From owner-svn-soc-all@FreeBSD.ORG Tue Aug 12 18:05:26 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8D1C7831 for ; Tue, 12 Aug 2014 18:05:26 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5C63A308F for ; Tue, 12 Aug 2014 17:29:24 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7CHTOAf040160 for ; Tue, 12 Aug 2014 17:29:24 GMT (envelope-from ghostmansd@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7CHTK23040135 for svn-soc-all@FreeBSD.org; Tue, 12 Aug 2014 17:29:20 GMT (envelope-from ghostmansd@FreeBSD.org) Date: Tue, 12 Aug 2014 17:29:20 GMT Message-Id: <201408121729.s7CHTK23040135@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to ghostmansd@FreeBSD.org using -f From: ghostmansd@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272296 - in soc2014/ghostmansd/head: contrib/colldb lib lib/libc lib/libc/locale lib/libc/unicode lib/libcolldb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Aug 2014 18:05:26 -0000 Author: ghostmansd Date: Tue Aug 12 17:29:20 2014 New Revision: 272296 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272296 Log: putting everything together libc now supports UNICODE flag. If it is defined, then the entire libc is compiled with -D_UNICODE_SOURCE, thus supporting Unicode Collation Algorithm as well as Unicode normalization and canonicalization using hidden __ucsnorm() and __ucscanon() functions. Collation Database Library (libcolldb) moved into contrib/, though it has its own Makefile inside lib/ directory. Collation Database Library provides colldb script, which is used to transform Unicode collation files into Collation Database format. Added: soc2014/ghostmansd/head/contrib/colldb/ - copied from r272251, soc2014/ghostmansd/head/lib/libcolldb/ soc2014/ghostmansd/head/contrib/colldb/colldb - copied, changed from r272251, soc2014/ghostmansd/head/lib/libcolldb/colldb.py soc2014/ghostmansd/head/lib/libc/unicode/Makefile.inc soc2014/ghostmansd/head/lib/libcolldb/Makefile Replaced: soc2014/ghostmansd/head/lib/libcolldb/ Deleted: soc2014/ghostmansd/head/contrib/colldb/colldb.py soc2014/ghostmansd/head/lib/libc/unicode/uchash.c Modified: soc2014/ghostmansd/head/contrib/colldb/colldb.c soc2014/ghostmansd/head/contrib/colldb/colldb.h soc2014/ghostmansd/head/lib/Makefile soc2014/ghostmansd/head/lib/libc/Makefile soc2014/ghostmansd/head/lib/libc/locale/collate.c soc2014/ghostmansd/head/lib/libc/locale/xlocale.c soc2014/ghostmansd/head/lib/libc/locale/xlocale_private.h soc2014/ghostmansd/head/lib/libc/unicode/coll.h soc2014/ghostmansd/head/lib/libc/unicode/norm.h soc2014/ghostmansd/head/lib/libc/unicode/ucscoll.c soc2014/ghostmansd/head/lib/libc/unicode/ucsnorm.c soc2014/ghostmansd/head/lib/libc/unicode/ucsxfrm.c Copied and modified: soc2014/ghostmansd/head/contrib/colldb/colldb (from r272251, soc2014/ghostmansd/head/lib/libcolldb/colldb.py) ============================================================================== --- soc2014/ghostmansd/head/lib/libcolldb/colldb.py Tue Aug 12 01:40:11 2014 (r272251, copy source) +++ soc2014/ghostmansd/head/contrib/colldb/colldb Tue Aug 12 17:29:20 2014 (r272296) @@ -1,11 +1,12 @@ #!/usr/bin/env python # *-* coding: utf-8 *-* -"""Python bindings for FreeBSD libcoll2db""" +"""Python bindings for libcolldb""" import codecs import ctypes import os import re +import sys __author__ = "Dmitry Selyutin" @@ -14,43 +15,12 @@ __maintainer__ = "Dmitry Selyutin" -_dll_ = ctypes.CDLL("libcoll2db.so") +#_dll_ = ctypes.CDLL("libcolldb.so") +_dll_ = ctypes.CDLL("./colldb.so") -_create_ = _dll_.__collation_create -_create_.argtypes = [ctypes.POINTER(ctypes.c_char), ctypes.c_int] -_create_.restype = ctypes.POINTER(CollationDB) - -_open_ = _dll_.__collation_open -_open_.argtypes = [ctypes.POINTER(ctypes.c_char)] -_open_.restype = ctypes.POINTER(CollationDB) -_sync_ = _dll_.__collation_close -_sync_.argtypes = [ctypes.POINTER(CollationDB)] -_sync_.restype = ctypes.c_int - -_close_ = _dll_.__collation_close -_close_.argtypes = [ctypes.POINTER(CollationDB)] -_close_.restype = ctypes.c_int - -_get_ = _dll_.__collation_get -_get_.argtypes = [ - ctypes.POINTER(CollationDB), - ctypes.POINTER(_CollatonKey_), - ctypes.POINTER(_CollationValue_), -] -_get_.restype = ctypes.c_int - -_put_ = _dll_.__collation_put -_put_.argtypes = [ - ctypes.POINTER(CollationDB), - ctypes.POINTER(_CollatonKey_), - ctypes.POINTER(_CollationValue_), -] -_put_.restype = ctypes.c_int - - -class _CollationWeight_(ctypes.Structure): - """struct __collation_weight { +class _CollDB_Weight_(ctypes.Structure): + """struct colldb_weight { uint8_t alternate; uint32_t level1; uint32_t level2; @@ -66,8 +36,8 @@ ] -class _CollatonKey_(ctypes.Structure): - """struct __collation_key { +class _CollDB_Key_(ctypes.Structure): + """struct colldb_key { uint8_t count; uint32_t *chars; };""" @@ -77,33 +47,55 @@ ] -class _CollationValue_(ctypes.Structure): - """struct __collation_value { +class _CollDB_Value_(ctypes.Structure): + """struct colldb_value { uint8_t count; - struct __collation_weight *weights; + struct colldb_weight *weights; };""" _fields_ = [ ("count", ctypes.c_uint8), - ("weights", ctypes.POINTER(_CollationWeight_)), + ("weights", ctypes.POINTER(_CollDB_Weight_)), ] -class CollationDB(ctypes.Structure): - """struct __collation { - uint32_t version; - void *handle; - };""" - _fields_ = [ - ("version", ctypes.c_uint32), - ("handle", ctypes.c_void_p), - ] +_create_ = _dll_.colldb_create +_create_.argtypes = [ctypes.c_char_p, ctypes.c_int] +_create_.restype = ctypes.c_void_p + +_open_ = _dll_.colldb_open +_open_.argtypes = [ctypes.c_char_p] +_open_.restype = ctypes.c_void_p +_sync_ = _dll_.colldb_sync +_sync_.argtypes = [ctypes.c_void_p] +_sync_.restype = ctypes.c_int + +_close_ = _dll_.colldb_close +_close_.argtypes = [ctypes.c_void_p] +_close_.restype = ctypes.c_int -class Collation(object): - """Collation object manages collation databases using C API.""" +_get_ = _dll_.colldb_get +_get_.argtypes = [ + ctypes.c_void_p, + ctypes.POINTER(_CollDB_Key_), + ctypes.POINTER(_CollDB_Value_), +] +_get_.restype = ctypes.c_int + +_put_ = _dll_.colldb_put +_put_.argtypes = [ + ctypes.c_void_p, + ctypes.POINTER(_CollDB_Key_), + ctypes.POINTER(_CollDB_Value_), +] +_put_.restype = ctypes.c_int + + +class CollDB(object): + """CollDB object manages collation databases using C API.""" def __init__(self, path, mode): - """Collation.__init__(path, mode) -> Collation""" + """CollDB.__init__(path, mode) -> Collation""" path = path.encode("UTF-8") if mode == "w": self._db_ = _create_(path, 511) @@ -111,6 +103,8 @@ self._db_ = _open_(path) else: raise ValueError("mode must be either 'r' or 'w'") + if not self._db_: + raise OSError(os.strerror(ctypes.get_errno())) def __enter__(self): return self @@ -125,37 +119,41 @@ def get(self, key): """Get the value which corresponds to the given key.""" - ckey = _CollatonKey_() - cvalue = _CollationValue_() - weights = ([_CollationWeight_()] * 16) + ckey = _CollDB_Key_() + cvalue = _CollDB_Value_() + weights = ([_CollDB_Weight_()] * 16) ckey.count = len(key) cvalue.count = len(weights) ckey.chars = (ctypes.c_uint32 * len(key))(*key) - cvalue.weights = (_CollationWeight_ * len(weights))(*weights) - state = _get_(self._db_, ctypes.byref(ckey), ctypes.byref(cvalue)) + cvalue.weights = (_CollDB_Weight_ * len(weights))(*weights) + state = _get_( + self._db_, + ctypes.byref(ckey), + ctypes.byref(cvalue) + ) if state == -1: raise OSError(os.strerror(ctypes.get_errno())) elif state == +1: return KeyError("".join([chr(i) for i in key])) value = [] for i in range(cvalue.count): - alternate = cvalue.weights[i][0] + alt = cvalue.weights[i][0] level1 = cvalue.weights[i][1] level2 = cvalue.weights[i][2] level3 = cvalue.weights[i][3] level4 = cvalue.weights[i][4] - value.append([alternate, level1, level2, level3, level4]) + value.append([alt, level1, level2, level3, level4]) return value def put(self, key, value): """Associate the given key with the given value.""" weights = [] - ckey = _CollatonKey_() - cvalue = _CollationValue_() + ckey = _CollDB_Key_() + cvalue = _CollDB_Value_() ckey.count = len(key) cvalue.count = len(value) for i in range(len(value)): - weight = _CollationWeight_() + weight = _CollDB_Weight_() weight.alternate = value[i][0] weight.level1 = value[i][1] weight.level2 = value[i][2] @@ -163,8 +161,12 @@ weight.level4 = value[i][4] weights.append(weight) ckey.chars = (ctypes.c_uint32 * len(key))(*key) - cvalue.weights = (_CollationWeight_ * len(value))(*weights) - state = _put_(self._db_, ctypes.byref(ckey), ctypes.byref(cvalue)) + cvalue.weights = (_CollDB_Weight_ * len(value))(*weights) + state = _put_( + self._db_, + ctypes.byref(ckey), + ctypes.byref(cvalue) + ) if state != 0: raise OSError(os.strerror(ctypes.get_errno())) @@ -182,8 +184,8 @@ """, re.X) -def coll2db(src, dst): - collation = Collation(dst, "w") +def colldb(src, dst): + collation = CollDB(dst, "w") stream = codecs.open(src, "rb", "UTF-8") for line in stream: line = line.strip() @@ -209,3 +211,11 @@ collation.put(sequence, elements) collation.close() stream.close() + + +if __name__ == "__main__": + if len(sys.argv) != 3: + sys.stderr.write("usage: colldb \n") + exit(-1) + colldb(sys.argv[1], sys.argv[2]) + exit(0) Modified: soc2014/ghostmansd/head/contrib/colldb/colldb.c ============================================================================== --- soc2014/ghostmansd/head/lib/libcolldb/colldb.c Tue Aug 12 01:40:11 2014 (r272251) +++ soc2014/ghostmansd/head/contrib/colldb/colldb.c Tue Aug 12 17:29:20 2014 (r272296) @@ -25,23 +25,30 @@ */ #include +#include #include #include #include "colldb.h" -colldb_t * +struct colldb { + uint32_t version; + void *handle; +}; + + +void * colldb_create(const char *path, int mode) { DBT key; DBT value; DB *db = NULL; int error = 0; + void *colldb = NULL; uint32_t version = 0; int flags = (O_RDWR | O_CREAT | O_TRUNC); - colldb_t *colldb = NULL; - colldb = calloc(1, sizeof(*colldb)); + colldb = calloc(1, sizeof(struct colldb)); if (colldb == NULL) { errno = ENOMEM; @@ -55,7 +62,7 @@ errno = error; return (NULL); } - colldb->version = __COLLATION_VERSION; + ((struct colldb*)colldb)->version = COLLDB_VERSION; key.data = "TYPE"; value.data = "COLLATION"; @@ -68,17 +75,17 @@ } key.data = "VERSION"; - version = htonl(colldb->version); + version = htonl(((struct colldb*)colldb)->version); value.data = &version; key.size = (strlen("VERSION") + 1); - value.size = sizeof(colldb->version); + value.size = sizeof(((struct colldb*)colldb)->version); if (db->put(db, &key, &value, 0) == -1) { error = errno; goto failure; } - colldb->handle = db; + ((struct colldb*)colldb)->handle = db; return (colldb); failure: @@ -89,7 +96,7 @@ } -colldb_t * +void * colldb_open(const char *path) { DBT key; @@ -97,10 +104,10 @@ DB *db = NULL; int error = 0; int state = 0; + void *colldb = NULL; int flags = O_RDONLY; - colldb_t *colldb = NULL; - colldb = calloc(1, sizeof(*colldb)); + colldb = calloc(1, sizeof(struct colldb)); if (colldb == NULL) { errno = ENOMEM; @@ -143,9 +150,10 @@ error = EFTYPE; goto failure; } - colldb->version = ntohl(*(const uint32_t*)value.data); + ((struct colldb*)colldb)->version = + ntohl(*(const uint32_t*)value.data); - colldb->handle = db; + ((struct colldb*)colldb)->handle = db; return (colldb); failure: @@ -157,7 +165,7 @@ int -colldb_close(colldb_t *colldb) +colldb_close(void *colldb) { DB *db = NULL; int error = 0; @@ -167,7 +175,7 @@ errno = EINVAL; return (-1); } - db = colldb->handle; + db = ((struct colldb*)colldb)->handle; if (db == NULL) { errno = EINVAL; @@ -186,7 +194,7 @@ int -colldb_sync(colldb_t *colldb) +colldb_sync(void *colldb) { DB *db = NULL; @@ -195,7 +203,7 @@ errno = EINVAL; return (-1); } - db = colldb->handle; + db = ((struct colldb*)colldb)->handle; if (db == NULL) { errno = EINVAL; @@ -206,9 +214,9 @@ int -colldb_get(colldb_t *colldb, - struct colldb_key *key, - struct colldb_value *value) +colldb_get(void *colldb, + struct colldb_key *key, + struct colldb_value *value) { DBT dbkey; DBT dbvalue; @@ -223,7 +231,7 @@ errno = EINVAL; return (-1); } - db = colldb->handle; + db = ((struct colldb*)colldb)->handle; if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) { errno = EINVAL; @@ -273,9 +281,9 @@ int -colldb_put(colldb_t *colldb, - struct colldb_key *key, - struct colldb_value *value) +colldb_put(void *colldb, + struct colldb_key *key, + struct colldb_value *value) { DBT dbkey; DBT dbvalue; @@ -291,7 +299,7 @@ errno = EINVAL; return (-1); } - db = colldb->handle; + db = ((struct colldb*)colldb)->handle; if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) { errno = EINVAL; Modified: soc2014/ghostmansd/head/contrib/colldb/colldb.h ============================================================================== --- soc2014/ghostmansd/head/lib/libcolldb/colldb.h Tue Aug 12 01:40:11 2014 (r272251) +++ soc2014/ghostmansd/head/contrib/colldb/colldb.h Tue Aug 12 17:29:20 2014 (r272296) @@ -49,6 +49,14 @@ * errno to ERANGE to indicate that struct colldb_value must allocate * a larger weights buffer. */ + +#include +#include +#include +#include +#include + + #define COLLDB_VERSION 0x00000001 #define COLLDB_WEIGHTS_MAX 10 @@ -70,17 +78,15 @@ struct colldb_weight *weights; }; -typedef struct colldb colldb_t; - -colldb_t* colldb_create(const char*, int mode); -colldb_t* colldb_open(const char*); -int colldb_close(colldb_t*); -int colldb_sync(colldb_t*); -int colldb_get(colldb_t*, +void* colldb_create(const char*, int mode); +void* colldb_open(const char*); +int colldb_close(void*); +int colldb_sync(void*); +int colldb_get(void*, struct colldb_key*, struct colldb_value*); -int colldb_put(colldb_t*, +int colldb_put(void*, struct colldb_key*, struct colldb_value*); Modified: soc2014/ghostmansd/head/lib/Makefile ============================================================================== --- soc2014/ghostmansd/head/lib/Makefile Tue Aug 12 16:51:37 2014 (r272295) +++ soc2014/ghostmansd/head/lib/Makefile Tue Aug 12 17:29:20 2014 (r272296) @@ -114,6 +114,10 @@ ${_cuse} \ ${_tests} +.ifdef UNICODE +SUBDIR+= libcolldb +.endif + # Inter-library dependencies. When the makefile for a library contains LDADD # libraries, those libraries should be listed as build order dependencies here. Modified: soc2014/ghostmansd/head/lib/libc/Makefile ============================================================================== --- soc2014/ghostmansd/head/lib/libc/Makefile Tue Aug 12 16:51:37 2014 (r272295) +++ soc2014/ghostmansd/head/lib/libc/Makefile Tue Aug 12 17:29:20 2014 (r272296) @@ -94,6 +94,10 @@ .include "${LIBC_SRCTOP}/stdlib/jemalloc/Makefile.inc" .include "${LIBC_SRCTOP}/stdtime/Makefile.inc" .include "${LIBC_SRCTOP}/string/Makefile.inc" +.ifdef UNICODE +CFLAGS+= -D_UNICODE_SOURCE +.include "${LIBC_SRCTOP}/unicode/Makefile.inc" +.endif .include "${LIBC_SRCTOP}/sys/Makefile.inc" .include "${LIBC_SRCTOP}/rpc/Makefile.inc" .include "${LIBC_SRCTOP}/uuid/Makefile.inc" Modified: soc2014/ghostmansd/head/lib/libc/locale/collate.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/locale/collate.c Tue Aug 12 16:51:37 2014 (r272295) +++ soc2014/ghostmansd/head/lib/libc/locale/collate.c Tue Aug 12 17:29:20 2014 (r272296) @@ -51,18 +51,50 @@ #ifdef _UNICODE_SOURCE -__colldb_t * +#include +#include +#include +#include +#include + + +struct __colldb { + uint32_t version; + void *handle; +}; + + +static void *handle = NULL; +static pthread_once_t once = PTHREAD_ONCE_INIT; + + +static void +__colldb_root_init(void) +{ + handle = __colldb_open("/usr/share/colldb/root.db"); +} + + +void * +__colldb_root_handle(void) +{ + pthread_once(&once, &__colldb_root_init); + return (handle); +} + + +void * __colldb_create(const char *path, int mode) { DBT key; DBT value; DB *db = NULL; int error = 0; + void *colldb = NULL; uint32_t version = 0; int flags = (O_RDWR | O_CREAT | O_TRUNC); - __colldb_t *colldb = NULL; - colldb = calloc(1, sizeof(*colldb)); + colldb = calloc(1, sizeof(struct __colldb)); if (colldb == NULL) { errno = ENOMEM; @@ -76,7 +108,7 @@ errno = error; return (NULL); } - colldb->version = __COLLATION_VERSION; + ((struct __colldb*)colldb)->version = __COLLDB_VERSION; key.data = "TYPE"; value.data = "COLLATION"; @@ -89,17 +121,17 @@ } key.data = "VERSION"; - version = htonl(colldb->version); + version = htonl(((struct __colldb*)colldb)->version); value.data = &version; key.size = (strlen("VERSION") + 1); - value.size = sizeof(colldb->version); + value.size = sizeof(((struct __colldb*)colldb)->version); if (db->put(db, &key, &value, 0) == -1) { error = errno; goto failure; } - colldb->handle = db; + ((struct __colldb*)colldb)->handle = db; return (colldb); failure: @@ -110,7 +142,7 @@ } -__colldb_t * +void * __colldb_open(const char *path) { DBT key; @@ -118,10 +150,10 @@ DB *db = NULL; int error = 0; int state = 0; + void *colldb = NULL; int flags = O_RDONLY; - __colldb_t *colldb = NULL; - colldb = calloc(1, sizeof(*colldb)); + colldb = calloc(1, sizeof(struct __colldb)); if (colldb == NULL) { errno = ENOMEM; @@ -164,9 +196,10 @@ error = EFTYPE; goto failure; } - colldb->version = ntohl(*(const uint32_t*)value.data); + ((struct __colldb*)colldb)->version = + ntohl(*(const uint32_t*)value.data); - colldb->handle = db; + ((struct __colldb*)colldb)->handle = db; return (colldb); failure: @@ -178,7 +211,7 @@ int -__colldb_close(__colldb_t *colldb) +__colldb_close(void *colldb) { DB *db = NULL; int error = 0; @@ -188,7 +221,7 @@ errno = EINVAL; return (-1); } - db = colldb->handle; + db = ((struct __colldb*)colldb)->handle; if (db == NULL) { errno = EINVAL; @@ -207,7 +240,7 @@ int -__colldb_sync(__colldb_t *colldb) +__colldb_sync(void *colldb) { DB *db = NULL; @@ -216,7 +249,7 @@ errno = EINVAL; return (-1); } - db = colldb->handle; + db = ((struct __colldb*)colldb)->handle; if (db == NULL) { errno = EINVAL; @@ -227,14 +260,15 @@ int -__colldb_get(__colldb_t *colldb, - struct __colldb_key *key, - struct __colldb_value *value) +__colldb_get(void *colldb, + struct __colldb_key *key, + struct __colldb_value *value) { DBT dbkey; DBT dbvalue; DB *db = NULL; size_t i = 0; + int error = 0; int state = 0; uint32_t *keybuf = NULL; struct __colldb_weight *weights = NULL; @@ -244,37 +278,37 @@ errno = EINVAL; return (-1); } - db = colldb->handle; + db = ((struct __colldb*)colldb)->handle; if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) { errno = EINVAL; return (-1); } - keybuf = key->chars; - if (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__) + keybuf = malloc(key->count * sizeof(*key->chars)); + if (keybuf == NULL) { - keybuf = malloc(key->count * sizeof(*key->chars)); - if (keybuf == NULL) - { - errno = ENOMEM; - return (-1); - } - for (i = 0; i < key->count; ++i) - keybuf[i] = htonl(key->chars[i]); + errno = ENOMEM; + return (-1); } + for (i = 0; i < key->count; ++i) + keybuf[i] = htonl(key->chars[i]); dbkey.data = keybuf; dbkey.size = (key->count * sizeof(*key->chars)); state = db->get(db, &dbkey, &dbvalue, 0); if (state != 0) + { + error = errno; + free(keybuf); + errno = error; return (state); + } weights = dbvalue.data; if ((dbvalue.size / sizeof(*weights)) > value->count) { - if (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__) - free(keybuf); + free(keybuf); errno = ERANGE; return (-1); } @@ -287,16 +321,15 @@ value->weights[i].level3 = ntohl(weights[i].level3); value->weights[i].level4 = ntohl(weights[i].level4); } - if (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__) - free(keybuf); + free(keybuf); return (0); } int -__colldb_put(__colldb_t *colldb, - struct __colldb_key *key, - struct __colldb_value *value) +__colldb_put(void *colldb, + struct __colldb_key *key, + struct __colldb_value *value) { DBT dbkey; DBT dbvalue; @@ -312,34 +345,30 @@ errno = EINVAL; return (-1); } - db = colldb->handle; + db = ((struct __colldb*)colldb)->handle; if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) { errno = EINVAL; return (-1); } - keybuf = key->chars; valuebuf = value->weights; - if (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__) + keybuf = malloc(key->count * sizeof(*key->chars)); + valuebuf = malloc(value->count * sizeof(*value->weights)); + if ((keybuf == NULL) || (valuebuf == NULL)) { - keybuf = malloc(key->count * sizeof(*key->chars)); - valuebuf = malloc(value->count * sizeof(*value->weights)); - if ((keybuf == NULL) || (valuebuf == NULL)) - { - errno = ENOMEM; - return (-1); - } - for (i = 0; i < key->count; ++i) - keybuf[i] = htonl(key->chars[i]); - for (i = 0; i < value->count; ++i) - { - valuebuf[i].alternate = value->weights[i].alternate; - valuebuf[i].level1 = htonl(value->weights[i].level1); - valuebuf[i].level2 = htonl(value->weights[i].level2); - valuebuf[i].level3 = htonl(value->weights[i].level3); - valuebuf[i].level4 = htonl(value->weights[i].level4); - } + errno = ENOMEM; + return (-1); + } + for (i = 0; i < key->count; ++i) + keybuf[i] = htonl(key->chars[i]); + for (i = 0; i < value->count; ++i) + { + valuebuf[i].alternate = value->weights[i].alternate; + valuebuf[i].level1 = htonl(value->weights[i].level1); + valuebuf[i].level2 = htonl(value->weights[i].level2); + valuebuf[i].level3 = htonl(value->weights[i].level3); + valuebuf[i].level4 = htonl(value->weights[i].level4); } dbkey.data = keybuf; @@ -347,7 +376,7 @@ dbkey.size = (key->count * sizeof(*key->chars)); dbvalue.size = (value->count * sizeof(*value->weights)); state = db->put(db, &dbkey, &dbvalue, 0); - if (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__) + if (state != 0) { error = errno; free(keybuf); @@ -504,7 +533,7 @@ return (_LDP_ERROR); } -#define FREAD(a, b, c, d) \ +#define COLL_FREAD(a, b, c, d) \ { \ if (fread(a, b, c, d) != c) { \ saverr = errno; \ @@ -517,9 +546,9 @@ } \ } - FREAD(TMP_substitute_table, sizeof(__collate_substitute_table), 1, fp); - FREAD(TMP_char_pri_table, sizeof(__collate_char_pri_table), 1, fp); - FREAD(TMP_chain_pri_table, + COLL_FREAD(TMP_substitute_table, sizeof(__collate_substitute_table), 1, fp); + COLL_FREAD(TMP_char_pri_table, sizeof(__collate_char_pri_table), 1, fp); + COLL_FREAD(TMP_chain_pri_table, sizeof(*__collate_chain_pri_table), chains, fp); (void)fclose(fp); Modified: soc2014/ghostmansd/head/lib/libc/locale/xlocale.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/locale/xlocale.c Tue Aug 12 16:51:37 2014 (r272295) +++ soc2014/ghostmansd/head/lib/libc/locale/xlocale.c Tue Aug 12 17:29:20 2014 (r272296) @@ -81,6 +81,9 @@ &__xlocale_global_time, &__xlocale_global_messages }, +#ifdef _UNICODE_SOURCE + NULL, +#endif 1, 0, 1, @@ -94,6 +97,9 @@ &__xlocale_C_ctype, 0, 0, 0, 0 }, +#ifdef _UNICODE_SOURCE + NULL, +#endif 1, 0, 1, Modified: soc2014/ghostmansd/head/lib/libc/locale/xlocale_private.h ============================================================================== --- soc2014/ghostmansd/head/lib/libc/locale/xlocale_private.h Tue Aug 12 16:51:37 2014 (r272295) +++ soc2014/ghostmansd/head/lib/libc/locale/xlocale_private.h Tue Aug 12 17:29:20 2014 (r272296) @@ -56,8 +56,8 @@ #define __UC_NFKC 4 size_t __ucsnorm(uint32_t*, const uint32_t*, size_t, int); -#define COLLDB_VERSION 0x00000001 -#define COLLDB_WEIGHTS_MAX 10 +#define __COLLDB_VERSION 0x00000001 +#define __COLLDB_WEIGHTS_MAX 10 struct __colldb_weight { uint8_t alternate; uint32_t level1; @@ -67,28 +67,28 @@ }; struct __colldb_key { size_t count; - uint32_t *chars; + const uint32_t *chars; }; struct __colldb_value { size_t count; struct __colldb_weight *weights; }; -typedef struct __colldb __colldb_t; -#define __colldb_root (__colldb_root_handle()) +void *__colldb_root_handle(void); +#define __colldb_root (__colldb_root_handle()) -__colldb_t* __colldb_create(const char*, int mode); -__colldb_t* __colldb_open(const char*); -int __colldb_close(__colldb_t*); -int __colldb_sync(__colldb_t*); -int __colldb_get(__colldb_t*, +void* __colldb_create(const char*, int mode); +void* __colldb_open(const char*); +int __colldb_close(void*); +int __colldb_sync(void*); +int __colldb_get(void*, struct __colldb_key*, struct __colldb_value*); -int __colldb_put(__colldb_t*, +int __colldb_put(void*, struct __colldb_key*, struct __colldb_value*); -size_t __ucsxfrm(uint32_t*, const uint32_t*, size_t, const __colldb_t*); -int __ucscoll(const uint32_t*, const uint32_t*, const __colldb_t*); +size_t __ucsxfrm(uint32_t*, const uint32_t*, size_t, void*); +int __ucscoll(const uint32_t*, const uint32_t*, void*); #endif @@ -138,9 +138,8 @@ /** Components for the locale. */ struct xlocale_component *components[XLC_LAST]; #ifdef _UNICODE_SOURCE - /** Collation table (NULL means DUCET). */ - size_t collsize; - struct __collation *colltable; + /** Collation Database handle. */ + void *colldb; #endif /** Flag indicating if components[XLC_MONETARY] has changed since the * last call to localeconv_l() with this locale. */ Added: soc2014/ghostmansd/head/lib/libc/unicode/Makefile.inc ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/ghostmansd/head/lib/libc/unicode/Makefile.inc Tue Aug 12 17:29:20 2014 (r272296) @@ -0,0 +1,6 @@ +# from @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 + +# unicode sources +.PATH: ${LIBC_SRCTOP}/${LIBC_ARCH}/unicode ${LIBC_SRCTOP}/unicode + +SRCS+= uccclass.c ucscanon.c ucscoll.c ucsnorm.c ucsxfrm.c Modified: soc2014/ghostmansd/head/lib/libc/unicode/coll.h ============================================================================== --- soc2014/ghostmansd/head/lib/libc/unicode/coll.h Tue Aug 12 16:51:37 2014 (r272295) +++ soc2014/ghostmansd/head/lib/libc/unicode/coll.h Tue Aug 12 17:29:20 2014 (r272296) @@ -26,28 +26,11 @@ #include #include "xlocale_private.h" -static __colldb_t *handle = NULL; -static pthread_once_t once = PTHREAD_ONCE_INIT; - - -static __colldb_t -__colldb_root_init(void) -{ - handle = __colldb_open("/usr/share/colldb/root.db"); -} - - -__colldb_t * -__colldb_root_handle(void) -{ - pthread_once(&once, &__colldb_root_init); - return handle; -} static size_t -__coll_iter(const uint32_t *iter, __colldb_t *colldb, struct __colldb_value *val, - struct __colldb_weight *default_weights[2]) +__coll_iter(const uint32_t *iter, void *colldb, struct __colldb_value *val, + struct __colldb_weight default_weights[2]) { int state = 0; size_t shift = 0; @@ -58,7 +41,7 @@ if (*(iter + shift - 1) == 0) break; key.count = shift; - key.chars = norm; + key.chars = iter; state = __colldb_get(colldb, &key, val); if (state == -1) return (0); @@ -73,7 +56,7 @@ if (*(iter + shift - 1) == 0) break; key.count = shift; - key.chars = norm; + key.chars = iter; state = __colldb_get(__colldb_root, &key, val); if (state == -1) return (0); @@ -85,7 +68,7 @@ if (state != 0) { shift = 1; - (*default_weights)[0].level1 = 0xFBC0; + default_weights[0].level1 = 0xFBC0; if (((0x4E00 <= *iter) && (*iter <= 0x9FCC)) || (*iter == 0xFA0E) || (*iter == 0xFA0F) || (*iter == 0xFA11) || (*iter == 0xFA13) || @@ -93,15 +76,15 @@ (*iter == 0xFA21) || (*iter == 0xFA23) || (*iter == 0xFA24) || (*iter == 0xFA27) || (*iter == 0xFA28) || (*iter == 0xFA29)) - (*default_weights)[0].level1 = 0xFB40; + default_weights[0].level1 = 0xFB40; else if (((0x3400 <= *iter) && (*iter <= 0x4DB5)) || ((0x20000 <= *iter) && (*iter <= 0x2A6D6)) || ((0x2A700 <= *iter) && (*iter <= 0x2B734)) || ((0x2B740 <= *iter) && (*iter <= 0x2B81D))) - (*default_weights)[0].level1 = 0xFB80; - (*default_weights)[0].level1 = ((*default_weights)[0].level1 + (*iter >> 15)); - (*default_weights)[1].level1 = ((*iter & 0x7FFF) | 0x8000); - val->weights = *default_weights; + default_weights[0].level1 = 0xFB80; + default_weights[0].level1 = (default_weights[0].level1 + (*iter >> 15)); + default_weights[1].level1 = ((*iter & 0x7FFF) | 0x8000); + val->weights = default_weights; val->count = 2; } *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-soc-all@FreeBSD.ORG Tue Aug 12 22:38:53 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7CD5B9C7 for ; Tue, 12 Aug 2014 22:38:53 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 697792025 for ; Tue, 12 Aug 2014 22:38:53 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7CMcrEO019666 for ; Tue, 12 Aug 2014 22:38:53 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7CMcqno019658 for svn-soc-all@FreeBSD.org; Tue, 12 Aug 2014 22:38:52 GMT (envelope-from op@FreeBSD.org) Date: Tue, 12 Aug 2014 22:38:52 GMT Message-Id: <201408122238.s7CMcqno019658@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272309 - in soc2014/op/freebsd-base/sys: kern sys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Aug 2014 22:38:53 -0000 Author: op Date: Tue Aug 12 22:38:52 2014 New Revision: 272309 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272309 Log: KSP: fixed panic on module unload case, and added stubs for protection changes currently protection changes are unneeded, because the whole kernel image mappad with RWX protection... Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/smap+kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c soc2014/op/freebsd-base/sys/sys/selfpatch.h Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Tue Aug 12 21:51:31 2014 (r272308) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Tue Aug 12 22:38:52 2014 (r272309) @@ -65,6 +65,11 @@ __noinline void lf_selfpatch_selftest(void); #endif +static void lf_open_kernel_text(struct lf_selfpatch *p); +static void lf_close_kernel_text(struct lf_selfpatch *p); +static void lf_open_module_text(struct lf_selfpatch *p); +static void lf_close_module_text(struct lf_selfpatch *p); + bool lf_selfpatch_patch_needed(struct lf_selfpatch *p) { @@ -127,15 +132,9 @@ for (patch = start; patch != stop; patch++) { DBG("apply: %p\n", patch); - if (mod == KSP_MODULE) { - ret = lf_selfpatch_apply_module(lf, patch); - if (ret != 0) - return (ret); - } else { - ret = lf_selfpatch_apply(lf, patch); - if (ret != 0) - return (ret); - } + ret = lf_selfpatch_apply(lf, patch, mod); + if (ret != 0) + return (ret); } #ifdef KSP_DEBUG @@ -149,11 +148,8 @@ } int -lf_selfpatch_apply(linker_file_t lf, struct lf_selfpatch *p) +lf_selfpatch_apply(linker_file_t lf, struct lf_selfpatch *p, int mod) { - vm_paddr_t pages[4]; - vm_offset_t page_offset; - int i, page_number; /* Refuse to patch if securelevel raised */ if (prison0.pr_securelevel > 0) @@ -176,77 +172,94 @@ if (p->patch_size != p->patchable_size) panic("%s: patch_size != patchable_size", __func__); - page_offset = (vm_offset_t)p->patchable & (vm_offset_t)PAGE_MASK; - page_number = (p->patchable_size >> PAGE_SHIFT) + - ((page_offset + p->patchable_size) > PAGE_SIZE ? 2 : 1); - - DBG("page_number: %d\n", page_number); - - KASSERT(page_number < 4, - ("patch size longer than 3 page does not supported yet\n")); - - DBG("change mapping attribute from RX to RWX:\n"); - for (i=0; ipatchable) + i * PAGE_SIZE; - pages[i] = pmap_kextract(kva); + /* + * replace the instructions + */ + memcpy(p->patchable, p->patch, p->patchable_size); - DBG("kva: %p page: %p\n", (void *)kva, (void *)pages[i]); -#ifdef NOT_THE_RIGHT_API - pmap_kenter_attr(kva, pages[i], VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE); -#endif - } - DBG("done.\n"); + if (mod == KSP_MODULE) + lf_close_module_text(p); + else + lf_close_kernel_text(p); - memcpy(p->patchable, p->patch, p->patchable_size); DBG("patched.\n"); - DBG("change mapping attribute from RWX to RX:\n"); - for (i=0; ipatchable) + i * PAGE_SIZE; -#ifdef NOT_THE_RIGHT_API - pmap_kenter_attr(kva, pages[i], VM_PROT_READ | VM_PROT_EXECUTE); -#endif - } - DBG("done.\n"); - return (0); } -int -lf_selfpatch_apply_module(linker_file_t lf, struct lf_selfpatch *p) +static void +lf_open_kernel_text(struct lf_selfpatch *p) { + /* + * dummy function, currently unused becasue the kernel + * protection is RWX + */ +#if 0 + pmap_protect(kernel_pmap, sva, eva, + VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE); +#endif +} - /* Refuse to patch if securelevel raised */ - if (prison0.pr_securelevel > 0) - return (EPERM); - - DBG("patchable: %p\n", p->patchable); - DBG("patch: %p\n", p->patch); - DBG("feature selector: %d\n", p->feature_selector); - DBG("feature: %d\n", p->feature); - DBG("patchable size: %d\n", p->patchable_size); - DBG("patch size: %d\n", p->patch_size); - DBG("comment: %s\n", p->comment); - - if (!lf_selfpatch_patch_needed(p)) { - DBG("not needed.\n"); - - return (0); - } +static void +lf_close_kernel_text(struct lf_selfpatch *p) +{ + /* + * dummy function, currently unused becasue the kernel + * protection is RWX + * + * currently flushes the cache after modification + */ +#if 0 + pmap_protect(kernel_pmap, sva, eva, + VM_PROT_READ | VM_PROT_EXECUTE); +#endif - if (p->patch_size != p->patchable_size) - panic("%s: patch_size != patchable_size", __func__); + /* Flushes caches and TLBs. */ + wbinvd(); + invltlb(); +} - memcpy(p->patchable, p->patch, p->patchable_size); +static void +lf_open_module_text(struct lf_selfpatch *p) +{ + /* + * dummy function, currently unused becasue the kernel + * protection is RWX + */ +#if 0 + pmap_protect(module_pmap, sva, eva, + VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE); +#endif +} - DBG("patched.\n"); +static void +lf_close_module_text(struct lf_selfpatch *p) +{ + /* + * dummy function, currently unused becasue the kernel + * protection is RWX + * + * currently flushes the cache after modification + */ +#if 0 + pmap_protect(module_pmap, sva, eva, + VM_PROT_READ | VM_PROT_EXECUTE); +#endif - return (0); + /* Flushes caches and TLBs. */ + wbinvd(); + invltlb(); } #ifdef KSP_DEBUG Modified: soc2014/op/freebsd-base/sys/sys/selfpatch.h ============================================================================== --- soc2014/op/freebsd-base/sys/sys/selfpatch.h Tue Aug 12 21:51:31 2014 (r272308) +++ soc2014/op/freebsd-base/sys/sys/selfpatch.h Tue Aug 12 22:38:52 2014 (r272309) @@ -63,7 +63,6 @@ extern char *selfpatch_nop_table[]; int lf_selfpatch(linker_file_t lf, int mod); -int lf_selfpatch_apply(linker_file_t lf, struct lf_selfpatch *patch); -int lf_selfpatch_apply_module(linker_file_t lf, struct lf_selfpatch *patch); +int lf_selfpatch_apply(linker_file_t lf, struct lf_selfpatch *patch, int mod); #endif /* __SELFPATH_H__ */ From owner-svn-soc-all@FreeBSD.ORG Tue Aug 12 23:03:12 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C2BBC192 for ; Tue, 12 Aug 2014 23:03:12 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id AF75223E7 for ; Tue, 12 Aug 2014 23:03:12 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7CN3CRj073096 for ; Tue, 12 Aug 2014 23:03:12 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7CN3BRY073093 for svn-soc-all@FreeBSD.org; Tue, 12 Aug 2014 23:03:11 GMT (envelope-from dpl@FreeBSD.org) Date: Tue, 12 Aug 2014 23:03:11 GMT Message-Id: <201408122303.s7CN3BRY073093@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272310 - soc2014/dpl/llvm_examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Aug 2014 23:03:12 -0000 Author: dpl Date: Tue Aug 12 23:03:11 2014 New Revision: 272310 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272310 Log: Added necessary boilerplate to get it working without includes. Added: soc2014/dpl/llvm_examples/structs.ll Modified: soc2014/dpl/llvm_examples/structs.c Modified: soc2014/dpl/llvm_examples/structs.c ============================================================================== --- soc2014/dpl/llvm_examples/structs.c Tue Aug 12 22:38:52 2014 (r272309) +++ soc2014/dpl/llvm_examples/structs.c Tue Aug 12 23:03:11 2014 (r272310) @@ -1,11 +1,34 @@ -#include -#include -#include -#include +#include #include +struct mbuf { + struct mbuf *m_next; + struct mbuf *m_nextpkt; + void *m_data; + int m_len; /* length in this mbuf */ + int m_flags; + struct { + struct ifnet *rcvif; + int len; /* total packet len */ + SLIST_HEAD (packet_tags, m_tag) tags; + } m_pkthdr; + struct skbuf *m_skb; + + /* + * in-stack mbuffers point to an external buffer, + * the two variables below contain base and size, + * and have M_STACK set in m_flags. + * Buffers from the heap have __m_extbuf = (char *)m + MSIZE + */ + void *__m_extbuf; /* external buffer base */ + int __m_extlen; /* data in ext buffer */ + void (*__m_callback)(struct mbuf *, int); + void *__m_peer; /* argument attached to the mbuf */ +}; + struct mbuf gmbuf; +#define mtod(m, t) ((t)((m)->m_data)) int main() @@ -15,7 +38,7 @@ struct ip *ip = mtod(m, struct ip *); m = &gmbuf; - pktlen = m->pkthdr.len; + pktlen = m->m_pkthdr.len; return (0); } Added: soc2014/dpl/llvm_examples/structs.ll ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/dpl/llvm_examples/structs.ll Tue Aug 12 23:03:11 2014 (r272310) @@ -0,0 +1,41 @@ +; ModuleID = 'structs.c' +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-freebsd11.0" + +%struct.mbuf = type { %struct.mbuf*, %struct.mbuf*, i8*, i32, i32, %struct.anon, %struct.skbuf*, i8*, i32, void (%struct.mbuf*, i32)*, i8* } +%struct.anon = type { %struct.ifnet*, i32, %struct.packet_tags } +%struct.ifnet = type opaque +%struct.packet_tags = type { %struct.m_tag* } +%struct.m_tag = type opaque +%struct.skbuf = type opaque +%struct.ip = type opaque + +@gmbuf = common global %struct.mbuf zeroinitializer, align 8 + +; Function Attrs: nounwind uwtable +define i32 @main() #0 { +entry: + %retval = alloca i32, align 4 + %m = alloca %struct.mbuf*, align 8 + %pktlen = alloca i32, align 4 + %ip = alloca %struct.ip*, align 8 + store i32 0, i32* %retval + %0 = load %struct.mbuf** %m, align 8 + %m_data = getelementptr inbounds %struct.mbuf* %0, i32 0, i32 2 + %1 = load i8** %m_data, align 8 + %2 = bitcast i8* %1 to %struct.ip* + store %struct.ip* %2, %struct.ip** %ip, align 8 + store %struct.mbuf* @gmbuf, %struct.mbuf** %m, align 8 + %3 = load %struct.mbuf** %m, align 8 + %m_pkthdr = getelementptr inbounds %struct.mbuf* %3, i32 0, i32 5 + %len = getelementptr inbounds %struct.anon* %m_pkthdr, i32 0, i32 1 + %4 = load i32* %len, align 4 + store i32 %4, i32* %pktlen, align 4 + ret i32 0 +} + +attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.ident = !{!0} + +!0 = metadata !{metadata !"FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512"} From owner-svn-soc-all@FreeBSD.ORG Tue Aug 12 23:22:39 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 940954BE for ; Tue, 12 Aug 2014 23:22:39 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 73F5725A3 for ; Tue, 12 Aug 2014 23:22:39 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7CNMdj0015162 for ; Tue, 12 Aug 2014 23:22:39 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7CNMdXF015160 for svn-soc-all@FreeBSD.org; Tue, 12 Aug 2014 23:22:39 GMT (envelope-from op@FreeBSD.org) Date: Tue, 12 Aug 2014 23:22:39 GMT Message-Id: <201408122322.s7CNMdXF015160@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272311 - soc2014/op/freebsd-base/sys/kern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Aug 2014 23:22:39 -0000 Author: op Date: Tue Aug 12 23:22:38 2014 New Revision: 272311 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272311 Log: KSP: added KSP_WxorX_KERNEL guard, and added more code to KSP_WxorX_KERNEL case Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/smap+kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Tue Aug 12 23:03:11 2014 (r272310) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Tue Aug 12 23:22:38 2014 (r272311) @@ -26,7 +26,7 @@ * $FreeBSD$ */ -//#include "opt_selfpatch.h" +#include "opt_selfpatch.h" #include @@ -54,6 +54,10 @@ printf(__VA_ARGS__); \ } +#ifdef KSP_WxorX_KERNEL +#undef KSP_WxorX_KERNEL +#endif /* KSP_WxorX_KERNEL */ + extern struct lf_selfpatch __start_set_selfpatch_set[]; extern struct lf_selfpatch __stop_set_selfpatch_set[]; @@ -205,7 +209,14 @@ * dummy function, currently unused becasue the kernel * protection is RWX */ -#if 0 +#ifdef KSP_WxorX_KERNEL + vm_offset_t eva, sva; + + eva = (vm_offset_t)(p->patchable); + sva = (vm_offset_t)(p->patchable + p->patchable_size); + + DBG("kernel: %p - %p RX -> RWX" + (void *)sva, (void *)eva); pmap_protect(kernel_pmap, sva, eva, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE); #endif @@ -220,7 +231,14 @@ * * currently flushes the cache after modification */ -#if 0 +#ifdef KSP_WxorX_KERNEL + vm_offset_t eva, sva; + + eva = (vm_offset_t)(p->patchable); + sva = (vm_offset_t)(p->patchable + p->patchable_size); + DBG("kernel: %p - %p RWX -> RX", + (void *)sva, (void *)eva); + pmap_protect(kernel_pmap, sva, eva, VM_PROT_READ | VM_PROT_EXECUTE); #endif @@ -228,6 +246,8 @@ /* Flushes caches and TLBs. */ wbinvd(); invltlb(); + + DBG("caches flushed."); } static void @@ -237,7 +257,14 @@ * dummy function, currently unused becasue the kernel * protection is RWX */ -#if 0 +#ifdef KSP_WxorX_KERNEL + vm_offset_t eva, sva; + + eva = (vm_offset_t)(p->patchable); + sva = (vm_offset_t)(p->patchable + p->patchable_size); + DBG("module: %p - %p RX -> RWX", + (void *)sva, (void *)eva); + pmap_protect(module_pmap, sva, eva, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE); #endif @@ -252,7 +279,14 @@ * * currently flushes the cache after modification */ -#if 0 +#ifdef KSP_WxorX_KERNEL + vm_offset_t eva, sva; + + eva = (vm_offset_t)(p->patchable); + sva = (vm_offset_t)(p->patchable + p->patchable_size); + DBG("module: %p - %p RWX -> RX", + (void *)sva, (void *)eva); + pmap_protect(module_pmap, sva, eva, VM_PROT_READ | VM_PROT_EXECUTE); #endif From owner-svn-soc-all@FreeBSD.ORG Tue Aug 12 23:29:31 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D7F08667 for ; Tue, 12 Aug 2014 23:29:31 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C3B3425F9 for ; Tue, 12 Aug 2014 23:29:31 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7CNTVHb020068 for ; Tue, 12 Aug 2014 23:29:31 GMT (envelope-from ghostmansd@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7CNTT46020047 for svn-soc-all@FreeBSD.org; Tue, 12 Aug 2014 23:29:29 GMT (envelope-from ghostmansd@FreeBSD.org) Date: Tue, 12 Aug 2014 23:29:29 GMT Message-Id: <201408122329.s7CNTT46020047@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to ghostmansd@FreeBSD.org using -f From: ghostmansd@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272312 - in soc2014/ghostmansd/head/lib/libc: locale unicode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Aug 2014 23:29:32 -0000 Author: ghostmansd Date: Tue Aug 12 23:29:29 2014 New Revision: 272312 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272312 Log: various style(9) fixes as suggested by Pedro Modified: soc2014/ghostmansd/head/lib/libc/locale/collate.c soc2014/ghostmansd/head/lib/libc/unicode/uccclass.c soc2014/ghostmansd/head/lib/libc/unicode/ucscanon.c soc2014/ghostmansd/head/lib/libc/unicode/ucscoll.c soc2014/ghostmansd/head/lib/libc/unicode/ucsnorm.c soc2014/ghostmansd/head/lib/libc/unicode/ucsxfrm.c Modified: soc2014/ghostmansd/head/lib/libc/locale/collate.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/locale/collate.c Tue Aug 12 23:22:38 2014 (r272311) +++ soc2014/ghostmansd/head/lib/libc/locale/collate.c Tue Aug 12 23:29:29 2014 (r272312) @@ -95,14 +95,12 @@ int flags = (O_RDWR | O_CREAT | O_TRUNC); colldb = calloc(1, sizeof(struct __colldb)); - if (colldb == NULL) - { + if (colldb == NULL) { errno = ENOMEM; return (NULL); } db = dbopen(path, flags, mode, DB_HASH, NULL); - if (db == NULL) - { + if (db == NULL) { error = errno; free(colldb); errno = error; @@ -114,8 +112,7 @@ value.data = "COLLATION"; key.size = (strlen("TYPE") + 1); value.size = (strlen("COLLATION") + 1); - if (db->put(db, &key, &value, 0) == -1) - { + if (db->put(db, &key, &value, 0) == -1) { error = errno; goto failure; } @@ -125,8 +122,7 @@ value.data = &version; key.size = (strlen("VERSION") + 1); value.size = sizeof(((struct __colldb*)colldb)->version); - if (db->put(db, &key, &value, 0) == -1) - { + if (db->put(db, &key, &value, 0) == -1) { error = errno; goto failure; } @@ -154,14 +150,12 @@ int flags = O_RDONLY; colldb = calloc(1, sizeof(struct __colldb)); - if (colldb == NULL) - { + if (colldb == NULL) { errno = ENOMEM; return (NULL); } db = dbopen(path, flags, 0, DB_HASH, NULL); - if (db == NULL) - { + if (db == NULL) { error = errno; free(colldb); errno = error; @@ -171,16 +165,14 @@ key.data = "TYPE"; key.size = (strlen("TYPE") + 1); state = db->get(db, &key, &value, 0); - if (state != 0) - { + if (state != 0) { if (state < 0) error = errno; else error = EFTYPE; goto failure; } - if (strcmp(value.data, "COLLATION") != 0) - { + if (strcmp(value.data, "COLLATION") != 0) { error = EFTYPE; goto failure; } @@ -188,8 +180,7 @@ key.data = "VERSION"; key.size = (strlen("VERSION") + 1); state = db->get(db, &key, &value, 0); - if (state != 0) - { + if (state != 0) { if (state < 0) error = errno; else @@ -216,19 +207,16 @@ DB *db = NULL; int error = 0; - if (colldb == NULL) - { + if (colldb == NULL) { errno = EINVAL; return (-1); } db = ((struct __colldb*)colldb)->handle; - if (db == NULL) - { + if (db == NULL) { errno = EINVAL; return (-1); } - if (db->close(db) == -1) - { + if (db->close(db) == -1) { error = errno; free(colldb); errno = error; @@ -244,14 +232,12 @@ { DB *db = NULL; - if (colldb == NULL) - { + if (colldb == NULL) { errno = EINVAL; return (-1); } db = ((struct __colldb*)colldb)->handle; - if (db == NULL) - { + if (db == NULL) { errno = EINVAL; return (-1); } @@ -273,21 +259,18 @@ uint32_t *keybuf = NULL; struct __colldb_weight *weights = NULL; - if ((colldb == NULL) || (key == NULL) || (value == NULL)) - { + if ((colldb == NULL) || (key == NULL) || (value == NULL)) { errno = EINVAL; return (-1); } db = ((struct __colldb*)colldb)->handle; - if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) - { + if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) { errno = EINVAL; return (-1); } keybuf = malloc(key->count * sizeof(*key->chars)); - if (keybuf == NULL) - { + if (keybuf == NULL) { errno = ENOMEM; return (-1); } @@ -297,8 +280,7 @@ dbkey.data = keybuf; dbkey.size = (key->count * sizeof(*key->chars)); state = db->get(db, &dbkey, &dbvalue, 0); - if (state != 0) - { + if (state != 0) { error = errno; free(keybuf); errno = error; @@ -306,15 +288,13 @@ } weights = dbvalue.data; - if ((dbvalue.size / sizeof(*weights)) > value->count) - { + if ((dbvalue.size / sizeof(*weights)) > value->count) { free(keybuf); errno = ERANGE; return (-1); } value->count = (dbvalue.size / sizeof(*weights)); - for (i = 0; i < value->count; ++i) - { + for (i = 0; i < value->count; ++i) { value->weights[i].alternate = weights[i].alternate; value->weights[i].level1 = ntohl(weights[i].level1); value->weights[i].level2 = ntohl(weights[i].level2); @@ -340,14 +320,12 @@ uint32_t *keybuf = NULL; struct __colldb_weight *valuebuf = NULL; - if ((colldb == NULL) || (key == NULL) || (value == NULL)) - { + if ((colldb == NULL) || (key == NULL) || (value == NULL)) { errno = EINVAL; return (-1); } db = ((struct __colldb*)colldb)->handle; - if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) - { + if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) { errno = EINVAL; return (-1); } @@ -355,15 +333,13 @@ valuebuf = value->weights; keybuf = malloc(key->count * sizeof(*key->chars)); valuebuf = malloc(value->count * sizeof(*value->weights)); - if ((keybuf == NULL) || (valuebuf == NULL)) - { + if ((keybuf == NULL) || (valuebuf == NULL)) { errno = ENOMEM; return (-1); } for (i = 0; i < key->count; ++i) keybuf[i] = htonl(key->chars[i]); - for (i = 0; i < value->count; ++i) - { + for (i = 0; i < value->count; ++i) { valuebuf[i].alternate = value->weights[i].alternate; valuebuf[i].level1 = htonl(value->weights[i].level1); valuebuf[i].level2 = htonl(value->weights[i].level2); @@ -376,8 +352,7 @@ dbkey.size = (key->count * sizeof(*key->chars)); dbvalue.size = (value->count * sizeof(*value->weights)); state = db->put(db, &dbkey, &dbvalue, 0); - if (state != 0) - { + if (state != 0) { error = errno; free(keybuf); free(valuebuf); Modified: soc2014/ghostmansd/head/lib/libc/unicode/uccclass.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/unicode/uccclass.c Tue Aug 12 23:22:38 2014 (r272311) +++ soc2014/ghostmansd/head/lib/libc/unicode/uccclass.c Tue Aug 12 23:29:29 2014 (r272312) @@ -37,9 +37,8 @@ high = COMBINING_CLASS_COUNT; if ((code <= COMBINING_CLASS_MIN) || (code >= COMBINING_CLASS_MAX)) - return 0; - while (low <= high) - { + return (0); + while (low <= high) { mid = (low + ((high - low) / 2)); if (code < combining_class[mid].code) high = (mid - 1); @@ -48,5 +47,5 @@ else return combining_class[mid].ccclass; } - return 0; + return (0); } Modified: soc2014/ghostmansd/head/lib/libc/unicode/ucscanon.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/unicode/ucscanon.c Tue Aug 12 23:22:38 2014 (r272311) +++ soc2014/ghostmansd/head/lib/libc/unicode/ucscanon.c Tue Aug 12 23:29:29 2014 (r272312) @@ -37,25 +37,22 @@ uint32_t cchr = 0; uint32_t lchr = 0; - if (!str) - { + if (!str) { errno = EINVAL; - return -1; + return (-1); } if ((str[0] == 0) || (str[1] == 0)) return 0; - for (++index; str[index] != 0; ++index) - { + for (++index; str[index] != 0; ++index) { cchr = str[index]; lchr = str[index - 1]; lcls = __uccclass(lchr); ccls = __uccclass(cchr); - if ((ccls != 0) && (lcls != 0) && (lcls > ccls)) - { + if ((ccls != 0) && (lcls != 0) && (lcls > ccls)) { str[index] = lchr; str[index - 1] = cchr; index -= ((index > 1) + 1); } } - return 0; + return (0); } Modified: soc2014/ghostmansd/head/lib/libc/unicode/ucscoll.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/unicode/ucscoll.c Tue Aug 12 23:22:38 2014 (r272311) +++ soc2014/ghostmansd/head/lib/libc/unicode/ucscoll.c Tue Aug 12 23:29:29 2014 (r272312) @@ -48,19 +48,16 @@ struct __colldb_weight weights[2][__COLLDB_WEIGHTS_MAX]; const int init_error = errno; - if ((lstr == NULL) || (rstr == NULL)) - { + if ((lstr == NULL) || (rstr == NULL)) { errno = EINVAL; return (0); } if (colldb == NULL) colldb = __colldb_root; - for (i = 0; i < 2; ++i) - { + for (i = 0; i < 2; ++i) { size[i] = __ucsnorm(NULL, str[i], 0, __UC_NFD); norm[i] = malloc(size[i] * sizeof(uint32_t)); - if (__ucsnorm(norm[i], str[i], size[i], __UC_NFD) > size[i]) - { + if (__ucsnorm(norm[i], str[i], size[i], __UC_NFD) > size[i]) { error = errno; free(norm[0]); free(norm[1]); @@ -72,22 +69,18 @@ if (colldb == NULL) colldb = __colldb_root; - while (*iter[0] != 0) - { - if (*iter[1] == 0) - { + while (*iter[0] != 0) { + if (*iter[1] == 0) { free(norm[0]); free(norm[1]); return (+1); } - for (i = 0; i < 2; ++i) - { + for (i = 0; i < 2; ++i) { val[i].weights = weights[i]; val[i].count = __COLLDB_WEIGHTS_MAX; shift[i] = __coll_iter(iter[0], colldb, &val[i], - default_weights[i]); - if (shift[i] == 0) - { + default_weights[i]); + if (shift[i] == 0) { error = errno; free(norm[0]); free(norm[1]); @@ -100,12 +93,10 @@ cmp = val[0].count; else cmp = val[1].count; - for (i = 0; i < cmp; ++i) - { + for (i = 0; i < cmp; ++i) { state = memcmp(&val[0].weights[i], &val[1].weights[i], - sizeof(struct __colldb_weight)); - if (state != 0) - { + sizeof(struct __colldb_weight)); + if (state != 0) { free(norm[0]); free(norm[1]); errno = init_error; Modified: soc2014/ghostmansd/head/lib/libc/unicode/ucsnorm.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/unicode/ucsnorm.c Tue Aug 12 23:22:38 2014 (r272311) +++ soc2014/ghostmansd/head/lib/libc/unicode/ucsnorm.c Tue Aug 12 23:29:29 2014 (r272312) @@ -42,17 +42,14 @@ *size = 1; high = NORMALIZATION_COUNT; - if (compat) - { - while (low <= high) - { + if (compat) { + while (low <= high) { mid = (low + ((high - low) / 2)); if (*code < normalization[mid].code) high = (mid - 1); else if (*code > normalization[mid].code) low = (mid + 1); - else - { + else { canonical = normalization[mid].canonical; compatible = normalization[mid].compatible; if ((canonical == -1) || (canonical == compatible)) @@ -61,18 +58,14 @@ return (decomposition + compatible); } } - } - else - { - while (low <= high) - { + } else { + while (low <= high) { mid = (low + ((high - low) / 2)); if (*code < normalization[mid].code) high = (mid - 1); else if (*code > normalization[mid].code) low = (mid + 1); - else - { + else { canonical = normalization[mid].canonical; if (canonical == -1) return (code); @@ -98,35 +91,27 @@ const uint32_t *iter = str; const uint32_t *segptr = segbuf; - for (; *iter != 0; ++iter) - { + for (; *iter != 0; ++iter) { code = *iter; segsize = 1; segptr = iter; - if ((HANGUL_SBASE <= code) && (code < (HANGUL_SBASE + HANGUL_SCOUNT))) - { + if ((HANGUL_SBASE <= code) && (code < (HANGUL_SBASE + HANGUL_SCOUNT))) { code -= HANGUL_SBASE; - if (code < HANGUL_SCOUNT) - { + if (code < HANGUL_SCOUNT) { segbuf[0] = (HANGUL_LBASE + (code / HANGUL_NCOUNT)); segbuf[1] = (HANGUL_VBASE + ((code % HANGUL_NCOUNT) / HANGUL_TCOUNT)); segbuf[2] = (HANGUL_TBASE + (code % HANGUL_TCOUNT)); segsize = ((segptr[2] == HANGUL_TBASE) ? 2 : 3); - } - else + } else segbuf[0] = *iter; - } - else if ((DECOMPOSITION_MIN <= code) && (code <= DECOMPOSITION_MAX)) - { + } else if ((DECOMPOSITION_MIN <= code) && (code <= DECOMPOSITION_MAX)) { segptr = decompose_base(&code, &segsize, compat); - if (segptr != &code) - { + if (segptr != &code) { segsize *= sizeof(uint32_t); memcpy(segbuf, segptr, segsize); segsize /= sizeof(uint32_t); segptr = segbuf; - while (tmpsize != segsize) - { + while (tmpsize != segsize) { tmpsize = segsize; tmpbuf[segsize] = 0; segsize *= sizeof(uint32_t); @@ -136,15 +121,13 @@ } } } - if (((reqsize + segsize + 1) > size) && (buffer != NULL)) - { + if (((reqsize + segsize + 1) > size) && (buffer != NULL)) { size = (size - reqsize - 1); memcpy(buffer, segptr, (size * sizeof(uint32_t))); *(buffer + size) = 0; return decompose(NULL, str, 0, compat); } - if (buffer != NULL) - { + if (buffer != NULL) { memcpy(buffer, segptr, (segsize * sizeof(uint32_t))); buffer += segsize; } @@ -170,19 +153,17 @@ /* Hangul L + V composition sequence. */ if (((HANGUL_LBASE <= lchr) && (lchr < (HANGUL_LBASE + HANGUL_LCOUNT))) - && ((HANGUL_VBASE <= cchr) && (cchr < (HANGUL_VBASE + HANGUL_VCOUNT)))) - { + && ((HANGUL_VBASE <= cchr) && (cchr < (HANGUL_VBASE + HANGUL_VCOUNT)))) { code += ((lchr - HANGUL_LBASE) * HANGUL_VCOUNT); code += (cchr - HANGUL_VBASE); code *= HANGUL_TCOUNT; code += HANGUL_SBASE; return (code); } - /* Hangul LV + T composition sequence. */ if ((((lchr - HANGUL_SBASE) % HANGUL_TCOUNT) == 0) - && ((HANGUL_SBASE <= lchr) && (lchr < (HANGUL_SBASE + HANGUL_SCOUNT))) - && ((HANGUL_TBASE <= cchr) && (cchr < (HANGUL_TBASE + HANGUL_TCOUNT)))) + && ((HANGUL_SBASE <= lchr) && (lchr < (HANGUL_SBASE + HANGUL_SCOUNT))) + && ((HANGUL_TBASE <= cchr) && (cchr < (HANGUL_TBASE + HANGUL_TCOUNT)))) return (lchr + (cchr - HANGUL_TBASE)); /* Generic composition sequence. */ @@ -190,15 +171,13 @@ pair = (((uint64_t)cchr << 32) | lchr); if ((pair < COMPOSITION_MIN) || (pair > COMPOSITION_MAX)) return (0); - while (low <= high) - { + while (low <= high) { mid = (low + ((high - low) / 2)); if (pair < composition[mid].pair) high = (mid - 1); else if (pair > composition[mid].pair) high = (mid + 1); - else - { + else { index = composition[mid].index; return (normalization[index].code); } @@ -224,40 +203,33 @@ xlen = decompose(NULL, str, 0, compat); data = malloc(xlen * sizeof(uint32_t)); - if (data == NULL) - { + if (data == NULL) { errno = ENOMEM; return (SIZE_MAX); } - (void) decompose(data, NULL, xlen, compat); - (void) __ucscanon(data); + (void)decompose(data, NULL, xlen, compat); + (void)__ucscanon(data); len = --xlen; lchr = data[0]; lcls = __uccclass(lchr); if (lcls != 0) lcls = 255; - for (; dpos < len; ++dpos) - { + for (; dpos < len; ++dpos) { cchr = data[dpos]; ccls = __uccclass(cchr); code = compose_base(lchr, cchr); - if ((code != 0) && ((lcls < ccls) || (lcls == 0))) - { + if ((code != 0) && ((lcls < ccls) || (lcls == 0))) { data[spos] = code; lchr = code; - } - else - { - if (ccls == 0) - { + } else { + if (ccls == 0) { spos = cpos; lchr = cchr; } lcls = ccls; data[cpos] = cchr; - if (len != xlen) - { + if (len != xlen) { dpos += (len - xlen); xlen = len; } @@ -268,8 +240,7 @@ xlen = ((size >= (len + 1)) ? len : size); if (buffer != NULL) memcpy(buffer, data, (xlen * sizeof(uint32_t))); - if ((buffer == NULL) || (size < (len + 1))) - { + if ((buffer == NULL) || (size < (len + 1))) { if (buffer != NULL) buffer[--xlen] = 0; errno = ERANGE; @@ -285,15 +256,12 @@ size_t __ucsnorm(uint32_t *buffer, const uint32_t *str, size_t size, int form) { - if (!str || (buffer && !size)) - { + if (!str || (buffer && !size)) { errno = EINVAL; return (SIZE_MAX); } - if (*str == 0) - { - if (size == 0) - { + if (*str == 0) { + if (size == 0) { errno = EINVAL; return (SIZE_MAX); } Modified: soc2014/ghostmansd/head/lib/libc/unicode/ucsxfrm.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/unicode/ucsxfrm.c Tue Aug 12 23:22:38 2014 (r272311) +++ soc2014/ghostmansd/head/lib/libc/unicode/ucsxfrm.c Tue Aug 12 23:29:29 2014 (r272312) @@ -31,7 +31,7 @@ size_t __ucsxfrm(uint32_t *buffer, const uint32_t *str, size_t size, - void *colldb) + void *colldb) { size_t i = 0; int error = 0; @@ -47,8 +47,7 @@ struct __colldb_weight weights[__COLLDB_WEIGHTS_MAX]; const int init_error = errno; - if ((str == NULL) || ((buffer != NULL) && (size == 0))) - { + if ((str == NULL) || ((buffer != NULL) && (size == 0))) { errno = EINVAL; return (SIZE_MAX); } @@ -56,48 +55,40 @@ colldb = __colldb_root; normsize = __ucsnorm(NULL, str, 0, __UC_NFD); norm = malloc(normsize * sizeof(uint32_t)); - if (norm == NULL) - { + if (norm == NULL) { errno = ENOMEM; return (SIZE_MAX); } - if (__ucsnorm(norm, str, normsize, __UC_NFD) > normsize) - { + if (__ucsnorm(norm, str, normsize, __UC_NFD) > normsize) { error = errno; free(norm); errno = error; return (SIZE_MAX); } - iter = norm; if (colldb == NULL) colldb = __colldb_root; - while (*iter != 0) - { + while (*iter != 0) { value.weights = weights; value.count = __COLLDB_WEIGHTS_MAX; shift = __coll_iter(iter, colldb, &value, default_weights); - if (shift == 0) - { + if (shift == 0) { error = errno; free(elements); free(norm); errno = error; return (SIZE_MAX); } - free(elements); count = (value.count * 4); elements = malloc(count * sizeof(uint32_t)); - if (elements == NULL) - { + if (elements == NULL) { free(elements); free(norm); errno = ENOMEM; return (SIZE_MAX); } - for (i = 0; i < value.count; ++i) - { + for (i = 0; i < value.count; ++i) { elements[(count * 0) + i] = value.weights[i].level1; elements[(count * 1) + i] = value.weights[i].level2; elements[(count * 2) + i] = value.weights[i].level3; @@ -106,8 +97,7 @@ for (i = 0; i < count; ++i) elements[i] = (elements[i] ? elements[i] : 1); - if (((reqsize + count) > size) && (buffer != NULL)) - { + if (((reqsize + count) > size) && (buffer != NULL)) { count = (size - reqsize - 1); memcpy(buffer, elements, (count * sizeof(uint32_t))); *(buffer + count) = 0; @@ -115,8 +105,7 @@ free(norm); return __ucsxfrm(NULL, str, 0, colldb); } - if (buffer != NULL) - { + if (buffer != NULL) { memcpy(buffer, elements, (count * sizeof(uint32_t))); buffer += count; } From owner-svn-soc-all@FreeBSD.ORG Tue Aug 12 23:43:44 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BAB67A1C for ; Tue, 12 Aug 2014 23:43:44 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A82DE2792 for ; Tue, 12 Aug 2014 23:43:44 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7CNhihp064095 for ; Tue, 12 Aug 2014 23:43:44 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7CNhi2n064076 for svn-soc-all@FreeBSD.org; Tue, 12 Aug 2014 23:43:44 GMT (envelope-from op@FreeBSD.org) Date: Tue, 12 Aug 2014 23:43:44 GMT Message-Id: <201408122343.s7CNhi2n064076@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272313 - soc2014/op/tools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Aug 2014 23:43:44 -0000 Author: op Date: Tue Aug 12 23:43:43 2014 New Revision: 272313 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272313 Log: updated tools/run_smap_test_vm_64bit_with_smap.csh from UP to SMP (4 cpu) Signed-off-by: Oliver Pinter Modified: soc2014/op/tools/run_smap_test_vm_64bit_with_smap.csh Modified: soc2014/op/tools/run_smap_test_vm_64bit_with_smap.csh ============================================================================== --- soc2014/op/tools/run_smap_test_vm_64bit_with_smap.csh Tue Aug 12 23:29:29 2014 (r272312) +++ soc2014/op/tools/run_smap_test_vm_64bit_with_smap.csh Tue Aug 12 23:43:43 2014 (r272313) @@ -14,7 +14,7 @@ set QEMU="${QEMU_PREFIX}/bin/qemu" set QEMU_BIN="${QEMU_PREFIX}/bin/qemu-system-${QTARGET}" -set QEMU_OPTIONS="-cpu ${QCPU},enforce,+smap,+smep,-hypervisor -m 1024M" +set QEMU_OPTIONS="-cpu ${QCPU},enforce,+smap,+smep,-hypervisor -m 1024M -smp 4" set FREEBSD_VMIMAGE="freebsd-${TARGET}.raw" From owner-svn-soc-all@FreeBSD.ORG Wed Aug 13 00:47:13 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 44721A76 for ; Wed, 13 Aug 2014 00:47:13 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1780C2DE8 for ; Wed, 13 Aug 2014 00:47:13 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7D0lCIN005356 for ; Wed, 13 Aug 2014 00:47:12 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7D0lCpv005352 for svn-soc-all@FreeBSD.org; Wed, 13 Aug 2014 00:47:12 GMT (envelope-from op@FreeBSD.org) Date: Wed, 13 Aug 2014 00:47:12 GMT Message-Id: <201408130047.s7D0lCpv005352@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272315 - in soc2014/op/freebsd-base/sys: kern sys x86/x86 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Aug 2014 00:47:13 -0000 Author: op Date: Wed Aug 13 00:47:11 2014 New Revision: 272315 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272315 Log: KSP: constify ksp_selector_table Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/smap+kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c soc2014/op/freebsd-base/sys/sys/selfpatch.h soc2014/op/freebsd-base/sys/x86/x86/selfpatch_machdep.c Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Tue Aug 12 23:48:37 2014 (r272314) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Wed Aug 13 00:47:11 2014 (r272315) @@ -86,7 +86,7 @@ } matched = NULL; - for (e = ksp_selector_table; + for (e = __DECONST(struct ksp_selector_entry *, ksp_selector_table); (e->feature_selector != KSP_NULL) && (e->featurep != NULL); e++) { if (e->feature_selector == p->feature_selector) { Modified: soc2014/op/freebsd-base/sys/sys/selfpatch.h ============================================================================== --- soc2014/op/freebsd-base/sys/sys/selfpatch.h Tue Aug 12 23:48:37 2014 (r272314) +++ soc2014/op/freebsd-base/sys/sys/selfpatch.h Wed Aug 13 00:47:11 2014 (r272315) @@ -40,7 +40,7 @@ }; #define KSP_SELECTOR_END {KSP_NULL, NULL} -extern struct ksp_selector_entry ksp_selector_table[]; +extern const struct ksp_selector_entry ksp_selector_table[]; #define KSP_FEATURE_SELFTEST 1 Modified: soc2014/op/freebsd-base/sys/x86/x86/selfpatch_machdep.c ============================================================================== --- soc2014/op/freebsd-base/sys/x86/x86/selfpatch_machdep.c Tue Aug 12 23:48:37 2014 (r272314) +++ soc2014/op/freebsd-base/sys/x86/x86/selfpatch_machdep.c Wed Aug 13 00:47:11 2014 (r272315) @@ -39,7 +39,7 @@ #include #include -struct ksp_selector_entry ksp_selector_table[] = { +const struct ksp_selector_entry ksp_selector_table[] = { /* feature_selector feature pointer */ {KSP_CPUID, &cpu_feature}, {KSP_CPUID2, &cpu_feature2}, From owner-svn-soc-all@FreeBSD.ORG Wed Aug 13 00:47:25 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4A8A7A89 for ; Wed, 13 Aug 2014 00:47:25 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1DC592DEA for ; Wed, 13 Aug 2014 00:47:25 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7D0lOS8005422 for ; Wed, 13 Aug 2014 00:47:24 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7D0lOxT005419 for svn-soc-all@FreeBSD.org; Wed, 13 Aug 2014 00:47:24 GMT (envelope-from op@FreeBSD.org) Date: Wed, 13 Aug 2014 00:47:24 GMT Message-Id: <201408130047.s7D0lOxT005419@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272316 - soc2014/op/freebsd-base/sys/kern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Aug 2014 00:47:25 -0000 Author: op Date: Wed Aug 13 00:47:24 2014 New Revision: 272316 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272316 Log: KSP: new lines at end of DBG messages Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/smap+kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Wed Aug 13 00:47:11 2014 (r272315) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Wed Aug 13 00:47:24 2014 (r272316) @@ -215,7 +215,7 @@ eva = (vm_offset_t)(p->patchable); sva = (vm_offset_t)(p->patchable + p->patchable_size); - DBG("kernel: %p - %p RX -> RWX" + DBG("kernel: %p - %p RX -> RWX\n" (void *)sva, (void *)eva); pmap_protect(kernel_pmap, sva, eva, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE); @@ -236,7 +236,7 @@ eva = (vm_offset_t)(p->patchable); sva = (vm_offset_t)(p->patchable + p->patchable_size); - DBG("kernel: %p - %p RWX -> RX", + DBG("kernel: %p - %p RWX -> RX\n", (void *)sva, (void *)eva); pmap_protect(kernel_pmap, sva, eva, @@ -247,7 +247,7 @@ wbinvd(); invltlb(); - DBG("caches flushed."); + DBG("caches flushed.\n"); } static void @@ -262,7 +262,7 @@ eva = (vm_offset_t)(p->patchable); sva = (vm_offset_t)(p->patchable + p->patchable_size); - DBG("module: %p - %p RX -> RWX", + DBG("module: %p - %p RX -> RWX\n", (void *)sva, (void *)eva); pmap_protect(module_pmap, sva, eva, @@ -284,7 +284,7 @@ eva = (vm_offset_t)(p->patchable); sva = (vm_offset_t)(p->patchable + p->patchable_size); - DBG("module: %p - %p RWX -> RX", + DBG("module: %p - %p RWX -> RX\n", (void *)sva, (void *)eva); pmap_protect(module_pmap, sva, eva, @@ -294,6 +294,8 @@ /* Flushes caches and TLBs. */ wbinvd(); invltlb(); + + DBG("caches flushed.\n"); } #ifdef KSP_DEBUG From owner-svn-soc-all@FreeBSD.ORG Wed Aug 13 13:55:49 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BD0E8E7E for ; Wed, 13 Aug 2014 13:55:49 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A9DCE2A52 for ; Wed, 13 Aug 2014 13:55:49 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7DDtnB2019660 for ; Wed, 13 Aug 2014 13:55:49 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7DDtnNr019658 for svn-soc-all@FreeBSD.org; Wed, 13 Aug 2014 13:55:49 GMT (envelope-from dpl@FreeBSD.org) Date: Wed, 13 Aug 2014 13:55:49 GMT Message-Id: <201408131355.s7DDtnNr019658@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272363 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Aug 2014 13:55:49 -0000 Author: dpl Date: Wed Aug 13 13:55:48 2014 New Revision: 272363 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272363 Log: Comment Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Wed Aug 13 12:58:15 2014 (r272362) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Wed Aug 13 13:55:48 2014 (r272363) @@ -35,7 +35,7 @@ #include /* XXX for in_cksum */ -// The real function will be inserted by the JIT. +// The real function will be compiled and inserted by the JIT. int ipfw_chk_jit(struct ip_fw_args *args, struct ip_fw_chain *chain); // Declarations of some needed structs. From owner-svn-soc-all@FreeBSD.ORG Wed Aug 13 13:57:03 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A5DC5EA8 for ; Wed, 13 Aug 2014 13:57:03 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8578A2A6B for ; Wed, 13 Aug 2014 13:57:03 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7DDv3Ov020132 for ; Wed, 13 Aug 2014 13:57:03 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7DDv3bB020129 for svn-soc-all@FreeBSD.org; Wed, 13 Aug 2014 13:57:03 GMT (envelope-from dpl@FreeBSD.org) Date: Wed, 13 Aug 2014 13:57:03 GMT Message-Id: <201408131357.s7DDv3bB020129@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272364 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Aug 2014 13:57:03 -0000 Author: dpl Date: Wed Aug 13 13:57:02 2014 New Revision: 272364 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272364 Log: Finished allocating and initializing variables. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Wed Aug 13 13:55:48 2014 (r272363) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Wed Aug 13 13:57:02 2014 (r272364) @@ -18,6 +18,7 @@ extern "C" { #include #include +#include #include #include @@ -55,8 +56,12 @@ BasicBlock *entry; BasicBlock *pullup_failed; BasicBlock *startrules; + BasicBlock *check_tag; // JIT Compiled Vars + // These are the function arguments. + Value *argsptr; + Value *chainptr; // Loop control. Value *match; Value *l; @@ -169,6 +174,17 @@ void setEnv(struct ip_fw_args *args, struct ip_fw_chain *chain) { + // Get function arguments. + // (struct ip_fw_args *, struct ip_fw_chain *) + auto& arglist = func->getArgumentList(); + + // Error + if (arglist.size() != 2) + err(1, "Compilation error: no correct parameters\n"); + + argsptr = &arglist.front(); + chainptr = &arglist.back(); + // Get Type objects int8Ty = Type::getInt8Ty(con); int16Ty = Type::getInt16Ty(con); @@ -206,8 +222,35 @@ #ifdef __FreeBSD__ ucredPtrTy = PointerType::get(ucredTy, 0); #endif + // Get Function defs from bitcode. + // All of them are auxiliary functions. + inspect_pkt = mod->getFunction("inspect_pkt"); + is_icmp_query = mod->getFunction("is_icmp_query"); + flags_match = mod->getFunction("flags_match"); + ipopts_match = mod->getFunction("ipopts_match"); + tcpopts_match = mod->getFunction("tcpopts_match"); + iface_match = mod->getFunction("iface_match"); + verify_path = mod->getFunction("verify_path"); - // Allocate vars. +#ifdef INET6 + icmp6type_match = mod->getFunction("icmp6type_match"); + search_ip6_addr_net = mod->getFunction("search_ip6_addr_net"); + flow6id_match = mod->getFunction("flow6id_match"); + verify_path6 = mod->getFunction("verify_path6"); + is_icmp6_query = mod->getFunction("is_icmp6_query"); + send_reject6 = mod->getFunction("send_reject6"); +#endif /* INET6 */ + + send_reject = mod->getFunction("send_reject"); + check_uidgid = mod->getFunction("check_uidgid"); + set_match = mod->getFunction("set_match"); + jump_fast = mod->getFunction("jump_fast"); + } + + // Allocate and initialize vars. + void + allocaAndInit(struct ip_fw_args *args, struct ip_fw_chain *chain) + { match = irb.CreateAlloca(int32Ty); l = irb.CreateAlloca(int32Ty); done = irb.CreateAlloca(int32Ty); @@ -217,11 +260,13 @@ retval = irb.CreateAlloca(int32Ty); irb.CreateStore(ConstantInt::get(int32Ty, 0), retval); - m = irb.CreateAlloca(mbufPtrTy); // Init: args->m - // XXX m = args->m + // m = args->m (idx: 0) + m = irb.CreateAlloca(mbufPtrTy); + irb.CreateStore(irb.CreateInBoundsGEP(argsptr, ConstantInt::get(int32Ty, 0)), m); + // ip = (struct ip *)((m)->m_data) (idx: 2) ip = irb.CreateAlloca(ipPtrTy); - // XXX ip = (struct ip *)((m)->m_data); + irb.CreateStore(irb.CreateBitCast(irb.CreateInBoundsGEP(argsptr, ConstantInt::get(int32Ty, 2)), ipPtrTy), ip); #ifdef __FreeBSD__ ucred = irb.CreateAlloca(ucredPtrTy); // Init: NULL if type ucred. @@ -244,26 +289,33 @@ ip6f_mf = irb.CreateAlloca(int16Ty); irb.CreateStore(ConstantInt::get(int16Ty, 0), ip6f_mf); + // proto = args->f_id.proto = 0 + // proto = 0; proto = irb.CreateAlloca(int8Ty); irb.CreateStore(ConstantInt::get(int8Ty, 0), proto); - // XXX proto = args->f_id.proto = 0 + // args->f_id.proto = 0 (idx: 6, 5) + irb.CreateStore(ConstantInt::get(int8Ty, 0), irb.CreateInBoundsGEP(argsptr, {ConstantInt::get(int32Ty, 6), ConstantInt::get(int32Ty, 5)} )); src_port = irb.CreateAlloca(int16Ty); irb.CreateStore(ConstantInt::get(int16Ty, 0), src_port); dst_port = irb.CreateAlloca(int16Ty); irb.CreateStore(ConstantInt::get(int16Ty, 0), dst_port); + //src_ip.s_addr = 0; src_ip = irb.CreateAlloca(in_addrTy); - dst_ip = irb.CreateAlloca(in_addrTy); - // XXX + irb.CreateStore(ConstantInt::get(int32Ty, 0), irb.CreateInBoundsGEP(src_ip, ConstantInt::get(int32Ty, 0))); //dst_ip.s_addr = 0; - //src_ip.s_addr = 0; + dst_ip = irb.CreateAlloca(in_addrTy); + irb.CreateStore(ConstantInt::get(int32Ty, 0), irb.CreateInBoundsGEP(dst_ip, ConstantInt::get(int32Ty, 0))); iplen = irb.CreateAlloca(int16Ty); irb.CreateStore(ConstantInt::get(int16Ty, 0), iplen); + // pktlen = m->m_pkthdr.len; + // m_pkthdr is the 6th element (idx: 5) + // len is the 2nd element (idx: 1) pktlen = irb.CreateAlloca(int32Ty); - //XXX pktlen = m->m_pkthdr.len; + irb.CreateStore(ConstantInt::get(int32Ty, 0), irb.CreateInBoundsGEP(m, {ConstantInt::get(int32Ty, 5), ConstantInt::get(int32Ty, 1)} )); etype = irb.CreateAlloca(int16Ty); irb.CreateStore(ConstantInt::get(int32Ty, 0), etype); @@ -286,30 +338,6 @@ irb.CreateStore(ConstantInt::get(int8Ty, 0), icmp6_type); ext_hd = irb.CreateAlloca(int16Ty); irb.CreateStore(ConstantInt::get(int16Ty, 0), ext_hd); - - // Get Function defs from bitcode. - // All of them are auxiliary functions. - inspect_pkt = mod->getFunction("inspect_pkt"); - is_icmp_query = mod->getFunction("is_icmp_query"); - flags_match = mod->getFunction("flags_match"); - ipopts_match = mod->getFunction("ipopts_match"); - tcpopts_match = mod->getFunction("tcpopts_match"); - iface_match = mod->getFunction("iface_match"); - verify_path = mod->getFunction("verify_path"); - -#ifdef INET6 - icmp6type_match = mod->getFunction("icmp6type_match"); - search_ip6_addr_net = mod->getFunction("search_ip6_addr_net"); - flow6id_match = mod->getFunction("flow6id_match"); - verify_path6 = mod->getFunction("verify_path6"); - is_icmp6_query = mod->getFunction("is_icmp6_query"); - send_reject6 = mod->getFunction("send_reject6"); -#endif /* INET6 */ - - send_reject = mod->getFunction("send_reject"); - check_uidgid = mod->getFunction("check_uidgid"); - set_match = mod->getFunction("set_match"); - jump_fast = mod->getFunction("jump_fast"); } void @@ -354,19 +382,18 @@ printfFunc = mod->getFunction("printf"); - // Create first BasicBlocks. + // Create statics BasicBlocks. entry = BasicBlock::Create(con, "entry", func); pullup_failed = BasicBlock::Create(con, "pullup_failed", func); + check_tag = BasicBlock::Create(con, "check_tag", func); startrules = BasicBlock::Create(con, "startrules", func); - // Create the code related to the pullup_failed Basic Block. emit_pullup_failed(); - - // Set the IRBuilder to insert instructions after the entry BB. - irb.SetInsertPoint(entry); + emit_check_tag(); // Get struct types, and store vars - setEnv(args, chain); + setEnv(); + allocaAndInit(args, chain); } ~ipfwJIT() { @@ -393,7 +420,7 @@ { // If it returns one, goto pullup_failed. // Else, goto starrules. - irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateCall(inspect_pkt), ConstantInt::get(int32Ty, 1)), pullup_failed, startrules); + irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateCall(inspect_pkt, {argsptr, ip, m, src_ip, dst_ip, src_port, dst_port, etype, ext_hd, iplen, pktlen, is_ipv4, is_ipv6, hlen, proto, icmp6_type, ip6f_mf, offset, ulp}), ConstantInt::get(int32Ty, 1)), pullup_failed, startrules); return (0); } From owner-svn-soc-all@FreeBSD.ORG Wed Aug 13 16:52:53 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B78B3EE2 for ; Wed, 13 Aug 2014 16:52:53 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9874820DB for ; Wed, 13 Aug 2014 16:52:53 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7DGqr8J006969 for ; Wed, 13 Aug 2014 16:52:53 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7DGqqL7006748 for svn-soc-all@FreeBSD.org; Wed, 13 Aug 2014 16:52:52 GMT (envelope-from dpl@FreeBSD.org) Date: Wed, 13 Aug 2014 16:52:52 GMT Message-Id: <201408131652.s7DGqqL7006748@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272369 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Aug 2014 16:52:53 -0000 Author: dpl Date: Wed Aug 13 16:52:52 2014 New Revision: 272369 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272369 Log: Added emit_check_tag() function, which compiles stuff done before iterating the rules. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Wed Aug 13 15:50:16 2014 (r272368) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Wed Aug 13 16:52:52 2014 (r272369) @@ -59,6 +59,7 @@ // Functions used by JIT, external. int printf(const char * restrict format, ...); +int ipfw_find_rule(struct ip_fw_chain *chain, uint32_t key, uint32_t id); static VNET_DEFINE(int, fw_deny_unknown_exthdrs); #define V_fw_deny_unknown_exthdrs VNET(fw_deny_unknown_exthdrs) Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Wed Aug 13 15:50:16 2014 (r272368) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Wed Aug 13 16:52:52 2014 (r272369) @@ -102,6 +102,7 @@ Function *inspect_pkt; // Auxiliary functions used by our JITed code. + // All this are used from our bitcode. Function *is_icmp_query; Function *flags_match; Function *ipopts_match; @@ -123,6 +124,7 @@ // Not pkg-filtering related funcs. Function *printfFunc; + Function *ipfw_find_rule; // Used structs. StructType *ifnetTy; @@ -172,7 +174,7 @@ // Create the needed variables to perform pkt filtering. void - setEnv(struct ip_fw_args *args, struct ip_fw_chain *chain) + setEnv() { // Get function arguments. // (struct ip_fw_args *, struct ip_fw_chain *) @@ -245,6 +247,10 @@ check_uidgid = mod->getFunction("check_uidgid"); set_match = mod->getFunction("set_match"); jump_fast = mod->getFunction("jump_fast"); + + // Functions declared at bitcode. + printfFunc = mod->getFunction("printf"); + ipfw_find_rule = mod->getFunction("ipfw_find_rule"); } // Allocate and initialize vars. @@ -371,6 +377,55 @@ irb.CreateRet(ConstantInt::get(int32Ty, IP_FW_DENY)); } + void + emit_check_tag() + { + BasicBlock *tagged, *nottagged; + BasicBlock *yes, *no; + + // if (args->rule.slot) { + // /* + // * Packet has already been tagged as a result of a previous + // * match on rule args->rule aka args->rule_id (PIPE, QUEUE, + // * REASS, NETGRAPH, DIVERT/TEE...) + // * Validate the slot and continue from the next one + // * if still present, otherwise do a lookup. + // */ + // f_pos = (args->rule.chain_id == chain->id) ? + // args->rule.slot : + // ipfw_find_rule(chain, args->rule.rulenum, + // args->rule.rule_id); + // } else { + // f_pos = 0; + // } + + irb.SetInsertPoint(check_tag); + + // if (args->rule.slot) + irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateInBoundsGEP(argsptr, {ConstantInt::get(int32Ty, 4),ConstantInt::get(int32Ty, 0)}), ConstantInt::get(int32Ty, 0)), nottagged, tagged); + // if (args->rule.chain_id == chain->id) + irb.SetInsertPoint(tagged); + irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateInBoundsGEP(argsptr, {ConstantInt::get(int32Ty, 4), ConstantInt::get(int32Ty, 3)}), irb.CreateInBoundsGEP(chainptr, ConstantInt::get(int32Ty, 12))), yes, no); + + // f_pos = args->rule.slot; + irb.SetInsertPoint(yes); + irb.CreateStore(irb.CreateInBoundsGEP(argsptr, {ConstantInt::get(int32Ty, 4),ConstantInt::get(int32Ty, 0)}), f_pos); + irb.CreateBr(nottagged); + + // else fpos = ipfw_find_rule(chain, args->rule.rulenum, args->rule.rule_id) + irb.SetInsertPoint(no); + irb.CreateStore(irb.CreateCall3(ipfw_find_rule, chainptr, irb.CreateInBoundsGEP(argsptr, {ConstantInt::get(int32Ty, 4), ConstantInt::get(int32Ty, 1)}), irb.CreateInBoundsGEP(argsptr, {ConstantInt::get(int32Ty, 4), ConstantInt::get(int32Ty, 2)})), f_pos); + + // Branch to nottagged because it + // only finishes the check_tag BasicBlock. + irb.CreateBr(nottagged); + + // else f_pos = 0; + // Since f_pos is initialized by default as 0, we only br. + irb.SetInsertPoint(nottagged); + irb.CreateBr(startrules); + } + public: ipfwJIT(struct ip_fw_args *args, struct ip_fw_chain *chain): irb(con) { @@ -380,8 +435,6 @@ func = mod->getFunction("ipfw_chk_jit"); func->setLinkage(GlobalValue::ExternalLinkage); - printfFunc = mod->getFunction("printf"); - // Create statics BasicBlocks. entry = BasicBlock::Create(con, "entry", func); pullup_failed = BasicBlock::Create(con, "pullup_failed", func); From owner-svn-soc-all@FreeBSD.ORG Wed Aug 13 19:31:51 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 99908D9F for ; Wed, 13 Aug 2014 19:31:51 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6DECD24A0 for ; Wed, 13 Aug 2014 19:31:51 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7DJVpeP043170 for ; Wed, 13 Aug 2014 19:31:51 GMT (envelope-from pedrosouza@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7DJVkvr041792 for svn-soc-all@FreeBSD.org; Wed, 13 Aug 2014 19:31:46 GMT (envelope-from pedrosouza@FreeBSD.org) Date: Wed, 13 Aug 2014 19:31:46 GMT Message-Id: <201408131931.s7DJVkvr041792@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to pedrosouza@FreeBSD.org using -f From: pedrosouza@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272374 - in soc2014/pedrosouza/lua_loader/head: share/mk sys/boot sys/boot/amd64/efi sys/boot/arm/uboot sys/boot/i386/loader sys/boot/ia64/efi sys/boot/ia64/ski sys/boot/lua sys/boo... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Aug 2014 19:31:51 -0000 Author: pedrosouza Date: Wed Aug 13 19:31:46 2014 New Revision: 272374 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272374 Log: Updated makefiles with .lua scripts & fix undefined reference Modified: soc2014/pedrosouza/lua_loader/head/share/mk/src.opts.mk soc2014/pedrosouza/lua_loader/head/sys/boot/Makefile soc2014/pedrosouza/lua_loader/head/sys/boot/amd64/efi/Makefile soc2014/pedrosouza/lua_loader/head/sys/boot/arm/uboot/Makefile soc2014/pedrosouza/lua_loader/head/sys/boot/i386/loader/Makefile soc2014/pedrosouza/lua_loader/head/sys/boot/ia64/efi/Makefile soc2014/pedrosouza/lua_loader/head/sys/boot/ia64/ski/Makefile soc2014/pedrosouza/lua_loader/head/sys/boot/lua/menu.lua soc2014/pedrosouza/lua_loader/head/sys/boot/mips/beri/loader/Makefile soc2014/pedrosouza/lua_loader/head/sys/boot/pc98/loader/Makefile soc2014/pedrosouza/lua_loader/head/sys/boot/powerpc/ofw/Makefile soc2014/pedrosouza/lua_loader/head/sys/boot/powerpc/ps3/Makefile soc2014/pedrosouza/lua_loader/head/sys/boot/powerpc/uboot/Makefile soc2014/pedrosouza/lua_loader/head/sys/boot/sparc64/loader/Makefile soc2014/pedrosouza/lua_loader/head/sys/lua/src/ldo.c soc2014/pedrosouza/lua_loader/head/sys/lua/src/lstd.h Modified: soc2014/pedrosouza/lua_loader/head/share/mk/src.opts.mk ============================================================================== --- soc2014/pedrosouza/lua_loader/head/share/mk/src.opts.mk Wed Aug 13 16:53:12 2014 (r272373) +++ soc2014/pedrosouza/lua_loader/head/share/mk/src.opts.mk Wed Aug 13 19:31:46 2014 (r272374) @@ -78,7 +78,6 @@ FDT \ FLOPPY \ FMTREE \ - FORTH \ FP_LIBC \ FREEBSD_UPDATE \ GAMES \ @@ -109,6 +108,7 @@ LOCATE \ LPR \ LS_COLORS \ + LUA \ LZMA_SUPPORT \ MAIL \ MAILWRAPPER \ @@ -160,6 +160,7 @@ CLANG_EXTRAS \ EISA \ FMAKE \ + FORTH \ HESIOD \ LLDB \ NAND \ Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/Makefile ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/Makefile Wed Aug 13 16:53:12 2014 (r272373) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/Makefile Wed Aug 13 19:31:46 2014 (r272374) @@ -8,7 +8,9 @@ SUBDIR+= ficl .endif +.if ${MK_LUA} != "no" SUBDIR+= lua +.endif # Pick the machine-dependent subdir based on the target architecture. ADIR= ${MACHINE:S/powerpc64/powerpc/} Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/amd64/efi/Makefile ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/amd64/efi/Makefile Wed Aug 13 16:53:12 2014 (r272373) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/amd64/efi/Makefile Wed Aug 13 19:31:46 2014 (r272374) @@ -42,8 +42,10 @@ .endif #Lua -CFLAGS+= -DBOOT_LUA -I${.CURDIR}../../../lua/src +.if ${MK_LUA} != "no" +CFLAGS+= -DBOOT_LUA -I${.CURDIR}/../../../lua/src LIBLUA= ${.OBJDIR}/../../lua/liblua.a +.endif # Include bcache code. HAVE_BCACHE= yes @@ -90,8 +92,8 @@ LIBEFI= ${.OBJDIR}/../../efi/libefi/libefi.a CFLAGS+= -I${.CURDIR}/../../common -DPADD= ${LIBFICL} ${LIBEFI} ${LIBSTAND} ${LIBLUA} -LDADD= ${LIBFICL} ${LIBEFI} ${LIBSTAND} ${LIBLUA} +DPADD= ${LIBFICL} ${LIBLUA} ${LIBEFI} ${LIBSTAND} +LDADD= ${LIBFICL} ${LIBLUA} ${LIBEFI} ${LIBSTAND} .endif # ${COMPILER_TYPE} != "gcc" Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/arm/uboot/Makefile ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/arm/uboot/Makefile Wed Aug 13 16:53:12 2014 (r272373) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/arm/uboot/Makefile Wed Aug 13 19:31:46 2014 (r272374) @@ -83,8 +83,10 @@ .endif #Lua -CFLAGS+= -DBOOT_LUA -I${.CURDIR}../../../lua/src +.if ${MK_LUA} != "no" +CFLAGS+= -DBOOT_LUA -I${.CURDIR}/../../../lua/src LIBLUA= ${.OBJDIR}/../../lua/liblua.a +.endif # Always add MI sources .PATH: ${.CURDIR}/../../common @@ -116,8 +118,8 @@ # clang doesn't understand %D as a specifier to printf NO_WERROR.clang= -DPADD= ${LIBFICL} ${LIBUBOOT} ${LIBFDT} ${LIBSTAND} ${LIBLUA} -LDADD= ${LIBFICL} ${LIBUBOOT} ${LIBFDT} ${LIBLUA} -lstand +DPADD= ${LIBFICL} ${LIBLUA} ${LIBUBOOT} ${LIBFDT} ${LIBSTAND} +LDADD= ${LIBFICL} ${LIBLUA} ${LIBUBOOT} ${LIBFDT} -lstand vers.c: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT} @@ -139,12 +141,15 @@ fi .if !defined(LOADER_ONLY) + +FILESDIR_loader.conf= /boot/defaults + +.if ${MK_FORTH} != "no" .PATH: ${.CURDIR}/../../forth FILES+= loader.help loader.4th support.4th loader.conf -FILES+= screen.4th frames.4th beastie.4th -FILES+= brand.4th check-password.4th color.4th delay.4th -FILES+= menu.4th menu-commands.4th menusets.4th shortcuts.4th version.4th -FILESDIR_loader.conf= /boot/defaults +FILES+= screen.4th frames.4th beastie.4th +FILES+= brand.4th check-password.4th color.4th delay.4th +FILES+= menu.4th menu-commands.4th menusets.4th shortcuts.4th version.4th # Put sample loader.rc and menu.rc on disk but don't enable them # by default. @@ -154,4 +159,17 @@ FILESNAME_menu.rc= menu.rc.sample .endif +.if ${MK_LUA} != "no" +.PATH: ${.CURDIR}/../../lua +FILES+= config.lua core.lua drawer.lua +FILES+= menu.lua password.lua screen.lua + +.if !exists(${DESTDIR}/boot/loader.lua) +FILES+= loader.lua +.endif +.endif + + +.endif + .include Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/i386/loader/Makefile ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/i386/loader/Makefile Wed Aug 13 16:53:12 2014 (r272373) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/i386/loader/Makefile Wed Aug 13 19:31:46 2014 (r272374) @@ -51,8 +51,10 @@ .endif #Lua -CFLAGS+= -DBOOT_LUA -I${.CURDIR}../../../lua/src +.if ${MK_LUA} != "no" +CFLAGS+= -DBOOT_LUA -I${.CURDIR}/../../../lua/src LIBLUA= ${.OBJDIR}/../../lua/liblua.a +.endif .if defined(LOADER_BZIP2_SUPPORT) CFLAGS+= -DLOADER_BZIP2_SUPPORT @@ -111,12 +113,15 @@ FILESMODE_${LOADER}= ${BINMODE} -b .if !defined(LOADER_ONLY) + +FILESDIR_loader.conf= /boot/defaults + +.if ${MK_FORTH} != "no" .PATH: ${.CURDIR}/../../forth FILES+= loader.help loader.4th support.4th loader.conf FILES+= screen.4th frames.4th beastie.4th FILES+= brand.4th check-password.4th color.4th delay.4th FILES+= menu.4th menu-commands.4th menusets.4th shortcuts.4th version.4th -FILESDIR_loader.conf= /boot/defaults .if !exists(${DESTDIR}/boot/loader.rc) FILES+= loader.rc @@ -126,11 +131,24 @@ .endif .endif +.if ${MK_LUA} != "no" +.PATH: ${.CURDIR}/../../lua +FILES+= config.lua core.lua drawer.lua +FILES+= menu.lua password.lua screen.lua + +.if !exists(${DESTDIR}/boot/loader.lua) +FILES+= loader.lua +.endif +.endif + + +.endif + # XXX crt0.o needs to be first for pxeboot(8) to work OBJS= ${BTXCRT} -DPADD= ${LIBFICL} ${LIBFIREWIRE} ${LIBZFSBOOT} ${LIBI386} ${LIBSTAND} ${LIBLUA} -LDADD= ${LIBFICL} ${LIBFIREWIRE} ${LIBZFSBOOT} ${LIBI386} ${LIBSTAND} ${LIBLUA} +DPADD= ${LIBFICL} ${LIBLUA} ${LIBFIREWIRE} ${LIBZFSBOOT} ${LIBI386} ${LIBSTAND} +LDADD= ${LIBFICL} ${LIBLUA} ${LIBFIREWIRE} ${LIBZFSBOOT} ${LIBI386} ${LIBSTAND} .include Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/ia64/efi/Makefile ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/ia64/efi/Makefile Wed Aug 13 16:53:12 2014 (r272373) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/ia64/efi/Makefile Wed Aug 13 19:31:46 2014 (r272374) @@ -52,8 +52,14 @@ LIBFICL= ${.OBJDIR}/../../ficl/libficl.a .endif -DPADD= ${LIBIA64} ${LIBFICL} ${LIBEFI} ${LIBSTAND} +#Lua +.if ${MK_LUA} != "no" +CFLAGS+= -DBOOT_LUA -I${.CURDIR}/../../../lua/src +LIBLUA= ${.OBJDIR}/../../lua/liblua.a +.endif + +DPADD= ${LIBIA64} ${LIBFICL} ${LIBLUA} ${LIBEFI} ${LIBSTAND} LDADD= -Wl,--whole-archive ${LIBIA64} -Wl,--no-whole-archive \ - ${LIBFICL} ${LIBEFI} -lstand + ${LIBFICL} ${LIBLUA} ${LIBEFI} -lstand .include Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/ia64/ski/Makefile ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/ia64/ski/Makefile Wed Aug 13 16:53:12 2014 (r272373) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/ia64/ski/Makefile Wed Aug 13 19:31:46 2014 (r272374) @@ -33,11 +33,13 @@ .endif #Lua -CFLAGS+= -DBOOT_LUA -I${.CURDIR}../../../lua/src +.if ${MK_LUA} != "no" +CFLAGS+= -DBOOT_LUA -I${.CURDIR}/../../../lua/src LIBLUA= ${.OBJDIR}/../../lua/liblua.a +.endif -DPADD= ${LIBIA64} ${LIBFICL} ${LIBSTAND} ${LIBLUA} +DPADD= ${LIBIA64} ${LIBFICL} ${LIBLUA} ${LIBSTAND} LDADD= -Wl,--whole-archive ${LIBIA64} -Wl,--no-whole-archive \ - ${LIBFICL} -lstand ${LIBLUA} + ${LIBFICL} ${LIBLUA} -lstand .include Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/menu.lua ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/menu.lua Wed Aug 13 16:53:12 2014 (r272373) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/menu.lua Wed Aug 13 19:31:46 2014 (r272374) @@ -107,7 +107,8 @@ time = endtime - loader.time(); screen.setcursor(x, y); - print("Autoboot in "..time.." seconds, hit [Enter] to boot or any other key to stop "); + print("Autoboot in "..time.." seconds, hit [Enter] to boot" + .." or any other key to stop "); screen.defcursor(); if io.ischar() then local ch = io.getchar(); @@ -118,7 +119,8 @@ loader.perform("set autoboot_delay=NO"); -- erase autoboot msg screen.setcursor(0, y); - print(" "); + print(" " + .." "); screen.defcursor(); return; end @@ -177,7 +179,11 @@ if not v then return; end - kernels[tostring(i)] = {index = i, name = "Return to menu "..color.highlight("[Backspace]"), func = function() return true; end}; + kernels[tostring(i)] = { + index = i, + name = "Return to menu "..color.highlight("[Backspace]"), + func = function() return true; end + }; kernels.alias = {["\08"] = kernels[tostring(i)]}; i = i + 1; @@ -258,5 +264,5 @@ ["a"] = boot_options["3"], ["m"] = boot_options["4"], ["s"] = boot_options["5"], - ["v"] = boot_options["6"] + ["v"] = boot_options["6"] }; \ No newline at end of file Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/mips/beri/loader/Makefile ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/mips/beri/loader/Makefile Wed Aug 13 16:53:12 2014 (r272373) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/mips/beri/loader/Makefile Wed Aug 13 19:31:46 2014 (r272374) @@ -78,8 +78,10 @@ .endif #Lua -CFLAGS+= -DBOOT_LUA -I${.CURDIR}../../../lua/src -LIBLUA= ${.OBJDIR}/../../lua/liblua.a +.if ${MK_LUA} != "no" +CFLAGS+= -DBOOT_LUA -I${.CURDIR}/../../../../lua/src +LIBLUA= ${.OBJDIR}/../../../lua/liblua.a +.endif # Common code across BERI boot loader parts .PATH: ${.CURDIR}/../common @@ -116,8 +118,8 @@ CFLAGS+= -I${.CURDIR}/../../../../../lib/libstand/ LIBSTAND= ${.OBJDIR}/../../../../../lib/libstand/libstand.a -DPADD= ${LIBFICL} ${LIBSTAND} ${LIBLUA} -LDADD= ${LIBFICL} ${LIBSTAND} ${LIBLUA} +DPADD= ${LIBFICL} ${LIBLUA} ${LIBSTAND} +LDADD= ${LIBFICL} ${LIBLUA} ${LIBSTAND} vers.c: ${.CURDIR}/../../../common/newvers.sh ${.CURDIR}/version sh ${.CURDIR}/../../../common/newvers.sh ${.CURDIR}/version \ @@ -127,20 +129,34 @@ cat ${.ALLSRC} | \ awk -f ${.CURDIR}/../../../common/merge_help.awk > ${.TARGET} -.PATH: ${.CURDIR}/../../../forth -FILES= loader.help loader.4th support.4th loader.conf -FILES+= screen.4th frames.4th -FILES+= beastie.4th brand.4th check-password.4th color.4th delay.4th -FILES+= menu.4th menu-commands.4th menusets.4th shortcuts.4th version.4th + FILESDIR_loader.conf= /boot/defaults +.if ${MK_FORTH} != "no" +.PATH: ${.CURDIR}/../../../forth +FILES+= loader.help loader.4th support.4th loader.conf +FILES+= screen.4th frames.4th beastie.4th +FILES+= brand.4th check-password.4th color.4th delay.4th +FILES+= menu.4th menu-commands.4th menusets.4th shortcuts.4th version.4th + .if !exists(${DESTDIR}/boot/loader.rc) -FILES+= loader.rc +FILES+= loader.rc .endif - .if !exists(${DESTDIR}/boot/menu.rc) FILES+= menu.rc .endif +.endif + +.if ${MK_LUA} != "no" +.PATH: ${.CURDIR}/../../../lua +FILES+= config.lua core.lua drawer.lua +FILES+= menu.lua password.lua screen.lua + +.if !exists(${DESTDIR}/boot/loader.lua) +FILES+= loader.lua +.endif +.endif + .if defined(LOADER_USB_SUPPORT) # Do garbage collection Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/pc98/loader/Makefile ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/pc98/loader/Makefile Wed Aug 13 16:53:12 2014 (r272373) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/pc98/loader/Makefile Wed Aug 13 19:31:46 2014 (r272374) @@ -36,8 +36,10 @@ .endif #Lua -CFLAGS+= -DBOOT_LUA -I${.CURDIR}../../../lua/src +.if ${MK_LUA} != "no" +CFLAGS+= -DBOOT_LUA -I${.CURDIR}/../../../lua/src LIBLUA= ${.OBJDIR}/../../lua/liblua.a +.endif .if defined(LOADER_BZIP2_SUPPORT) CFLAGS+= -DLOADER_BZIP2_SUPPORT @@ -90,12 +92,14 @@ # XXX INSTALLFLAGS_loader= -b FILESMODE_${LOADER}= ${BINMODE} -b +FILESDIR_loader.conf= /boot/defaults + +.if ${MK_FORTH} != "no" .PATH: ${.CURDIR}/../../forth FILES+= loader.help loader.4th support.4th loader.conf FILES+= screen.4th frames.4th beastie.4th FILES+= brand.4th check-password.4th color.4th delay.4th FILES+= menu.4th menu-commands.4th menusets.4th shortcuts.4th version.4th -FILESDIR_loader.conf= /boot/defaults .if !exists(${DESTDIR}/boot/loader.rc) FILES+= ${.CURDIR}/../../i386/loader/loader.rc @@ -103,11 +107,22 @@ .if !exists(${DESTDIR}/boot/menu.rc) FILES+= menu.rc .endif +.endif + +.if ${MK_LUA} != "no" +.PATH: ${.CURDIR}/../../lua +FILES+= config.lua core.lua drawer.lua +FILES+= menu.lua password.lua screen.lua + +.if !exists(${DESTDIR}/boot/loader.lua) +FILES+= loader.lua +.endif +.endif # XXX crt0.o needs to be first for pxeboot(8) to work OBJS= ${BTXCRT} -DPADD= ${LIBFICL} ${LIBPC98} ${LIBSTAND} ${LIBLUA} -LDADD= ${LIBFICL} ${LIBPC98} ${LIBSTAND} ${LIBLUA} +DPADD= ${LIBFICL} ${LIBLUA} ${LIBPC98} ${LIBSTAND} +LDADD= ${LIBFICL} ${LIBLUA} ${LIBPC98} ${LIBSTAND} .include Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/powerpc/ofw/Makefile ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/powerpc/ofw/Makefile Wed Aug 13 16:53:12 2014 (r272373) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/powerpc/ofw/Makefile Wed Aug 13 19:31:46 2014 (r272374) @@ -58,8 +58,10 @@ .endif #Lua -CFLAGS+= -DBOOT_LUA -I${.CURDIR}../../../lua/src +.if ${MK_LUA} != "no" +CFLAGS+= -DBOOT_LUA -I${.CURDIR}/../../../lua/src LIBLUA= ${.OBJDIR}/../../lua/liblua.a +.endif # Avoid the open-close-dance for every file access as some firmwares perform # an auto-negotiation on every open of the network interface and thus causes @@ -96,8 +98,8 @@ LIBSTAND= ${.OBJDIR}/../../libstand32/libstand.a CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/ -DPADD= ${LIBFICL} ${LIBOFW} ${LIBSTAND} ${LIBLUA} -LDADD= ${LIBFICL} ${LIBOFW} ${LIBSTAND} ${LIBLUA} +DPADD= ${LIBFICL} ${LIBLUA} ${LIBOFW} ${LIBSTAND} +LDADD= ${LIBFICL} ${LIBLUA} ${LIBOFW} ${LIBSTAND} vers.c: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT} @@ -106,19 +108,31 @@ cat ${.ALLSRC} | \ awk -f ${.CURDIR}/../../common/merge_help.awk > ${.TARGET} -.PATH: ${.CURDIR}/../../forth -FILES= loader.help loader.4th support.4th loader.conf -FILES+= screen.4th frames.4th -FILES+= beastie.4th brand.4th check-password.4th color.4th delay.4th -FILES+= menu.4th menu-commands.4th menusets.4th shortcuts.4th version.4th FILESDIR_loader.conf= /boot/defaults +.if ${MK_FORTH} != "no" +.PATH: ${.CURDIR}/../../forth +FILES+= loader.help loader.4th support.4th loader.conf +FILES+= screen.4th frames.4th beastie.4th +FILES+= brand.4th check-password.4th color.4th delay.4th +FILES+= menu.4th menu-commands.4th menusets.4th shortcuts.4th version.4th + .if !exists(${DESTDIR}/boot/loader.rc) -FILES+= loader.rc +FILES+= loader.rc .endif - .if !exists(${DESTDIR}/boot/menu.rc) FILES+= menu.rc .endif +.endif + +.if ${MK_LUA} != "no" +.PATH: ${.CURDIR}/../../lua +FILES+= config.lua core.lua drawer.lua +FILES+= menu.lua password.lua screen.lua + +.if !exists(${DESTDIR}/boot/loader.lua) +FILES+= loader.lua +.endif +.endif .include Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/powerpc/ps3/Makefile ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/powerpc/ps3/Makefile Wed Aug 13 16:53:12 2014 (r272373) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/powerpc/ps3/Makefile Wed Aug 13 19:31:46 2014 (r272374) @@ -68,8 +68,10 @@ .endif #Lua -CFLAGS+= -DBOOT_LUA -I${.CURDIR}../../../lua/src +.if ${MK_LUA} != "no" +CFLAGS+= -DBOOT_LUA -I${.CURDIR}/../../../lua/src LIBLUA= ${.OBJDIR}/../../lua/liblua.a +.endif # Avoid the open-close-dance for every file access as some firmwares perform # an auto-negotiation on every open of the network interface and thus causes @@ -102,8 +104,8 @@ LIBSTAND= ${.OBJDIR}/../../libstand32/libstand.a CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/ -DPADD= ${LIBFICL} ${LIBOFW} ${LIBSTAND} ${LIBLUA} -LDADD= ${LIBFICL} ${LIBOFW} ${LIBSTAND} ${LIBLUA} +DPADD= ${LIBFICL} ${LIBLUA} ${LIBOFW} ${LIBSTAND} +LDADD= ${LIBFICL} ${LIBLUA} ${LIBOFW} ${LIBSTAND} SC_DFLT_FONT=cp437 @@ -117,19 +119,31 @@ cat ${.ALLSRC} | \ awk -f ${.CURDIR}/../../common/merge_help.awk > ${.TARGET} -.PATH: ${.CURDIR}/../../forth -FILES= loader.help loader.4th support.4th loader.conf -FILES+= screen.4th frames.4th -FILES+= beastie.4th brand.4th check-password.4th color.4th delay.4th -FILES+= menu.4th menu-commands.4th menusets.4th shortcuts.4th version.4th FILESDIR_loader.conf= /boot/defaults +.if ${MK_FORTH} != "no" +.PATH: ${.CURDIR}/../../forth +FILES+= loader.help loader.4th support.4th loader.conf +FILES+= screen.4th frames.4th beastie.4th +FILES+= brand.4th check-password.4th color.4th delay.4th +FILES+= menu.4th menu-commands.4th menusets.4th shortcuts.4th version.4th + .if !exists(${DESTDIR}/boot/loader.rc) -FILES+= loader.rc +FILES+= loader.rc .endif - .if !exists(${DESTDIR}/boot/menu.rc) FILES+= menu.rc .endif +.endif + +.if ${MK_LUA} != "no" +.PATH: ${.CURDIR}/../../lua +FILES+= config.lua core.lua drawer.lua +FILES+= menu.lua password.lua screen.lua + +.if !exists(${DESTDIR}/boot/loader.lua) +FILES+= loader.lua +.endif +.endif .include Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/powerpc/uboot/Makefile ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/powerpc/uboot/Makefile Wed Aug 13 16:53:12 2014 (r272373) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/powerpc/uboot/Makefile Wed Aug 13 19:31:46 2014 (r272374) @@ -73,8 +73,10 @@ .endif #Lua -CFLAGS+= -DBOOT_LUA -I${.CURDIR}../../../lua/src +.if ${MK_LUA} != "no" +CFLAGS+= -DBOOT_LUA -I${.CURDIR}/../../../lua/src LIBLUA= ${.OBJDIR}/../../lua/liblua.a +.endif # Always add MI sources .PATH: ${.CURDIR}/../../common ${.CURDIR}/../../../libkern @@ -102,8 +104,8 @@ LIBSTAND= ${.OBJDIR}/../../libstand32/libstand.a CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/ -DPADD= ${LIBFICL} ${LIBUBOOT} ${LIBFDT} ${LIBSTAND} ${LIBLUA} -LDADD= ${LIBFICL} ${LIBUBOOT} ${LIBFDT} ${LIBSTAND} ${LIBLUA} +DPADD= ${LIBFICL} ${LIBLUA} ${LIBUBOOT} ${LIBFDT} ${LIBSTAND} +LDADD= ${LIBFICL} ${LIBLUA} ${LIBUBOOT} ${LIBFDT} ${LIBSTAND} vers.c: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT} @@ -115,4 +117,14 @@ .PATH: ${.CURDIR}/../../forth FILES= loader.help +.if ${MK_LUA} != "no" +.PATH: ${.CURDIR}/../../lua +FILES+= config.lua core.lua drawer.lua +FILES+= menu.lua password.lua screen.lua + +.if !exists(${DESTDIR}/boot/loader.lua) +FILES+= loader.lua +.endif +.endif + .include Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/sparc64/loader/Makefile ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/sparc64/loader/Makefile Wed Aug 13 16:53:12 2014 (r272373) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/sparc64/loader/Makefile Wed Aug 13 19:31:46 2014 (r272374) @@ -66,8 +66,10 @@ .endif #Lua -CFLAGS+= -DBOOT_LUA -I${.CURDIR}../../../lua/src +.if ${MK_LUA} != "no" +CFLAGS+= -DBOOT_LUA -I${.CURDIR}/../../../lua/src LIBLUA= ${.OBJDIR}/../../lua/liblua.a +.endif # Always add MI sources .PATH: ${.CURDIR}/../../common @@ -90,8 +92,8 @@ # where to get libstand from CFLAGS+= -I${.CURDIR}/../../../../lib/libstand/ -DPADD= ${LIBFICL} ${LIBZFSBOOT} ${LIBOFW} ${LIBSTAND} ${LIBLUA} -LDADD= ${LIBFICL} ${LIBZFSBOOT} ${LIBOFW} -lstand ${LIBLUA} +DPADD= ${LIBFICL} ${LIBLUA} ${LIBZFSBOOT} ${LIBOFW} ${LIBSTAND} +LDADD= ${LIBFICL} ${LIBLUA} ${LIBZFSBOOT} ${LIBOFW} -lstand vers.c: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/../loader/version sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/../loader/version \ @@ -101,19 +103,31 @@ cat ${.ALLSRC} | \ awk -f ${.CURDIR}/../../common/merge_help.awk > ${.TARGET} -.PATH: ${.CURDIR}/../../forth -FILES= loader.help loader.4th support.4th loader.conf -FILES+= screen.4th frames.4th -FILES+= beastie.4th brand.4th check-password.4th color.4th delay.4th -FILES+= menu.4th menu-commands.4th menusets.4th shortcuts.4th version.4th FILESDIR_loader.conf= /boot/defaults +.if ${MK_FORTH} != "no" +.PATH: ${.CURDIR}/../../forth +FILES+= loader.help loader.4th support.4th loader.conf +FILES+= screen.4th frames.4th beastie.4th +FILES+= brand.4th check-password.4th color.4th delay.4th +FILES+= menu.4th menu-commands.4th menusets.4th shortcuts.4th version.4th + .if !exists(${DESTDIR}/boot/loader.rc) -FILES+= loader.rc +FILES+= loader.rc .endif - .if !exists(${DESTDIR}/boot/menu.rc) FILES+= menu.rc .endif +.endif + +.if ${MK_LUA} != "no" +.PATH: ${.CURDIR}/../../lua +FILES+= config.lua core.lua drawer.lua +FILES+= menu.lua password.lua screen.lua + +.if !exists(${DESTDIR}/boot/loader.lua) +FILES+= loader.lua +.endif +.endif .include Modified: soc2014/pedrosouza/lua_loader/head/sys/lua/src/ldo.c ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/lua/src/ldo.c Wed Aug 13 16:53:12 2014 (r272373) +++ soc2014/pedrosouza/lua_loader/head/sys/lua/src/ldo.c Wed Aug 13 19:31:46 2014 (r272374) @@ -7,10 +7,10 @@ #ifdef BOOT_LUA #include #else -#include #include #include #endif +#include #define ldo_c #define LUA_CORE Modified: soc2014/pedrosouza/lua_loader/head/sys/lua/src/lstd.h ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/lua/src/lstd.h Wed Aug 13 16:53:12 2014 (r272373) +++ soc2014/pedrosouza/lua_loader/head/sys/lua/src/lstd.h Wed Aug 13 19:31:46 2014 (r272374) @@ -39,7 +39,6 @@ #include #include -#include typedef __ptrdiff_t ptrdiff_t; From owner-svn-soc-all@FreeBSD.ORG Wed Aug 13 21:38:11 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E3FB689F for ; Wed, 13 Aug 2014 21:38:11 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D0CE6228B for ; Wed, 13 Aug 2014 21:38:11 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7DLcBhs018291 for ; Wed, 13 Aug 2014 21:38:11 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7DLcBX7018289 for svn-soc-all@FreeBSD.org; Wed, 13 Aug 2014 21:38:11 GMT (envelope-from dpl@FreeBSD.org) Date: Wed, 13 Aug 2014 21:38:11 GMT Message-Id: <201408132138.s7DLcBX7018289@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272378 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Aug 2014 21:38:12 -0000 Author: dpl Date: Wed Aug 13 21:38:10 2014 New Revision: 272378 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272378 Log: Warning Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c Wed Aug 13 19:55:14 2014 (r272377) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw2.c Wed Aug 13 21:38:10 2014 (r272378) @@ -320,6 +320,7 @@ * these types of constraints, as well as decrease contention * on pcb related locks. */ + // XXX Warning, take a look at crfree(); #ifndef __FreeBSD__ struct bsd_ucred ucred_cache; #else From owner-svn-soc-all@FreeBSD.ORG Thu Aug 14 04:13:27 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8554853E for ; Thu, 14 Aug 2014 04:13:27 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 701DC2B1F for ; Thu, 14 Aug 2014 04:13:27 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7E4DRRT010631 for ; Thu, 14 Aug 2014 04:13:27 GMT (envelope-from astarasikov@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7E4DQeY010627 for svn-soc-all@FreeBSD.org; Thu, 14 Aug 2014 04:13:26 GMT (envelope-from astarasikov@FreeBSD.org) Date: Thu, 14 Aug 2014 04:13:26 GMT Message-Id: <201408140413.s7E4DQeY010627@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to astarasikov@FreeBSD.org using -f From: astarasikov@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272382 - soc2014/astarasikov/head/sys/dev/ofw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 04:13:27 -0000 Author: astarasikov Date: Thu Aug 14 04:13:25 2014 New Revision: 272382 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272382 Log: [ofw]: workaround strlcat corruption on goldfish After enabling the MMC driver, I have experienced that the argument to strlcat always pointed to invalid memory. To allow me to debug the driver, I have implemented an ugly hack Modified: soc2014/astarasikov/head/sys/dev/ofw/ofw_bus_subr.c Modified: soc2014/astarasikov/head/sys/dev/ofw/ofw_bus_subr.c ============================================================================== --- soc2014/astarasikov/head/sys/dev/ofw/ofw_bus_subr.c Wed Aug 13 22:34:14 2014 (r272381) +++ soc2014/astarasikov/head/sys/dev/ofw/ofw_bus_subr.c Thu Aug 14 04:13:25 2014 (r272382) @@ -82,6 +82,7 @@ ofw_bus_gen_child_pnpinfo_str(device_t cbdev, device_t child, char *buf, size_t buflen) { + printf("%s: buflen=%x\n", __func__, buflen); if (ofw_bus_get_name(child) != NULL) { strlcat(buf, "name=", buflen); @@ -90,6 +91,10 @@ if (ofw_bus_get_compat(child) != NULL) { strlcat(buf, " compat=", buflen); + if (ofw_bus_get_compat(child) < (char*)0xc0000000) { + printf("%s: bad compat ptr %p\n", __func__, ofw_bus_get_compat(child)); + return (0); + } strlcat(buf, ofw_bus_get_compat(child), buflen); } return (0); From owner-svn-soc-all@FreeBSD.ORG Thu Aug 14 04:18:39 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id F145A5AB for ; Thu, 14 Aug 2014 04:18:39 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id DD5E62B3D for ; Thu, 14 Aug 2014 04:18:39 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7E4Idde012728 for ; Thu, 14 Aug 2014 04:18:39 GMT (envelope-from astarasikov@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7E4IcrW012719 for svn-soc-all@FreeBSD.org; Thu, 14 Aug 2014 04:18:38 GMT (envelope-from astarasikov@FreeBSD.org) Date: Thu, 14 Aug 2014 04:18:38 GMT Message-Id: <201408140418.s7E4IcrW012719@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to astarasikov@FreeBSD.org using -f From: astarasikov@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272383 - in soc2014/astarasikov/head/sys: arm/conf arm/goldfish boot/fdt/dts/arm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 04:18:40 -0000 Author: astarasikov Date: Thu Aug 14 04:18:38 2014 New Revision: 272383 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272383 Log: Goldfish: implement the (almost-working) MMC driver. The driver correctly writes/reads MMC command data, but seems stuck after sending CMD13. I'm currently debugging it. Modified: soc2014/astarasikov/head/sys/arm/conf/GOLDFISH soc2014/astarasikov/head/sys/arm/goldfish/files.goldfish soc2014/astarasikov/head/sys/arm/goldfish/goldfish_nand.c soc2014/astarasikov/head/sys/boot/fdt/dts/arm/goldfish.dts Modified: soc2014/astarasikov/head/sys/arm/conf/GOLDFISH ============================================================================== --- soc2014/astarasikov/head/sys/arm/conf/GOLDFISH Thu Aug 14 04:13:25 2014 (r272382) +++ soc2014/astarasikov/head/sys/arm/conf/GOLDFISH Thu Aug 14 04:18:38 2014 (r272383) @@ -41,6 +41,7 @@ makeoptions DEBUG=-g #Build kernel with gdb(1) debug symbols options HZ=100 +options SCSI_DELAY=5000 # Delay (in ms) before probing SCSI options SCHED_4BSD #4BSD scheduler options INET #InterNETworking options TMPFS # Efficient memory filesystem @@ -68,7 +69,8 @@ device snp # NAND for rootfs -# device nand +device nand +options NANDFS # NAND file system # Ethernet device ether @@ -83,10 +85,10 @@ # NOTE: serial console is disabled if syscons enabled # Comment following lines for headless setup -device sc -device kbdmux -options SC_DFLT_FONT # compile font in -makeoptions SC_DFLT_FONT=cp437 +#device sc +#device kbdmux +#options SC_DFLT_FONT # compile font in +#makeoptions SC_DFLT_FONT=cp437 options STACK makeoptions WITH_CTF=1 @@ -110,15 +112,19 @@ device md device random # Entropy device +device mmc +device mmcsd +options ROOTDEVNAME=\"ufs:/dev/mmcsd0s1a\" + # Flattened Device Tree options FDT options FDT_DTB_STATIC makeoptions FDT_DTS_FILE=goldfish.dts -options MD_ROOT -options MD_ROOT_SIZE=5120 -makeoptions MFS_IMAGE=/root/handhelds/myroot.img -options ROOTDEVNAME=\"/dev/md0\" +#options MD_ROOT +#options MD_ROOT_SIZE=5120 +#makeoptions MFS_IMAGE=/root/handhelds/myroot.img +#options ROOTDEVNAME=\"/dev/md0\" #boot from NFS #options NFSCL Modified: soc2014/astarasikov/head/sys/arm/goldfish/files.goldfish ============================================================================== --- soc2014/astarasikov/head/sys/arm/goldfish/files.goldfish Thu Aug 14 04:13:25 2014 (r272382) +++ soc2014/astarasikov/head/sys/arm/goldfish/files.goldfish Thu Aug 14 04:18:38 2014 (r272383) @@ -10,7 +10,8 @@ arm/goldfish/goldfish_fb.c optional sc arm/goldfish/goldfish_machdep.c standard -arm/goldfish/goldfish_mmc.c standard +arm/goldfish/goldfish_mmc.c optional mmc +#arm/goldfish/goldfish_nand.c optional nand arm/goldfish/goldfish_pic.c standard arm/goldfish/goldfish_pdev.c standard arm/goldfish/goldfish_timer.c standard Modified: soc2014/astarasikov/head/sys/arm/goldfish/goldfish_nand.c ============================================================================== --- soc2014/astarasikov/head/sys/arm/goldfish/goldfish_nand.c Thu Aug 14 04:13:25 2014 (r272382) +++ soc2014/astarasikov/head/sys/arm/goldfish/goldfish_nand.c Thu Aug 14 04:18:38 2014 (r272383) @@ -84,6 +84,9 @@ GOLGDFISH_NAND_VERSION_CURRENT = 0x1, }; +struct goldfish_nand_state { +}; + struct goldfish_nand_softc { struct nand_softc nand_dev; bus_space_handle_t sc_handle; @@ -99,25 +102,28 @@ static int goldfish_nand_attach(device_t); static int goldfish_nand_probe(device_t); -static int goldfish_nand_send_command(device_t, uint8_t); + +static int goldfish_nand_read_rnb(device_t); +static int goldfish_nand_select_cs(device_t, uint8_t); static int goldfish_nand_send_address(device_t, uint8_t); +static int goldfish_nand_send_command(device_t, uint8_t); +static int goldfish_nand_start_command(device_t dev); static uint8_t goldfish_nand_read_byte(device_t); static void goldfish_nand_read_buf(device_t, void *, uint32_t); static void goldfish_nand_write_buf(device_t, void *, uint32_t); -static int goldfish_nand_select_cs(device_t, uint8_t); -static int goldfish_nand_read_rnb(device_t); static device_method_t goldfish_nand_methods[] = { DEVMETHOD(device_probe, goldfish_nand_probe), DEVMETHOD(device_attach, goldfish_nand_attach), - DEVMETHOD(nfc_send_command, goldfish_nand_send_command), - DEVMETHOD(nfc_send_address, goldfish_nand_send_address), - DEVMETHOD(nfc_read_byte, goldfish_nand_read_byte), DEVMETHOD(nfc_read_buf, goldfish_nand_read_buf), - DEVMETHOD(nfc_write_buf, goldfish_nand_write_buf), - DEVMETHOD(nfc_select_cs, goldfish_nand_select_cs), + DEVMETHOD(nfc_read_byte, goldfish_nand_read_byte), DEVMETHOD(nfc_read_rnb, goldfish_nand_read_rnb), + DEVMETHOD(nfc_select_cs, goldfish_nand_select_cs), + DEVMETHOD(nfc_send_address, goldfish_nand_send_address), + DEVMETHOD(nfc_send_command, goldfish_nand_send_command), + DEVMETHOD(nfc_start_command, goldfish_nand_start_command), + DEVMETHOD(nfc_write_buf, goldfish_nand_write_buf), { 0, 0 }, }; @@ -129,7 +135,7 @@ }; static devclass_t goldfish_nand_devclass; -DRIVER_MODULE(goldfish_nand, localbus, goldfish_nand_driver, goldfish_nand_devclass, 0, 0); +DRIVER_MODULE(goldfish_nand, simplebus, goldfish_nand_driver, goldfish_nand_devclass, 0, 0); static uint32_t goldfish_nand_mmio_cmd(device_t dev, enum goldfish_nand_cmd cmd, @@ -158,7 +164,7 @@ static int goldfish_nand_probe(device_t dev) { - //if (!ofw_bus_is_compatible(dev, "arm,goldfish-nand")) + if (!ofw_bus_is_compatible(dev, "arm,goldfish-nand")) return (ENXIO); device_set_desc(dev, "Goldfish NAND controller"); @@ -192,36 +198,89 @@ nand_init(&sc->nand_dev, dev, NAND_ECC_SOFT, 0, 0, NULL, NULL); err = nandbus_create(dev); + printf("%s: nandbus_create=%d\n", __func__, err); return (err); } +static int goldfish_nand_start_command(device_t dev) +{ + printf("%s\n", __func__); + return (0); +} + static int goldfish_nand_send_command(device_t dev, uint8_t command) { + printf("%s: command=%x\n", __func__, command); + + switch (command) { + case NAND_CMD_READ: + fcm->code = CMD_READ_PAGE; + fcm->addr_type = ADDR_ROWCOL; + break; + case NAND_CMD_PROG: + fcm->code = CMD_PROG_PAGE; + fcm->addr_type = ADDR_ROWCOL; + break; + case NAND_CMD_PROG_END: + break; + case NAND_CMD_ERASE_END: + break; + case NAND_CMD_RESET: + fcm->code = CMD_RESET; + break; + case NAND_CMD_READ_ID: + fcm->code = CMD_READ_ID; + fcm->addr_type = ADDR_ID; + break; + case NAND_CMD_READ_PARAMETER: + fcm->code = CMD_READ_PAGE; + fcm->addr_type = ADDR_ID; + break; + case NAND_CMD_STATUS: + fcm->code = CMD_READ_STATUS; + break; + case NAND_CMD_ERASE: + fcm->code = CMD_ERASE; + fcm->addr_type = ADDR_ROW; + break; + case NAND_CMD_READ_END: + case NAND_CMD_PROG_END: + case NAND_CMD_ERASE_END: + break; + default: + printf("%s: unknown command %d\n", command); + return (1); + } + return (0); } static int goldfish_nand_send_address(device_t dev, uint8_t addr) { + printf("%s: addr=%x\n", __func__, addr); return (0); } static uint8_t goldfish_nand_read_byte(device_t dev) { + printf("%s\n", __func__); return (0); } static void goldfish_nand_read_buf(device_t dev, void* buf, uint32_t len) { + printf("%s: buf=%p, len=%x\n", __func__, buf, len); } static void goldfish_nand_write_buf(device_t dev, void* buf, uint32_t len) { + printf("%s: buf=%p, len=%x\n", __func__, buf, len); } static int Modified: soc2014/astarasikov/head/sys/boot/fdt/dts/arm/goldfish.dts ============================================================================== --- soc2014/astarasikov/head/sys/boot/fdt/dts/arm/goldfish.dts Thu Aug 14 04:13:25 2014 (r272382) +++ soc2014/astarasikov/head/sys/boot/fdt/dts/arm/goldfish.dts Thu Aug 14 04:18:38 2014 (r272383) @@ -25,12 +25,14 @@ #interrupt-cells = <1>; }; + /* pdev { - compatible = "arm,goldfish-xpdev"; + compatible = "arm,goldfish-pdev"; reg = <0xff001000 0x1000>; interrupts = <1>; interrupt-parent = <&pic>; }; + */ uart0: uart0 { compatible = "arm,goldfish-uart"; @@ -48,19 +50,34 @@ interrupts = <3>; interrupt-parent = <&pic>; }; - - audio { - compatible = "arm,goldfish-xaudio"; - reg = <0xff004000 0x1000>; + + mmc@xff005000 { + compatible = "arm,goldfish-mmc"; + reg = <0xff005000 0x1000>; interrupts = <15>; interrupt-parent = <&pic>; + non-removable; + mmchs-device-id = <1>; + max-frequency = <24000000>; }; - mmc { - compatible = "arm,goldfish-xmmc"; - reg = <0xff005000 0x1000>; - interrupts = <16>; - interrupt-parent = <&pic>; + /* + nand { + compatible = "arm,goldfish-nand"; + reg = <0xff017000 0x1000>; + interrupts = <2>; + interrupt-parent = <&pic>; + + slice@0 { + reg = <0x0 0x200000>; + label = "uboot"; + read-only; + }; + + slice@200000 { + reg = <0x200000 0x100000>; + label = "root"; + }; }; smc { @@ -78,6 +95,7 @@ interrupts = <14>; interrupt-parent = <&pic>; }; + */ }; memory { From owner-svn-soc-all@FreeBSD.ORG Thu Aug 14 09:09:08 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 00C62E37 for ; Thu, 14 Aug 2014 09:09:07 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E200F285C for ; Thu, 14 Aug 2014 09:09:07 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7E997gK074193 for ; Thu, 14 Aug 2014 09:09:07 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7E997AN074191 for svn-soc-all@FreeBSD.org; Thu, 14 Aug 2014 09:09:07 GMT (envelope-from op@FreeBSD.org) Date: Thu, 14 Aug 2014 09:09:07 GMT Message-Id: <201408140909.s7E997AN074191@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272395 - soc2014/op/freebsd-base/sys/kern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 09:09:08 -0000 Author: op Date: Thu Aug 14 09:09:07 2014 New Revision: 272395 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272395 Log: KSP: added critical_{enter,exit} to lf_selfpatch Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/smap+kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Thu Aug 14 08:42:16 2014 (r272394) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Thu Aug 14 09:09:07 2014 (r272395) @@ -134,6 +134,8 @@ count = stop - start; DBG("count: %d\n", count); + critical_enter(); + for (patch = start; patch != stop; patch++) { DBG("apply: %p\n", patch); ret = lf_selfpatch_apply(lf, patch, mod); @@ -141,6 +143,8 @@ return (ret); } + critical_exit(); + #ifdef KSP_DEBUG /* * when selfpatch does not works, the system should crash From owner-svn-soc-all@FreeBSD.ORG Thu Aug 14 11:42:26 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 08DABD22 for ; Thu, 14 Aug 2014 11:42:26 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id DE0B229CD for ; Thu, 14 Aug 2014 11:42:25 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7EBgPdE011482 for ; Thu, 14 Aug 2014 11:42:25 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7EBgOwx011453 for svn-soc-all@FreeBSD.org; Thu, 14 Aug 2014 11:42:24 GMT (envelope-from op@FreeBSD.org) Date: Thu, 14 Aug 2014 11:42:24 GMT Message-Id: <201408141142.s7EBgOwx011453@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272396 - in soc2014/op/tests/ksp-tester: . kmod MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 11:42:26 -0000 Author: op Date: Thu Aug 14 11:42:24 2014 New Revision: 272396 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272396 Log: KSP: added test kernel module Signed-off-by: Oliver Pinter Added: soc2014/op/tests/ksp-tester/ soc2014/op/tests/ksp-tester/Makefile soc2014/op/tests/ksp-tester/kmod/ soc2014/op/tests/ksp-tester/kmod/.clang_complete soc2014/op/tests/ksp-tester/kmod/Makefile soc2014/op/tests/ksp-tester/kmod/ksp-tester-kld.c Added: soc2014/op/tests/ksp-tester/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/op/tests/ksp-tester/Makefile Thu Aug 14 11:42:24 2014 (r272396) @@ -0,0 +1,3 @@ +SUBDIR= kmod + +.include Added: soc2014/op/tests/ksp-tester/kmod/.clang_complete ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/op/tests/ksp-tester/kmod/.clang_complete Thu Aug 14 11:42:24 2014 (r272396) @@ -0,0 +1,6 @@ +-D_KERNEL +-DKERNEL +-I/usr/src +-I/usr/src/sys +-I/usr/src/sys/amd64 +-I/usr/src/sys/x86 Added: soc2014/op/tests/ksp-tester/kmod/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/op/tests/ksp-tester/kmod/Makefile Thu Aug 14 11:42:24 2014 (r272396) @@ -0,0 +1,4 @@ +KMOD= ksp-tester-kld +SRCS= ksp-tester-kld.c + +.include Added: soc2014/op/tests/ksp-tester/kmod/ksp-tester-kld.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/op/tests/ksp-tester/kmod/ksp-tester-kld.c Thu Aug 14 11:42:24 2014 (r272396) @@ -0,0 +1,142 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "opt_ksp.h" + +#ifndef KSP_DEBUG +#error "KSP_DEBUG must set at kernel build time to properly use this test" +#endif + +#define DBG(...) \ + printf("%s: ", __func__); \ + printf(__VA_ARGS__); \ + +__noinline void lf_selfpatch_selftest(void); + +static int +ksp_tester_kld_loader(struct module *m __unused, int what, void *arg __unused) +{ + int error = 0; + + switch (what) { + case MOD_LOAD: + printf("KSP tester loaded.\n"); + break; + case MOD_UNLOAD: + printf("KSP tester unloaded.\n"); + break; + default: + error = EOPNOTSUPP; + break; + } + return (error); +} + +__noinline void +lf_selfpatch_selftest(void) +{ + printf("patch size == patchable size: "); + __asm __volatile( + "1:" + " ud2; ud2; ; " + "2: " + " .pushsection set_selfpatch_patch_set, \"ax\" ; " + "3: " + " .byte 0x90,0x90,0x90,0x90 ;" + "4: " + " .popsection " + " .pushsection set_selfpatch_set, \"a\" ; " + " .quad 1b ; " + " .quad 3b ; " + " .int 2b-1b ; " + " .int 4b-3b ; " + " .int " __XSTRING(KSP_SELFTEST) " ; " + " .int " __XSTRING(KSP_FEATURE_SELFTEST) " ; " + " .quad 0 ; " + " .popsection ; " + ); + DBG("works.\n"); + + + printf("patch size < patchable size: "); + __asm __volatile( + "1:" + " ud2; ud2; ; " + "2: " + " .pushsection set_selfpatch_patch_set, \"ax\" ; " + "3: " + " .byte 0x90 ;" + "4: " + " .popsection " + " .pushsection set_selfpatch_set, \"a\" ; " + " .quad 1b ; " + " .quad 3b ; " + " .int 2b-1b ; " + " .int 4b-3b ; " + " .int " __XSTRING(KSP_SELFTEST) " ; " + " .int " __XSTRING(KSP_FEATURE_SELFTEST) " ; " + " .quad 0 ; " + " .popsection ; " + ); + DBG("works.\n"); + + + printf("patch size << patchable size: "); + __asm __volatile( + "1:" + " ud2; ud2; ud2; ud2; ud2; ud2 ; " + "2: " + " .pushsection set_selfpatch_patch_set, \"ax\" ; " + "3: " + " .byte 0x90 ;" + "4: " + " .popsection " + " .pushsection set_selfpatch_set, \"a\" ; " + " .quad 1b ; " + " .quad 3b ; " + " .int 2b-1b ; " + " .int 4b-3b ; " + " .int " __XSTRING(KSP_SELFTEST) " ; " + " .int " __XSTRING(KSP_FEATURE_SELFTEST) " ; " + " .quad 0 ; " + " .popsection ; " + ); + DBG("works.\n"); + + + printf("patch size > patchable size: "); + __asm __volatile( + "1:" + " ud2; " + "2: " + " .pushsection set_selfpatch_patch_set, \"ax\" ; " + "3: " + " .byte 0x90, 0x90, 0x90, 0x90, 0x90 ;" + "4: " + " .popsection " + " .pushsection set_selfpatch_set, \"a\" ; " + " .quad 1b ; " + " .quad 3b ; " + " .int 2b-1b ; " + " .int 4b-3b ; " + " .int " __XSTRING(KSP_SELFTEST) " ; " + " .int " __XSTRING(KSP_FEATURE_SELFTEST) " ; " + " .quad 0 ; " + " .popsection ; " + ); + DBG("failed. this must panic.\n"); +} + +DEV_MODULE(ksp_tester_kld, ksp_tester_kld_loader, NULL); From owner-svn-soc-all@FreeBSD.ORG Thu Aug 14 11:45:50 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 834A1E65 for ; Thu, 14 Aug 2014 11:45:50 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6446029ED for ; Thu, 14 Aug 2014 11:45:50 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7EBjo2K013312 for ; Thu, 14 Aug 2014 11:45:50 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7EBjmKG013300 for svn-soc-all@FreeBSD.org; Thu, 14 Aug 2014 11:45:48 GMT (envelope-from op@FreeBSD.org) Date: Thu, 14 Aug 2014 11:45:48 GMT Message-Id: <201408141145.s7EBjmKG013300@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272397 - in soc2014/op/freebsd-base/sys: kern sys x86/include x86/x86 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 11:45:50 -0000 Author: op Date: Thu Aug 14 11:45:48 2014 New Revision: 272397 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272397 Log: KSP: added variable sized patch support Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/smap+kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c soc2014/op/freebsd-base/sys/sys/selfpatch.h soc2014/op/freebsd-base/sys/x86/include/selfpatch-asmacros.h soc2014/op/freebsd-base/sys/x86/include/selfpatch-machdep.h soc2014/op/freebsd-base/sys/x86/x86/selfpatch_machdep.c Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Thu Aug 14 11:42:24 2014 (r272396) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Thu Aug 14 11:45:48 2014 (r272397) @@ -73,6 +73,7 @@ static void lf_close_kernel_text(struct lf_selfpatch *p); static void lf_open_module_text(struct lf_selfpatch *p); static void lf_close_module_text(struct lf_selfpatch *p); +static void lf_pad_with_nop(struct lf_selfpatch *p); bool lf_selfpatch_patch_needed(struct lf_selfpatch *p) @@ -194,13 +195,13 @@ * replace the instructions */ memcpy(p->patchable, p->patch, p->patchable_size); + lf_pad_with_nop(p); if (mod == KSP_MODULE) lf_close_module_text(p); else lf_close_kernel_text(p); - DBG("patched.\n"); return (0); @@ -302,6 +303,33 @@ DBG("caches flushed.\n"); } + +static void +lf_pad_with_nop(struct lf_selfpatch *p) +{ + int i, rem; + char *patchable; + + if (p->patch_size == p->patchable_size) + return; + + if (p->patch_size > p->patchable_size) + panic("%s: patch_size > patchable_size", __func__); + + rem = p->patchable_size - p->patch_size; + patchable = p->patchable + p->patch_size; + + for (i = rem / KSP_MAX_NOPLEN; i > 0; i -= KSP_MAX_NOPLEN) { + memcpy(patchable, + selfpatch_nop_table[KSP_MAX_NOPLEN], + KSP_MAX_NOPLEN); + patchable += KSP_MAX_NOPLEN; + } + + rem %= KSP_MAX_NOPLEN; + memcpy(patchable, selfpatch_nop_table[rem], rem); +} + #ifdef KSP_DEBUG __noinline void lf_selfpatch_selftest(void) Modified: soc2014/op/freebsd-base/sys/sys/selfpatch.h ============================================================================== --- soc2014/op/freebsd-base/sys/sys/selfpatch.h Thu Aug 14 11:42:24 2014 (r272396) +++ soc2014/op/freebsd-base/sys/sys/selfpatch.h Thu Aug 14 11:45:48 2014 (r272397) @@ -60,7 +60,7 @@ char *comment; } lf_selfpatch_t; -extern char *selfpatch_nop_table[]; +extern const char *selfpatch_nop_table[]; int lf_selfpatch(linker_file_t lf, int mod); int lf_selfpatch_apply(linker_file_t lf, struct lf_selfpatch *patch, int mod); Modified: soc2014/op/freebsd-base/sys/x86/include/selfpatch-asmacros.h ============================================================================== --- soc2014/op/freebsd-base/sys/x86/include/selfpatch-asmacros.h Thu Aug 14 11:42:24 2014 (r272396) +++ soc2014/op/freebsd-base/sys/x86/include/selfpatch-asmacros.h Thu Aug 14 11:45:48 2014 (r272397) @@ -86,6 +86,7 @@ #define KSP_INSTR_NOP8_C KSP_INSTR_INTEL_NOP8_C #define KSP_INSTR_NOP9_C KSP_INSTR_INTEL_NOP9_C +#define KSP_MAX_NOPLEN 9 #define KSP_INSTR_XSAVE_XSAVEOPT(_ARG) \ 0723: \ Modified: soc2014/op/freebsd-base/sys/x86/include/selfpatch-machdep.h ============================================================================== --- soc2014/op/freebsd-base/sys/x86/include/selfpatch-machdep.h Thu Aug 14 11:42:24 2014 (r272396) +++ soc2014/op/freebsd-base/sys/x86/include/selfpatch-machdep.h Thu Aug 14 11:45:48 2014 (r272397) @@ -31,8 +31,6 @@ struct lf_selfpatch; -extern char *md_selfpatch_nop_table[]; - bool lf_selfpatch_patch_needed(struct lf_selfpatch *p); #endif /* __X86_SELFPATH_MACHDEP_H__ */ Modified: soc2014/op/freebsd-base/sys/x86/x86/selfpatch_machdep.c ============================================================================== --- soc2014/op/freebsd-base/sys/x86/x86/selfpatch_machdep.c Thu Aug 14 11:42:24 2014 (r272396) +++ soc2014/op/freebsd-base/sys/x86/x86/selfpatch_machdep.c Thu Aug 14 11:45:48 2014 (r272397) @@ -53,3 +53,51 @@ KSP_SELECTOR_END }; +/* + * assembly NOP store + */ +extern const char nop1; +extern const char nop2; +extern const char nop3; +extern const char nop4; +extern const char nop5; +extern const char nop6; +extern const char nop7; +extern const char nop8; +extern const char nop9; + +const char *selfpatch_nop_table[] = { + [0] = (const char *)NULL, + [1] = (const char *)&nop1, + [2] = (const char *)&nop2, + [3] = (const char *)&nop3, + [4] = (const char *)&nop4, + [5] = (const char *)&nop5, + [6] = (const char *)&nop6, + [7] = (const char *)&nop7, + [8] = (const char *)&nop8, + [9] = (const char *)&nop9 +}; + +__asm( +"nop1: \n" +" " KSP_INSTR_NOP1_C " \n" +"nop2: \n" +" " KSP_INSTR_NOP2_C " \n" +"nop3: \n" +" " KSP_INSTR_NOP3_C " \n" +"nop4: \n" +" " KSP_INSTR_NOP4_C " \n" +"nop5: \n" +" " KSP_INSTR_NOP5_C " \n" +"nop6: \n" +" " KSP_INSTR_NOP6_C " \n" +"nop7: \n" +" " KSP_INSTR_NOP7_C " \n" +"nop8: \n" +" " KSP_INSTR_NOP8_C " \n" +"nop9: \n" +" " KSP_INSTR_NOP9_C " \n" +" .p2align 4,0x90 \n" +); + From owner-svn-soc-all@FreeBSD.ORG Thu Aug 14 11:46:01 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 039B2E86 for ; Thu, 14 Aug 2014 11:46:01 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E513D29F2 for ; Thu, 14 Aug 2014 11:46:00 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7EBk0wp013406 for ; Thu, 14 Aug 2014 11:46:00 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7EBk08x013401 for svn-soc-all@FreeBSD.org; Thu, 14 Aug 2014 11:46:00 GMT (envelope-from op@FreeBSD.org) Date: Thu, 14 Aug 2014 11:46:00 GMT Message-Id: <201408141146.s7EBk08x013401@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272398 - soc2014/op/freebsd-base/sys/kern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 11:46:01 -0000 Author: op Date: Thu Aug 14 11:46:00 2014 New Revision: 272398 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272398 Log: KSP: enable variable sized patches Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/smap+kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Thu Aug 14 11:45:48 2014 (r272397) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Thu Aug 14 11:46:00 2014 (r272398) @@ -178,8 +178,8 @@ return (0); } - if (p->patch_size != p->patchable_size) - panic("%s: patch_size != patchable_size", __func__); + if (p->patch_size > p->patchable_size) + panic("%s: patch_size > patchable_size", __func__); /* * open the kernel text From owner-svn-soc-all@FreeBSD.ORG Thu Aug 14 11:46:09 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 205B6E9A for ; Thu, 14 Aug 2014 11:46:09 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0D91429F4 for ; Thu, 14 Aug 2014 11:46:09 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7EBk8WV013453 for ; Thu, 14 Aug 2014 11:46:08 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7EBk8XY013441 for svn-soc-all@FreeBSD.org; Thu, 14 Aug 2014 11:46:08 GMT (envelope-from op@FreeBSD.org) Date: Thu, 14 Aug 2014 11:46:08 GMT Message-Id: <201408141146.s7EBk8XY013441@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272399 - soc2014/op/freebsd-base/sys/kern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 11:46:09 -0000 Author: op Date: Thu Aug 14 11:46:08 2014 New Revision: 272399 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272399 Log: KSP: added more debug output Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/smap+kpatch Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Thu Aug 14 11:46:00 2014 (r272398) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Thu Aug 14 11:46:08 2014 (r272399) @@ -319,6 +319,9 @@ rem = p->patchable_size - p->patch_size; patchable = p->patchable + p->patch_size; + DBG("rem: %d\n", rem); + DBG("nop9: %d\n", rem / KSP_MAX_NOPLEN); + for (i = rem / KSP_MAX_NOPLEN; i > 0; i -= KSP_MAX_NOPLEN) { memcpy(patchable, selfpatch_nop_table[KSP_MAX_NOPLEN], @@ -327,6 +330,7 @@ } rem %= KSP_MAX_NOPLEN; + DBG("rem: %d -> nop%d\n", rem, rem); memcpy(patchable, selfpatch_nop_table[rem], rem); } From owner-svn-soc-all@FreeBSD.ORG Thu Aug 14 16:23:58 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7ABC02D2 for ; Thu, 14 Aug 2014 16:23:58 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5B94F2CDA for ; Thu, 14 Aug 2014 16:23:58 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7EGNwlV024763 for ; Thu, 14 Aug 2014 16:23:58 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7EGNvHZ024761 for svn-soc-all@FreeBSD.org; Thu, 14 Aug 2014 16:23:57 GMT (envelope-from dpl@FreeBSD.org) Date: Thu, 14 Aug 2014 16:23:57 GMT Message-Id: <201408141623.s7EGNvHZ024761@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272412 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 16:23:58 -0000 Author: dpl Date: Thu Aug 14 16:23:57 2014 New Revision: 272412 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272412 Log: Added basic code to start emitting parts of the control flow. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Thu Aug 14 15:46:15 2014 (r272411) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/jit.cc Thu Aug 14 16:23:57 2014 (r272412) @@ -56,7 +56,9 @@ BasicBlock *entry; BasicBlock *pullup_failed; BasicBlock *startrules; - BasicBlock *check_tag; + BasicBlock *end; + // This BB is the next emitted rule, always. + BasicBlock *next; // JIT Compiled Vars // These are the function arguments. @@ -361,7 +363,6 @@ // printf("ipfw: pullup failed\n"); // return (IP_FW_DENY); - irb.SetInsertPoint(pullup_failed); is_verbose = mod->getGlobalVariable("fw_verbose"); str = irb.CreateGlobalString("ipfw: pullup failed\n"); @@ -399,8 +400,6 @@ // f_pos = 0; // } - irb.SetInsertPoint(check_tag); - // if (args->rule.slot) irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateInBoundsGEP(argsptr, {ConstantInt::get(int32Ty, 4),ConstantInt::get(int32Ty, 0)}), ConstantInt::get(int32Ty, 0)), nottagged, tagged); // if (args->rule.chain_id == chain->id) @@ -417,7 +416,7 @@ irb.CreateStore(irb.CreateCall3(ipfw_find_rule, chainptr, irb.CreateInBoundsGEP(argsptr, {ConstantInt::get(int32Ty, 4), ConstantInt::get(int32Ty, 1)}), irb.CreateInBoundsGEP(argsptr, {ConstantInt::get(int32Ty, 4), ConstantInt::get(int32Ty, 2)})), f_pos); // Branch to nottagged because it - // only finishes the check_tag BasicBlock. + // only finishes the entry BasicBlock. irb.CreateBr(nottagged); // else f_pos = 0; @@ -436,17 +435,26 @@ func->setLinkage(GlobalValue::ExternalLinkage); // Create statics BasicBlocks. + // The entry basic block contains all the initialization + // and allocation of resources, and a basic check done + // before start emmiting the rules code. entry = BasicBlock::Create(con, "entry", func); + // This is equivalent to the pullup_failed tag. pullup_failed = BasicBlock::Create(con, "pullup_failed", func); - check_tag = BasicBlock::Create(con, "check_tag", func); + // This will be the first BasicBlock to store our emmited code. startrules = BasicBlock::Create(con, "startrules", func); - - emit_pullup_failed(); - emit_check_tag(); + // This will be executed at the end of ipfw_chk_jit(). + end = BasicBlock::Create(con, "end", func); // Get struct types, and store vars + irb.SetInsertPoint(entry); setEnv(); allocaAndInit(args, chain); + + emit_check_tag(); + + irb.SetInsertPoint(pullup_failed); + emit_pullup_failed(); } ~ipfwJIT() { @@ -468,13 +476,61 @@ } // Call the function that fills in some vars. - int + void emit_lookpkt() { // If it returns one, goto pullup_failed. // Else, goto starrules. irb.CreateCondBr(irb.CreateICmpEQ(irb.CreateCall(inspect_pkt, {argsptr, ip, m, src_ip, dst_ip, src_port, dst_port, etype, ext_hd, iplen, pktlen, is_ipv4, is_ipv6, hlen, proto, icmp6_type, ip6f_mf, offset, ulp}), ConstantInt::get(int32Ty, 1)), pullup_failed, startrules); - return (0); + return; + } + + // We get here ar the end of switch() on opcodes. + // XXX + void + emit_end_switch() + { + // /* if we get here with l=0, then match is irrelevant. */ + // if (cmd->len & F_NOT) + // match = !match; + + // if (match) { + // if (cmd->len & F_OR) + // skip_or = 1; + // } else { + // if (!(cmd->len & F_OR)) /* not an OR block, */ + // break; /* try next rule */ + // } + } + + // This code gets executed at the end of inner loop. + // In this context, break means goto end, else continue loop. + void + emit_end_opcodes() + { + // if (done) + // break; + irb.CreateCondBr(irb.CreateCmpNE(done, ConstantInt::get(int32Ty, 0)), end, next); + } + + // This will emit some code executed at the end. + // And set up basic blocks, if necessary. + // XXX + void + emit_end() + { + // if (done) { + // struct ip_fw *rule = chain->map[f_pos]; + // /* Update statistics */ + // (rule)->pcnt++; + // (rule)->bcnt += pktlen; + // (rule)->timestamp = time_uptime; + // } else { + // retval = IP_FW_DENY; + // printf("ipfw: ouch!, skip past end of rules, denying packet\n"); + // } + + irb.SetInsertPoint(end); } // Rules @@ -523,6 +579,7 @@ int pktlen = args->m->m_pkthdr.len; // For all the number of rules. + // It seems that we can create a control flow based on this. for (; f_pos < chain->n_rules; f_pos++) { ipfw_insn *cmd; int l, cmdlen, skip_or; /* skip rest of OR block */ @@ -916,9 +973,13 @@ default: panic("-- unknown opcode %d\n", cmd->opcode); } /* end of switch() on opcodes */ + comp.emit_end_switch(); } /* end of inner loop, scan opcodes */ + comp.emit_end_opcodes(); } /* end of outer for, scan rules */ + comp.emit_end(); + // Once we're done iterating through the rules, return the pointer. comp.optimize(); return (comp.getFuncPtr()); From owner-svn-soc-all@FreeBSD.ORG Thu Aug 14 17:55:57 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 211C125C for ; Thu, 14 Aug 2014 17:55:57 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0DD6727E3 for ; Thu, 14 Aug 2014 17:55:57 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7EHtuf7030121 for ; Thu, 14 Aug 2014 17:55:56 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7EHtu4q030119 for svn-soc-all@FreeBSD.org; Thu, 14 Aug 2014 17:55:56 GMT (envelope-from op@FreeBSD.org) Date: Thu, 14 Aug 2014 17:55:56 GMT Message-Id: <201408141755.s7EHtu4q030119@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272422 - soc2014/op/tests/ksp-tester/kmod MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 17:55:57 -0000 Author: op Date: Thu Aug 14 17:55:56 2014 New Revision: 272422 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272422 Log: fixed build in svn version too Signed-off-by: Oliver Pinter Modified: soc2014/op/tests/ksp-tester/kmod/ksp-tester-kld.c Modified: soc2014/op/tests/ksp-tester/kmod/ksp-tester-kld.c ============================================================================== --- soc2014/op/tests/ksp-tester/kmod/ksp-tester-kld.c Thu Aug 14 16:45:02 2014 (r272421) +++ soc2014/op/tests/ksp-tester/kmod/ksp-tester-kld.c Thu Aug 14 17:55:56 2014 (r272422) @@ -13,7 +13,7 @@ #include #include -#include "opt_ksp.h" +#include "opt_selfpatch.h" #ifndef KSP_DEBUG #error "KSP_DEBUG must set at kernel build time to properly use this test" From owner-svn-soc-all@FreeBSD.ORG Thu Aug 14 19:21:59 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 705BCB21 for ; Thu, 14 Aug 2014 19:21:59 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5D5A52403 for ; Thu, 14 Aug 2014 19:21:59 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7EJLxrd016312 for ; Thu, 14 Aug 2014 19:21:59 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7EJLw7E016300 for svn-soc-all@FreeBSD.org; Thu, 14 Aug 2014 19:21:58 GMT (envelope-from op@FreeBSD.org) Date: Thu, 14 Aug 2014 19:21:58 GMT Message-Id: <201408141921.s7EJLw7E016300@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272434 - soc2014/op/tools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 19:21:59 -0000 Author: op Date: Thu Aug 14 19:21:58 2014 New Revision: 272434 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272434 Log: tests: added xsave and osxsave emulation Signed-off-by: Oliver Pinter Modified: soc2014/op/tools/run_smap_test_vm_64bit_with_smap.csh Modified: soc2014/op/tools/run_smap_test_vm_64bit_with_smap.csh ============================================================================== --- soc2014/op/tools/run_smap_test_vm_64bit_with_smap.csh Thu Aug 14 18:57:46 2014 (r272433) +++ soc2014/op/tools/run_smap_test_vm_64bit_with_smap.csh Thu Aug 14 19:21:58 2014 (r272434) @@ -14,7 +14,7 @@ set QEMU="${QEMU_PREFIX}/bin/qemu" set QEMU_BIN="${QEMU_PREFIX}/bin/qemu-system-${QTARGET}" -set QEMU_OPTIONS="-cpu ${QCPU},enforce,+smap,+smep,-hypervisor -m 1024M -smp 4" +set QEMU_OPTIONS="-cpu ${QCPU},enforce,+smap,+smep,+xsave,+osxsave,-hypervisor -m 1024M -smp 4" set FREEBSD_VMIMAGE="freebsd-${TARGET}.raw" From owner-svn-soc-all@FreeBSD.ORG Thu Aug 14 19:49:06 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B0E743DC for ; Thu, 14 Aug 2014 19:49:06 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9DBEB2719 for ; Thu, 14 Aug 2014 19:49:06 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7EJn6JZ065179 for ; Thu, 14 Aug 2014 19:49:06 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7EJn69f065162 for svn-soc-all@FreeBSD.org; Thu, 14 Aug 2014 19:49:06 GMT (envelope-from op@FreeBSD.org) Date: Thu, 14 Aug 2014 19:49:06 GMT Message-Id: <201408141949.s7EJn69f065162@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272435 - soc2014/op/freebsd-base/sys/kern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 19:49:06 -0000 Author: op Date: Thu Aug 14 19:49:05 2014 New Revision: 272435 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272435 Log: KSP: disable debug log by default Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/master Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Modified: soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Thu Aug 14 19:21:58 2014 (r272434) +++ soc2014/op/freebsd-base/sys/kern/kern_selfpatch.c Thu Aug 14 19:49:05 2014 (r272435) @@ -61,7 +61,7 @@ extern struct lf_selfpatch __start_set_selfpatch_set[]; extern struct lf_selfpatch __stop_set_selfpatch_set[]; -static int selfpatch_debug=1; +static int selfpatch_debug = 0; SYSCTL_INT(_debug, OID_AUTO, selfpatch_debug, CTLFLAG_RWTUN, &selfpatch_debug, 0, "Set various levels of selfpatch debug"); From owner-svn-soc-all@FreeBSD.ORG Thu Aug 14 19:49:32 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4398F3EE for ; Thu, 14 Aug 2014 19:49:32 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2555F271B for ; Thu, 14 Aug 2014 19:49:32 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7EJnWX5065334 for ; Thu, 14 Aug 2014 19:49:32 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7EJnSY7065322 for svn-soc-all@FreeBSD.org; Thu, 14 Aug 2014 19:49:28 GMT (envelope-from op@FreeBSD.org) Date: Thu, 14 Aug 2014 19:49:28 GMT Message-Id: <201408141949.s7EJnSY7065322@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272436 - in soc2014/op/freebsd-base/sys: amd64/amd64 conf kern x86/include MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 19:49:32 -0000 Author: op Date: Thu Aug 14 19:49:28 2014 New Revision: 272436 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272436 Log: KSP SMAP: added KSP_FRAMEWORK and INTEL_SMAP_SUPPORT knobs Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/master Modified: soc2014/op/freebsd-base/sys/amd64/amd64/initcpu.c soc2014/op/freebsd-base/sys/amd64/amd64/machdep.c soc2014/op/freebsd-base/sys/amd64/amd64/pmap.c soc2014/op/freebsd-base/sys/amd64/amd64/trap.c soc2014/op/freebsd-base/sys/conf/NOTES soc2014/op/freebsd-base/sys/conf/files.amd64 soc2014/op/freebsd-base/sys/conf/options soc2014/op/freebsd-base/sys/conf/options.amd64 soc2014/op/freebsd-base/sys/kern/kern_linker.c soc2014/op/freebsd-base/sys/x86/include/selfpatch-asmacros.h Modified: soc2014/op/freebsd-base/sys/amd64/amd64/initcpu.c ============================================================================== --- soc2014/op/freebsd-base/sys/amd64/amd64/initcpu.c Thu Aug 14 19:49:05 2014 (r272435) +++ soc2014/op/freebsd-base/sys/amd64/amd64/initcpu.c Thu Aug 14 19:49:28 2014 (r272436) @@ -176,8 +176,10 @@ */ if (!IS_BSP() && (cpu_stdext_feature & CPUID_STDEXT_SMEP)) cr4 |= CR4_SMEP; +#ifdef INTEL_SMAP_SUPPORT if (!IS_BSP() && (cpu_stdext_feature & CPUID_STDEXT_SMAP)) cr4 |= CR4_SMAP; +#endif load_cr4(cr4); if ((amd_feature & AMDID_NX) != 0) { msr = rdmsr(MSR_EFER) | EFER_NXE; Modified: soc2014/op/freebsd-base/sys/amd64/amd64/machdep.c ============================================================================== --- soc2014/op/freebsd-base/sys/amd64/amd64/machdep.c Thu Aug 14 19:49:05 2014 (r272435) +++ soc2014/op/freebsd-base/sys/amd64/amd64/machdep.c Thu Aug 14 19:49:28 2014 (r272436) @@ -53,6 +53,7 @@ #include "opt_perfmon.h" #include "opt_platform.h" #include "opt_sched.h" +#include "opt_selfpatch.h" #include #include @@ -1999,8 +2000,10 @@ initializecpu(); /* Initialize CPU registers */ initializecpucache(); +#if defined(KSP_FRAMEWORK) || defined(INTEL_SMAP_SUPPORT) /* selfmodify kernel text, when needed */ lf_selfpatch(linker_kernel_file, 0); +#endif /* doublefault stack space, runs on ist1 */ common_tss[0].tss_ist1 = (long)&dblfault_stack[sizeof(dblfault_stack)]; Modified: soc2014/op/freebsd-base/sys/amd64/amd64/pmap.c ============================================================================== --- soc2014/op/freebsd-base/sys/amd64/amd64/pmap.c Thu Aug 14 19:49:05 2014 (r272435) +++ soc2014/op/freebsd-base/sys/amd64/amd64/pmap.c Thu Aug 14 19:49:28 2014 (r272436) @@ -100,6 +100,7 @@ * and to when physical maps must be made correct. */ +#include "opt_cpu.h" #include "opt_pmap.h" #include "opt_vm.h" @@ -835,12 +836,14 @@ if (cpu_stdext_feature & CPUID_STDEXT_SMEP) load_cr4(rcr4() | CR4_SMEP); +#ifdef INTEL_SMAP_SUPPORT if (cpu_stdext_feature & CPUID_STDEXT_SMAP) { printf("Intel SMAP: enabled\n"); load_cr4(rcr4() | CR4_SMAP); } else { printf("Intel SMAP: not supported or disabled\n"); } +#endif /* * Initialize the kernel pmap (which is statically allocated). Modified: soc2014/op/freebsd-base/sys/amd64/amd64/trap.c ============================================================================== --- soc2014/op/freebsd-base/sys/amd64/amd64/trap.c Thu Aug 14 19:49:05 2014 (r272435) +++ soc2014/op/freebsd-base/sys/amd64/amd64/trap.c Thu Aug 14 19:49:28 2014 (r272436) @@ -698,6 +698,7 @@ map = &vm->vm_map; +#ifdef INTEL_SMAP_SUPPORT /* * If CPL < 3, SMAP protections are disabled if EFLAGS.AC = 1. * If CPL = 3, SMAP applies to all supervisor-mode data accesses @@ -709,6 +710,7 @@ trap_fatal(frame, eva); return(-1); } +#endif /* * When accessing a usermode address, kernel must be @@ -881,7 +883,7 @@ panic("unknown/reserved trap"); } - +#ifdef INTEL_SMAP_SUPPORT /* * Supervisor Mode Access Prevention violation * @@ -906,6 +908,7 @@ */ return (true); } +#endif /* * Double fault handler. Called when a fault occurs while writing Modified: soc2014/op/freebsd-base/sys/conf/NOTES ============================================================================== --- soc2014/op/freebsd-base/sys/conf/NOTES Thu Aug 14 19:49:05 2014 (r272435) +++ soc2014/op/freebsd-base/sys/conf/NOTES Thu Aug 14 19:49:28 2014 (r272436) @@ -2986,3 +2986,7 @@ # Module to enable execution of application via emulators like QEMU options IMAGACT_BINMISC + +# Kernel selfpatch framework +options KSP_FRAMEWORK +options KSP_DEBUG Modified: soc2014/op/freebsd-base/sys/conf/files.amd64 ============================================================================== --- soc2014/op/freebsd-base/sys/conf/files.amd64 Thu Aug 14 19:49:05 2014 (r272435) +++ soc2014/op/freebsd-base/sys/conf/files.amd64 Thu Aug 14 19:49:28 2014 (r272436) @@ -439,7 +439,7 @@ isa/syscons_isa.c optional sc isa/vga_isa.c optional vga kern/kern_clocksource.c standard -kern/kern_selfpatch.c standard +kern/kern_selfpatch.c optional ksp_framework | intel_smap_support kern/link_elf_obj.c standard # # IA32 binary support @@ -554,7 +554,7 @@ x86/x86/nexus.c standard x86/x86/tsc.c standard x86/x86/delay.c standard -x86/x86/selfpatch_machdep.c standard +x86/x86/selfpatch_machdep.c optional ksp_framework | intel_smap_support x86/xen/hvm.c optional xenhvm x86/xen/xen_intr.c optional xen | xenhvm x86/xen/pv.c optional xenhvm Modified: soc2014/op/freebsd-base/sys/conf/options ============================================================================== --- soc2014/op/freebsd-base/sys/conf/options Thu Aug 14 19:49:05 2014 (r272435) +++ soc2014/op/freebsd-base/sys/conf/options Thu Aug 14 19:49:28 2014 (r272436) @@ -927,4 +927,5 @@ RANDOM_RWFILE opt_random.h # kernel selfpatch +KSP_FRAMEWORK opt_selfpatch.h KSP_DEBUG opt_selfpatch.h Modified: soc2014/op/freebsd-base/sys/conf/options.amd64 ============================================================================== --- soc2014/op/freebsd-base/sys/conf/options.amd64 Thu Aug 14 19:49:05 2014 (r272435) +++ soc2014/op/freebsd-base/sys/conf/options.amd64 Thu Aug 14 19:49:28 2014 (r272436) @@ -65,3 +65,6 @@ # options for the Intel C600 SAS driver (isci) ISCI_LOGGING opt_isci.h + +# Intel Supervisor Mode Access Prevention +INTEL_SMAP_SUPPORT opt_cpu.h Modified: soc2014/op/freebsd-base/sys/kern/kern_linker.c ============================================================================== --- soc2014/op/freebsd-base/sys/kern/kern_linker.c Thu Aug 14 19:49:05 2014 (r272435) +++ soc2014/op/freebsd-base/sys/kern/kern_linker.c Thu Aug 14 19:49:28 2014 (r272436) @@ -27,9 +27,11 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_cpu.h" #include "opt_ddb.h" #include "opt_kld.h" #include "opt_hwpmc_hooks.h" +#include "opt_selfpatch.h" #include #include @@ -421,11 +423,13 @@ return (error); } modules = !TAILQ_EMPTY(&lf->modules); +#if defined(KSP_FRAMEWORK) || defined (INTEL_SMAP_SUPPORT) error = lf_selfpatch(lf, KSP_MODULE); if (error != 0) { linker_file_unload(lf, LINKER_UNLOAD_FORCE); return (error); } +#endif linker_file_register_sysctls(lf); linker_file_sysinit(lf); lf->flags |= LINKER_FILE_LINKED; @@ -1614,13 +1618,14 @@ goto fail; } linker_file_register_modules(lf); - /* XXXOP */ +#if defined(KSP_FRAMEWORK) || defined(INTEL_SMAP_SUPPORT) error = lf_selfpatch(lf, KSP_MODULE); if (error != 0) { printf("KLD file %s - could not selfpatching\n", lf->filename); goto fail; } +#endif if (linker_file_lookup_set(lf, "sysinit_set", &si_start, &si_stop, NULL) == 0) sysinit_add(si_start, si_stop); Modified: soc2014/op/freebsd-base/sys/x86/include/selfpatch-asmacros.h ============================================================================== --- soc2014/op/freebsd-base/sys/x86/include/selfpatch-asmacros.h Thu Aug 14 19:49:05 2014 (r272435) +++ soc2014/op/freebsd-base/sys/x86/include/selfpatch-asmacros.h Thu Aug 14 19:49:28 2014 (r272436) @@ -30,6 +30,8 @@ #ifndef __X86_SELFPATCH_ASMACROS_H__ #define __X86_SELFPATCH_ASMACROS_H__ +#include "opt_cpu.h" + #define KSP_CPUID 1 #define KSP_CPUID2 2 #define KSP_AMDID 3 @@ -130,10 +132,15 @@ .quad 0 ; \ .popsection ; +#ifdef INTEL_SMAP_SUPPORT #ifndef _clac #define _clac KSP_INSTR_NOP3_CLAC #endif - +#else +#ifndef _clac +#define _clac +#endif +#endif #define KSP_INSTR_NOP3_STAC \ 0723: \ @@ -154,8 +161,14 @@ .quad 0 ; \ .popsection ; +#ifdef INTEL_SMAP_SUPPORT #ifndef _stac #define _stac KSP_INSTR_NOP3_STAC #endif +#else +#ifndef _stac +#define _stac +#endif +#endif #endif /* __X86_SELFPATCH_ASMACROS_H__ */ From owner-svn-soc-all@FreeBSD.ORG Thu Aug 14 19:49:41 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2335F401 for ; Thu, 14 Aug 2014 19:49:41 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 107D3271D for ; Thu, 14 Aug 2014 19:49:41 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7EJneEC065427 for ; Thu, 14 Aug 2014 19:49:40 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7EJnew3065424 for svn-soc-all@FreeBSD.org; Thu, 14 Aug 2014 19:49:40 GMT (envelope-from op@FreeBSD.org) Date: Thu, 14 Aug 2014 19:49:40 GMT Message-Id: <201408141949.s7EJnew3065424@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272437 - soc2014/op/freebsd-base/sys/amd64/conf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 19:49:41 -0000 Author: op Date: Thu Aug 14 19:49:40 2014 New Revision: 272437 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272437 Log: KSP: added KSP_FRAMEWORK to GENERIC, required by amd64's fpu code Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/master Modified: soc2014/op/freebsd-base/sys/amd64/conf/GENERIC Modified: soc2014/op/freebsd-base/sys/amd64/conf/GENERIC ============================================================================== --- soc2014/op/freebsd-base/sys/amd64/conf/GENERIC Thu Aug 14 19:49:28 2014 (r272436) +++ soc2014/op/freebsd-base/sys/amd64/conf/GENERIC Thu Aug 14 19:49:40 2014 (r272437) @@ -26,6 +26,7 @@ options SCHED_ULE # ULE scheduler options PREEMPTION # Enable kernel thread preemption +options KSP_FRAMEWORK # Kernel run-time selfpatches and updates options INET # InterNETworking options INET6 # IPv6 communications protocols options TCP_OFFLOAD # TCP offload From owner-svn-soc-all@FreeBSD.ORG Thu Aug 14 19:49:54 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6EFAF416 for ; Thu, 14 Aug 2014 19:49:54 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5BCA62720 for ; Thu, 14 Aug 2014 19:49:54 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7EJnsOL065549 for ; Thu, 14 Aug 2014 19:49:54 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7EJnrfv065547 for svn-soc-all@FreeBSD.org; Thu, 14 Aug 2014 19:49:53 GMT (envelope-from op@FreeBSD.org) Date: Thu, 14 Aug 2014 19:49:53 GMT Message-Id: <201408141949.s7EJnrfv065547@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272438 - soc2014/op/freebsd-base/sys/amd64/conf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 19:49:54 -0000 Author: op Date: Thu Aug 14 19:49:53 2014 New Revision: 272438 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272438 Log: SMAP: added INTEL_SMAP_SUPPORT to GENERIC Signed-off-by: Oliver Pinter git: https://github.com/opntr/opBSD/tree/op/gsoc2014/master Modified: soc2014/op/freebsd-base/sys/amd64/conf/GENERIC Modified: soc2014/op/freebsd-base/sys/amd64/conf/GENERIC ============================================================================== --- soc2014/op/freebsd-base/sys/amd64/conf/GENERIC Thu Aug 14 19:49:40 2014 (r272437) +++ soc2014/op/freebsd-base/sys/amd64/conf/GENERIC Thu Aug 14 19:49:53 2014 (r272438) @@ -89,6 +89,9 @@ # Make an SMP-capable kernel by default options SMP # Symmetric MultiProcessor Kernel +# Intel Supervisor Mode Access Prevention +options INTEL_SMAP_SUPPORT + # CPU frequency control device cpufreq From owner-svn-soc-all@FreeBSD.ORG Thu Aug 14 22:01:29 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 04672C02 for ; Thu, 14 Aug 2014 22:01:29 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3AAA0306A for ; Thu, 14 Aug 2014 20:33:39 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7EKXdu8084084 for ; Thu, 14 Aug 2014 20:33:39 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7EKXcFW084082 for svn-soc-all@FreeBSD.org; Thu, 14 Aug 2014 20:33:38 GMT (envelope-from op@FreeBSD.org) Date: Thu, 14 Aug 2014 20:33:38 GMT Message-Id: <201408142033.s7EKXcFW084082@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272441 - soc2014/op/patches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 22:01:29 -0000 Author: op Date: Thu Aug 14 20:33:38 2014 New Revision: 272441 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272441 Log: added final version of patch freebsd-head+intel-smap+selfpatch-all.diff Signed-off-by: Oliver Pinter Added: soc2014/op/patches/ soc2014/op/patches/freebsd-head+intel-smap+selfpatch-all.diff Added: soc2014/op/patches/freebsd-head+intel-smap+selfpatch-all.diff ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/op/patches/freebsd-head+intel-smap+selfpatch-all.diff Thu Aug 14 20:33:38 2014 (r272441) @@ -0,0 +1,2265 @@ +diff --git a/.gitignore b/.gitignore +new file mode 100644 +index 0000000..f3b9484 +--- /dev/null ++++ b/.gitignore +@@ -0,0 +1 @@ ++.clang_complete +diff --git a/sys/amd64/amd64/cpu_switch.S b/sys/amd64/amd64/cpu_switch.S +index 7c37a41..a50a80a 100644 +--- a/sys/amd64/amd64/cpu_switch.S ++++ b/sys/amd64/amd64/cpu_switch.S +@@ -35,6 +35,7 @@ + + #include + #include ++#include + + #include "assym.s" + #include "opt_sched.h" +@@ -121,10 +122,7 @@ done_store_dr: + 1: movq %rdx,%rcx + movl xsave_mask,%eax + movl xsave_mask+4,%edx +- .globl ctx_switch_xsave +-ctx_switch_xsave: +- /* This is patched to xsaveopt if supported, see fpuinit_bsp1() */ +- xsave (%r8) ++ _xsave_xsaveopt (%r8) + movq %rcx,%rdx + 2: smsw %ax + orb $CR0_TS,%al +diff --git a/sys/amd64/amd64/exception.S b/sys/amd64/amd64/exception.S +index 2a908a9..1aed663 100644 +--- a/sys/amd64/amd64/exception.S ++++ b/sys/amd64/amd64/exception.S +@@ -42,6 +42,7 @@ + #include + #include + #include ++#include + + #include "assym.s" + +@@ -198,6 +199,7 @@ alltraps_pushregs_no_rdi: + movq %r14,TF_R14(%rsp) + movq %r15,TF_R15(%rsp) + movl $TF_HASSEGS,TF_FLAGS(%rsp) ++ _clac + cld + FAKE_MCOUNT(TF_RIP(%rsp)) + #ifdef KDTRACE_HOOKS +@@ -278,6 +280,7 @@ IDTVEC(dblfault) + movw %es,TF_ES(%rsp) + movw %ds,TF_DS(%rsp) + movl $TF_HASSEGS,TF_FLAGS(%rsp) ++ _clac + cld + testb $SEL_RPL_MASK,TF_CS(%rsp) /* Did we come from kernel? */ + jz 1f /* already running with kernel GS.base */ +@@ -381,6 +384,7 @@ IDTVEC(fast_syscall) + movq %r14,TF_R14(%rsp) /* C preserved */ + movq %r15,TF_R15(%rsp) /* C preserved */ + movl $TF_HASSEGS,TF_FLAGS(%rsp) ++ _clac + cld + FAKE_MCOUNT(TF_RIP(%rsp)) + movq PCPU(CURTHREAD),%rdi +@@ -452,6 +456,7 @@ IDTVEC(fast_syscall32) + */ + + IDTVEC(nmi) ++ _clac + subq $TF_RIP,%rsp + movl $(T_NMI),TF_TRAPNO(%rsp) + movq $0,TF_ADDR(%rsp) +@@ -535,6 +540,7 @@ nmi_calltrap: + movq %rdx,%rdi /* destination stack pointer */ + + shrq $3,%rcx /* trap frame size in long words */ ++ _clac + cld + rep + movsq /* copy trapframe */ +diff --git a/sys/amd64/amd64/fpu.c b/sys/amd64/amd64/fpu.c +index 0f4b2b5..a897ef7 100644 +--- a/sys/amd64/amd64/fpu.c ++++ b/sys/amd64/amd64/fpu.c +@@ -203,16 +203,6 @@ fpuinit_bsp1(void) + xsave_mask &= ~XFEATURE_AVX512; + if ((xsave_mask & XFEATURE_MPX) != XFEATURE_MPX) + xsave_mask &= ~XFEATURE_MPX; +- +- cpuid_count(0xd, 0x1, cp); +- if ((cp[0] & CPUID_EXTSTATE_XSAVEOPT) != 0) { +- /* +- * Patch the XSAVE instruction in the cpu_switch code +- * to XSAVEOPT. We assume that XSAVE encoding used +- * REX byte, and set the bit 4 of the r/m byte. +- */ +- ctx_switch_xsave[3] |= 0x10; +- } + } + + /* +diff --git a/sys/amd64/amd64/identcpu.c b/sys/amd64/amd64/identcpu.c +index 3b66369..226389e 100644 +--- a/sys/amd64/amd64/identcpu.c ++++ b/sys/amd64/amd64/identcpu.c +@@ -566,13 +566,21 @@ identify_cpu(void) + */ + if (cpu_feature2 & CPUID2_HV) { + cpu_stdext_disable = CPUID_STDEXT_FSGSBASE | +- CPUID_STDEXT_SMEP; ++ CPUID_STDEXT_SMEP | CPUID_STDEXT_SMAP; + } else + cpu_stdext_disable = 0; + TUNABLE_INT_FETCH("hw.cpu_stdext_disable", &cpu_stdext_disable); + cpu_stdext_feature &= ~cpu_stdext_disable; + } + ++ if (cpu_high >= 13) { ++ if (cpu_feature2 & CPUID2_XSAVE) { ++ cpuid_count(13, 1, regs); ++ cpu_extstate = regs[0]; ++ } else ++ cpu_extstate = 0; ++ } ++ + if (cpu_vendor_id == CPU_VENDOR_INTEL || + cpu_vendor_id == CPU_VENDOR_AMD || + cpu_vendor_id == CPU_VENDOR_CENTAUR) { +diff --git a/sys/amd64/amd64/initcpu.c b/sys/amd64/amd64/initcpu.c +index 34a362d..f5976eb 100644 +--- a/sys/amd64/amd64/initcpu.c ++++ b/sys/amd64/amd64/initcpu.c +@@ -78,6 +78,7 @@ u_int cpu_max_ext_state_size; + u_int cpu_mon_mwait_flags; /* MONITOR/MWAIT flags (CPUID.05H.ECX) */ + u_int cpu_mon_min_size; /* MONITOR minimum range size, bytes */ + u_int cpu_mon_max_size; /* MONITOR minimum range size, bytes */ ++u_int cpu_extstate; /* Extended State features */ + + SYSCTL_UINT(_hw, OID_AUTO, via_feature_rng, CTLFLAG_RD, + &via_feature_rng, 0, "VIA RNG feature available in CPU"); +@@ -168,13 +169,17 @@ initializecpu(void) + cr4 |= CR4_FSGSBASE; + + /* +- * Postpone enabling the SMEP on the boot CPU until the page +- * tables are switched from the boot loader identity mapping ++ * Postpone enabling the SMEP and SMAP on the boot CPU until the ++ * page tables are switched from the boot loader identity mapping + * to the kernel tables. The boot loader enables the U bit in + * its tables. + */ + if (!IS_BSP() && (cpu_stdext_feature & CPUID_STDEXT_SMEP)) + cr4 |= CR4_SMEP; ++#ifdef INTEL_SMAP_SUPPORT ++ if (!IS_BSP() && (cpu_stdext_feature & CPUID_STDEXT_SMAP)) ++ cr4 |= CR4_SMAP; ++#endif + load_cr4(cr4); + if ((amd_feature & AMDID_NX) != 0) { + msr = rdmsr(MSR_EFER) | EFER_NXE; +diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c +index f02045d..237cc7f 100644 +--- a/sys/amd64/amd64/machdep.c ++++ b/sys/amd64/amd64/machdep.c +@@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$"); + #include "opt_perfmon.h" + #include "opt_platform.h" + #include "opt_sched.h" ++#include "opt_selfpatch.h" + + #include + #include +@@ -81,6 +82,7 @@ __FBSDID("$FreeBSD$"); + #include + #include + #include ++#include + #include + #ifdef SMP + #include +@@ -1998,6 +2000,11 @@ hammer_time(u_int64_t modulep, u_int64_t physfree) + initializecpu(); /* Initialize CPU registers */ + initializecpucache(); + ++#if defined(KSP_FRAMEWORK) || defined(INTEL_SMAP_SUPPORT) ++ /* selfmodify kernel text, when needed */ ++ lf_selfpatch(linker_kernel_file, 0); ++#endif ++ + /* doublefault stack space, runs on ist1 */ + common_tss[0].tss_ist1 = (long)&dblfault_stack[sizeof(dblfault_stack)]; + +diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c +index 6adc86d..508dcdd 100644 +--- a/sys/amd64/amd64/pmap.c ++++ b/sys/amd64/amd64/pmap.c +@@ -100,6 +100,7 @@ __FBSDID("$FreeBSD$"); + * and to when physical maps must be made correct. + */ + ++#include "opt_cpu.h" + #include "opt_pmap.h" + #include "opt_vm.h" + +@@ -429,7 +430,6 @@ static vm_page_t pmap_enter_quick_locked(pmap_t pmap, vm_offset_t va, + vm_page_t m, vm_prot_t prot, vm_page_t mpte, struct rwlock **lockp); + static void pmap_fill_ptp(pt_entry_t *firstpte, pt_entry_t newpte); + static int pmap_insert_pt_page(pmap_t pmap, vm_page_t mpte); +-static void pmap_kenter_attr(vm_offset_t va, vm_paddr_t pa, int mode); + static vm_page_t pmap_lookup_pt_page(pmap_t pmap, vm_offset_t va); + static void pmap_pde_attr(pd_entry_t *pde, int cache_bits, int mask); + static void pmap_promote_pde(pmap_t pmap, pd_entry_t *pde, vm_offset_t va, +@@ -836,6 +836,15 @@ pmap_bootstrap(vm_paddr_t *firstaddr) + if (cpu_stdext_feature & CPUID_STDEXT_SMEP) + load_cr4(rcr4() | CR4_SMEP); + ++#ifdef INTEL_SMAP_SUPPORT ++ if (cpu_stdext_feature & CPUID_STDEXT_SMAP) { ++ printf("Intel SMAP: enabled\n"); ++ load_cr4(rcr4() | CR4_SMAP); ++ } else { ++ printf("Intel SMAP: not supported or disabled\n"); ++ } ++#endif ++ + /* + * Initialize the kernel pmap (which is statically allocated). + */ +@@ -1915,7 +1924,7 @@ pmap_kenter(vm_offset_t va, vm_paddr_t pa) + pte_store(pte, pa | X86_PG_RW | X86_PG_V | X86_PG_G); + } + +-static __inline void ++__inline void + pmap_kenter_attr(vm_offset_t va, vm_paddr_t pa, int mode) + { + pt_entry_t *pte; +diff --git a/sys/amd64/amd64/support.S b/sys/amd64/amd64/support.S +index 77dbf63..ed92e36 100644 +--- a/sys/amd64/amd64/support.S ++++ b/sys/amd64/amd64/support.S +@@ -35,6 +35,8 @@ + #include + #include + #include ++#include ++#include + + #include "assym.s" + +@@ -59,7 +61,7 @@ ENTRY(bzero) + stosb + ret + END(bzero) +- ++ + /* Address: %rdi */ + ENTRY(pagezero) + movq $-PAGE_SIZE,%rdx +@@ -137,7 +139,7 @@ ENTRY(bcopy) + cld + ret + END(bcopy) +- ++ + /* + * Note: memcpy does not support overlapping copies + */ +@@ -181,10 +183,10 @@ ENTRY(pagecopy) + ret + END(pagecopy) + +-/* fillw(pat, base, cnt) */ ++/* fillw(pat, base, cnt) */ + /* %rdi,%rsi, %rdx */ + ENTRY(fillw) +- movq %rdi,%rax ++ movq %rdi,%rax + movq %rsi,%rdi + movq %rdx,%rcx + cld +@@ -203,6 +205,9 @@ END(fillw) + * These routines set curpcb->pcb_onfault for the time they execute. When a + * protection violation occurs inside the functions, the trap handler + * returns to *curpcb->pcb_onfault instead of the function. ++ * ++ * Warning: when Intel SMAP are enabled on CPU, the EFLAGS.AC bit gets ++ * cleared before reaches the fault handler. + */ + + /* +@@ -244,12 +249,16 @@ ENTRY(copyout) + + shrq $3,%rcx + cld ++ _stac /* open user-space */ + rep + movsq ++ _clac /* close user-space */ + movb %dl,%cl + andb $7,%cl ++ _stac /* open user-space */ + rep + movsb ++ _clac /* close user-space */ + + done_copyout: + xorl %eax,%eax +@@ -259,6 +268,9 @@ done_copyout: + + ALIGN_TEXT + copyout_fault: ++ /* ++ * WARNING: on fault EFLAGS.AC gets cleared by Intel SMAP if available ++ */ + movq PCPU(CURPCB),%rdx + movq $0,PCB_ONFAULT(%rdx) + movq $EFAULT,%rax +@@ -290,12 +302,16 @@ ENTRY(copyin) + movb %cl,%al + shrq $3,%rcx /* copy longword-wise */ + cld ++ _stac /* open user-space */ + rep + movsq ++ _clac /* close user-space */ + movb %al,%cl + andb $7,%cl /* copy remaining bytes */ ++ _stac /* open user-space */ + rep + movsb ++ _clac /* close user-space */ + + done_copyin: + xorl %eax,%eax +@@ -305,6 +321,9 @@ done_copyin: + + ALIGN_TEXT + copyin_fault: ++ /* ++ * WARNING: on fault EFLAGS.AC gets cleared by Intel SMAP if available ++ */ + movq PCPU(CURPCB),%rdx + movq $0,PCB_ONFAULT(%rdx) + movq $EFAULT,%rax +@@ -324,10 +343,12 @@ ENTRY(casuword32) + ja fusufault + + movl %esi,%eax /* old */ ++ _stac /* open user-space */ + #ifdef SMP + lock + #endif + cmpxchgl %edx,(%rdi) /* new = %edx */ ++ _clac /* close user-space */ + + /* + * The old value is in %eax. If the store succeeded it will be the +@@ -353,10 +374,12 @@ ENTRY(casuword) + ja fusufault + + movq %rsi,%rax /* old */ ++ _stac /* open user-space */ + #ifdef SMP + lock + #endif + cmpxchgq %rdx,(%rdi) /* new = %rdx */ ++ _clac /* close user-space */ + + /* + * The old value is in %eax. If the store succeeded it will be the +@@ -385,10 +408,12 @@ ENTRY(fuword) + cmpq %rax,%rdi /* verify address is valid */ + ja fusufault + ++ _stac /* open user-space */ + movq (%rdi),%rax ++ _clac /* close user-space */ + movq $0,PCB_ONFAULT(%rcx) + ret +-END(fuword64) ++END(fuword64) + END(fuword) + + ENTRY(fuword32) +@@ -399,7 +424,9 @@ ENTRY(fuword32) + cmpq %rax,%rdi /* verify address is valid */ + ja fusufault + ++ _stac /* open user-space */ + movl (%rdi),%eax ++ _clac /* close user-space */ + movq $0,PCB_ONFAULT(%rcx) + ret + END(fuword32) +@@ -426,7 +453,9 @@ ENTRY(fuword16) + cmpq %rax,%rdi + ja fusufault + ++ _stac /* open user-space */ + movzwl (%rdi),%eax ++ _clac /* close user-space */ + movq $0,PCB_ONFAULT(%rcx) + ret + END(fuword16) +@@ -439,13 +468,18 @@ ENTRY(fubyte) + cmpq %rax,%rdi + ja fusufault + ++ _stac /* open user-space */ + movzbl (%rdi),%eax ++ _clac /* close user-space */ + movq $0,PCB_ONFAULT(%rcx) + ret + END(fubyte) + + ALIGN_TEXT + fusufault: ++ /* ++ * WARNING: on fault EFLAGS.AC gets cleared by Intel SMAP if available ++ */ + movq PCPU(CURPCB),%rcx + xorl %eax,%eax + movq %rax,PCB_ONFAULT(%rcx) +@@ -466,7 +500,9 @@ ENTRY(suword) + cmpq %rax,%rdi /* verify address validity */ + ja fusufault + ++ _stac /* open user-space */ + movq %rsi,(%rdi) ++ _clac /* close user-space */ + xorl %eax,%eax + movq PCPU(CURPCB),%rcx + movq %rax,PCB_ONFAULT(%rcx) +@@ -482,7 +518,9 @@ ENTRY(suword32) + cmpq %rax,%rdi /* verify address validity */ + ja fusufault + ++ _stac /* open user-space */ + movl %esi,(%rdi) ++ _clac /* close user-space */ + xorl %eax,%eax + movq PCPU(CURPCB),%rcx + movq %rax,PCB_ONFAULT(%rcx) +@@ -497,7 +535,9 @@ ENTRY(suword16) + cmpq %rax,%rdi /* verify address validity */ + ja fusufault + ++ _stac /* open user-space */ + movw %si,(%rdi) ++ _clac /* close user-space */ + xorl %eax,%eax + movq PCPU(CURPCB),%rcx /* restore trashed register */ + movq %rax,PCB_ONFAULT(%rcx) +@@ -513,7 +553,9 @@ ENTRY(subyte) + ja fusufault + + movl %esi,%eax ++ _stac /* open user-space */ + movb %al,(%rdi) ++ _clac /* close user-space */ + xorl %eax,%eax + movq PCPU(CURPCB),%rcx /* restore trashed register */ + movq %rax,PCB_ONFAULT(%rcx) +@@ -555,7 +597,9 @@ ENTRY(copyinstr) + decq %rdx + jz 3f + ++ _stac /* open user-space */ + lodsb ++ _clac /* close user-space */ + stosb + orb %al,%al + jnz 2b +@@ -584,7 +628,9 @@ cpystrflt_x: + testq %r9,%r9 + jz 1f + subq %rdx,%r8 ++ _stac /* open user-space */ + movq %r8,(%r9) ++ _clac /* close user-space */ + 1: + ret + END(copyinstr) +diff --git a/sys/amd64/amd64/trap.c b/sys/amd64/amd64/trap.c +index f6459f4..de7fe00 100644 +--- a/sys/amd64/amd64/trap.c ++++ b/sys/amd64/amd64/trap.c +@@ -104,6 +104,7 @@ void dblfault_handler(struct trapframe *frame); + + static int trap_pfault(struct trapframe *, int); + static void trap_fatal(struct trapframe *, vm_offset_t); ++static bool smap_access_violation(struct trapframe *, int usermode); + + #define MAX_TRAP_MSG 32 + static char *trap_msg[] = { +@@ -697,6 +698,20 @@ trap_pfault(frame, usermode) + + map = &vm->vm_map; + ++#ifdef INTEL_SMAP_SUPPORT ++ /* ++ * If CPL < 3, SMAP protections are disabled if EFLAGS.AC = 1. ++ * If CPL = 3, SMAP applies to all supervisor-mode data accesses ++ * (these are implicit supervisor accesses) regardless of the ++ * value of EFLAGS.AC." - Intel Ref. # 319433-014 9.3.2 ++ */ ++ if (__predict_false(smap_access_violation(frame, usermode))) { ++ printf("\nSupervisor Mode Access Prevention\n"); ++ trap_fatal(frame, eva); ++ return(-1); ++ } ++#endif ++ + /* + * When accessing a usermode address, kernel must be + * ready to accept the page fault, and provide a +@@ -868,6 +883,33 @@ trap_fatal(frame, eva) + panic("unknown/reserved trap"); + } + ++#ifdef INTEL_SMAP_SUPPORT ++/* ++ * Supervisor Mode Access Prevention violation ++ * ++ * If CPL < 3, SMAP protections are disabled if EFLAGS.AC = 1. ++ * If CPL = 3, SMAP applies to all supervisor-mode data accesses ++ * (these are implicit supervisor accesses) regardless of the ++ * value of EFLAGS.AC." - Intel Ref. # 319433-014 9.3.2 ++ */ ++static bool ++smap_access_violation(struct trapframe *frame, int usermode) ++{ ++ /* SMAP disabled */ ++ if ((cpu_stdext_feature & CPUID_STDEXT_SMAP) == 0) ++ return (false); ++ ++ /* CPL == 3 or EFLAGS.AC == 1 */ ++ if (usermode || (frame->tf_rflags & PSL_AC) != 0) ++ return (false); ++ ++ /* ++ * CPL < 3 and EFLAGS.AC == 0 ++ */ ++ return (true); ++} ++#endif ++ + /* + * Double fault handler. Called when a fault occurs while writing + * a frame for a trap/exception onto the stack. This usually occurs +diff --git a/sys/amd64/conf/GENERIC b/sys/amd64/conf/GENERIC +index 4269889..3a0ccf9 100644 +--- a/sys/amd64/conf/GENERIC ++++ b/sys/amd64/conf/GENERIC +@@ -26,6 +26,7 @@ makeoptions WITH_CTF=1 # Run ctfconvert(1) for DTrace support + + options SCHED_ULE # ULE scheduler + options PREEMPTION # Enable kernel thread preemption ++options KSP_FRAMEWORK # Kernel run-time selfpatches and updates + options INET # InterNETworking + options INET6 # IPv6 communications protocols + options TCP_OFFLOAD # TCP offload +@@ -88,6 +89,9 @@ options MALLOC_DEBUG_MAXZONES=8 # Separate malloc(9) zones + # Make an SMP-capable kernel by default + options SMP # Symmetric MultiProcessor Kernel + ++# Intel Supervisor Mode Access Prevention ++options INTEL_SMAP_SUPPORT ++ + # CPU frequency control + device cpufreq + +diff --git a/sys/amd64/ia32/ia32_exception.S b/sys/amd64/ia32/ia32_exception.S +index fe1a676..8ba7c88 100644 +--- a/sys/amd64/ia32/ia32_exception.S ++++ b/sys/amd64/ia32/ia32_exception.S +@@ -27,6 +27,8 @@ + */ + + #include ++#include ++#include + + #include "assym.s" + +@@ -67,6 +69,7 @@ IDTVEC(int0x80_syscall) + movq %r14,TF_R14(%rsp) + movq %r15,TF_R15(%rsp) + movl $TF_HASSEGS,TF_FLAGS(%rsp) ++ _clac + cld + FAKE_MCOUNT(TF_RIP(%rsp)) + movq %rsp, %rdi +diff --git a/sys/amd64/include/asmacros.h b/sys/amd64/include/asmacros.h +index ce8dce4..d08cab9 100644 +--- a/sys/amd64/include/asmacros.h ++++ b/sys/amd64/include/asmacros.h +@@ -33,6 +33,8 @@ + #define _MACHINE_ASMACROS_H_ + + #include ++#include ++#include + + /* XXX too much duplication in various asm*.h's. */ + +@@ -167,6 +169,7 @@ + movw %es,TF_ES(%rsp) ; \ + movw %ds,TF_DS(%rsp) ; \ + movl $TF_HASSEGS,TF_FLAGS(%rsp) ; \ ++ _clac; \ + cld + + #define POP_FRAME \ +diff --git a/sys/amd64/include/cpufunc.h b/sys/amd64/include/cpufunc.h +index 7464739..acec833 100644 +--- a/sys/amd64/include/cpufunc.h ++++ b/sys/amd64/include/cpufunc.h +@@ -43,6 +43,9 @@ + #error this file needs sys/cdefs.h as a prerequisite + #endif + ++#include ++#include ++ + struct region_descriptor; + + #define readb(va) (*(volatile uint8_t *) (va)) +@@ -587,6 +590,59 @@ cpu_mwait(u_long extensions, u_int hints) + __asm __volatile("mwait" : : "a" (hints), "c" (extensions)); + } + ++/* ++ * Intel SMAP related functions. ++ */ ++static __inline void ++clac(void) ++{ ++ ++ __asm __volatile( ++ "0723: " ++ " " KSP_INSTR_NOP3_C "; " ++ "0724: " ++ " .pushsection set_selfpatch_patch_set, \"ax\" ; " ++ "0725: " ++ " clac ; " ++ "0726: " ++ " .popsection " ++ " .pushsection set_selfpatch_set, \"a\" ; " ++ " .quad 0723b ; " ++ " .quad 0725b ; " ++ " .int 0724b-0723b ; " ++ " .int 0726b-0725b ; " ++ " .int " __XSTRING(KSP_CPUID_STDEXT) " ; " ++ " .int " __XSTRING(CPUID_STDEXT_SMAP) " ; " ++ " .quad 0 ; " ++ " .popsection ; " ++ : : : "memory"); ++} ++ ++static __inline void ++stac(void) ++{ ++ ++ __asm __volatile( ++ "0723: " ++ " " KSP_INSTR_NOP3_C "; " ++ "0724: " ++ " .pushsection set_selfpatch_patch_set, \"ax\" ; " ++ "0725: " ++ " stac ; " ++ "0726: " ++ " .popsection " ++ " .pushsection set_selfpatch_set, \"a\" ; " ++ " .quad 0723b ; " ++ " .quad 0725b ; " ++ " .int 0724b-0723b ; " ++ " .int 0726b-0725b ; " ++ " .int " __XSTRING(KSP_CPUID_STDEXT) " ; " ++ " .int " __XSTRING(CPUID_STDEXT_SMAP) " ; " ++ " .quad 0 ; " ++ " .popsection ; " ++ : : : "memory"); ++} ++ + #ifdef _KERNEL + /* This is defined in but is too painful to get to */ + #ifndef MSR_FSBASE +diff --git a/sys/amd64/include/md_var.h b/sys/amd64/include/md_var.h +index 5ddfbbd..643623b 100644 +--- a/sys/amd64/include/md_var.h ++++ b/sys/amd64/include/md_var.h +@@ -61,7 +61,7 @@ extern u_int cpu_vendor_id; + extern u_int cpu_mon_mwait_flags; + extern u_int cpu_mon_min_size; + extern u_int cpu_mon_max_size; +-extern char ctx_switch_xsave[]; ++extern u_int cpu_extstate; + extern char kstack[]; + extern char sigcode[]; + extern int szsigcode; +diff --git a/sys/amd64/include/pmap.h b/sys/amd64/include/pmap.h +index e83e07e..c6f3a89 100644 +--- a/sys/amd64/include/pmap.h ++++ b/sys/amd64/include/pmap.h +@@ -380,6 +380,7 @@ int pmap_change_attr(vm_offset_t, vm_size_t, int); + void pmap_demote_DMAP(vm_paddr_t base, vm_size_t len, boolean_t invalidate); + void pmap_init_pat(void); + void pmap_kenter(vm_offset_t va, vm_paddr_t pa); ++void pmap_kenter_attr(vm_offset_t va, vm_paddr_t pa, int mode); + void *pmap_kenter_temporary(vm_paddr_t pa, int i); + vm_paddr_t pmap_kextract(vm_offset_t); + void pmap_kremove(vm_offset_t); +diff --git a/sys/amd64/include/selfpatch-asmacros.h b/sys/amd64/include/selfpatch-asmacros.h +new file mode 100644 +index 0000000..fb723de +--- /dev/null ++++ b/sys/amd64/include/selfpatch-asmacros.h +@@ -0,0 +1,34 @@ ++/*- ++ * Copyright (c) 2014, by Oliver Pinter ++ * All rights reserved. ++ * ++ * Redistribution and use in source and binary forms, with or without ++ * modification, are permitted provided that the following conditions ++ * are met: ++ * 1. Redistributions of source code must retain the above copyright ++ * notice, this list of conditions and the following disclaimer. ++ * 2. Redistributions in binary form must reproduce the above copyright ++ * notice, this list of conditions and the following disclaimer in the ++ * documentation and/or other materials provided with the distribution. ++ * ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ++ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ++ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE ++ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ++ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ++ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ++ * SUCH DAMAGE. ++ * ++ * $FreeBSD$ ++ */ ++ ++#ifndef __AMD64_SELFPATH_ASMACROS_H__ ++#define __AMD64_SELFPATH_ASMACROS_H__ ++ ++#include ++ ++#endif /* __AMD64_SELFPATH_ASMACROS_H__ */ +diff --git a/sys/amd64/include/selfpatch-machdep.h b/sys/amd64/include/selfpatch-machdep.h +new file mode 100644 +index 0000000..caa22f7 +--- /dev/null ++++ b/sys/amd64/include/selfpatch-machdep.h +@@ -0,0 +1,34 @@ ++/*- ++ * Copyright (c) 2014, by Oliver Pinter ++ * All rights reserved. ++ * ++ * Redistribution and use in source and binary forms, with or without ++ * modification, are permitted provided that the following conditions ++ * are met: ++ * 1. Redistributions of source code must retain the above copyright ++ * notice, this list of conditions and the following disclaimer. ++ * 2. Redistributions in binary form must reproduce the above copyright ++ * notice, this list of conditions and the following disclaimer in the ++ * documentation and/or other materials provided with the distribution. ++ * ++ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ++ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ++ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE ++ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ++ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ++ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ++ * SUCH DAMAGE. ++ * ++ * $FreeBSD$ ++ */ ++ ++#ifndef __AMD64_SELFPATH_MACHDEP_H__ ++#define __AMD64_SELFPATH_MACHDEP_H__ ++ ++#include ++ ++#endif /* __AMD64_SELFPATH_MACHDEP_H__ */ +diff --git a/sys/conf/NOTES b/sys/conf/NOTES +index 6959425..dd49c17 100644 +--- a/sys/conf/NOTES ++++ b/sys/conf/NOTES +@@ -2986,3 +2986,7 @@ options RANDOM_RWFILE # Read and write entropy cache + + # Module to enable execution of application via emulators like QEMU + options IMAGACT_BINMISC ++ ++# Kernel selfpatch framework ++options KSP_FRAMEWORK ++options KSP_DEBUG +diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64 +index b63044d..d4f4803 100644 +--- a/sys/conf/files.amd64 ++++ b/sys/conf/files.amd64 +@@ -439,6 +439,7 @@ dev/virtio/random/virtio_random.c optional virtio_random + isa/syscons_isa.c optional sc + isa/vga_isa.c optional vga + kern/kern_clocksource.c standard ++kern/kern_selfpatch.c optional ksp_framework | intel_smap_support + kern/link_elf_obj.c standard + # + # IA32 binary support +@@ -553,6 +554,7 @@ x86/x86/msi.c optional pci + x86/x86/nexus.c standard + x86/x86/tsc.c standard + x86/x86/delay.c standard ++x86/x86/selfpatch_machdep.c optional ksp_framework | intel_smap_support + x86/xen/hvm.c optional xenhvm + x86/xen/xen_intr.c optional xen | xenhvm + x86/xen/pv.c optional xenhvm +diff --git a/sys/conf/ldscript.amd64 b/sys/conf/ldscript.amd64 +index 9210a73..5a97c52 100644 +--- a/sys/conf/ldscript.amd64 ++++ b/sys/conf/ldscript.amd64 +@@ -30,6 +30,10 @@ SECTIONS + .rela.data : { *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) } + .rel.tdata : { *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*) } + .rela.tdata : { *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) } ++ .rel.set_selfpatch_set : { *(.rel.set_selfpatch_set) } ++ .rela.set_selfpatch_set : { *(.rela.set_selfpatch_set) } ++ .rel.set_selfpatch_patch_set : { *(.rel.set_selfpatch_patch_set) } ++ .rela.set_selfpatch_patch_set : { *(.rela.set_selfpatch_patch_set) } + .rel.tbss : { *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*) } + .rela.tbss : { *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) } + .rel.ctors : { *(.rel.ctors) } +@@ -140,6 +144,18 @@ SECTIONS + .got : { *(.got) } + . = DATA_SEGMENT_RELRO_END (24, .); + .got.plt : { *(.got.plt) } ++ set_selfpatch_set : ++ { ++ PROVIDE ( __start_set_selfpatch_set = . ); ++ KEEP (*(set_selfpatch_set)); ++ PROVIDE ( __stop_set_selfpatch_set = . ); ++ } ++ set_selfpatch_patch_set : ++ { ++ PROVIDE ( __start_set_selfpatch_patch_set = . ); ++ KEEP (*(set_selfpatch_patch_set)); ++ PROVIDE ( __stop_set_selfpatch_patch_set = . ); ++ } + .data : + { + *(.data .data.* .gnu.linkonce.d.*) +diff --git a/sys/conf/options b/sys/conf/options +index 6ed7ce9..1e9f21d 100644 +--- a/sys/conf/options ++++ b/sys/conf/options +@@ -927,3 +927,7 @@ RANDOM_YARROW opt_random.h + RANDOM_FORTUNA opt_random.h + RANDOM_DEBUG opt_random.h + RANDOM_RWFILE opt_random.h ++ ++# kernel selfpatch ++KSP_FRAMEWORK opt_selfpatch.h ++KSP_DEBUG opt_selfpatch.h +diff --git a/sys/conf/options.amd64 b/sys/conf/options.amd64 +index f1d4b4a..cebe69c 100644 +--- a/sys/conf/options.amd64 ++++ b/sys/conf/options.amd64 +@@ -65,3 +65,6 @@ XENHVM opt_global.h + + # options for the Intel C600 SAS driver (isci) + ISCI_LOGGING opt_isci.h ++ ++# Intel Supervisor Mode Access Prevention ++INTEL_SMAP_SUPPORT opt_cpu.h +diff --git a/sys/i386/i386/db_disasm.c b/sys/i386/i386/db_disasm.c +index 719c9f7..b0176a9 100644 +--- a/sys/i386/i386/db_disasm.c ++++ b/sys/i386/i386/db_disasm.c +@@ -1266,13 +1266,23 @@ db_disasm(loc, altfmt) + case 0xc8: + i_name = "monitor"; + i_size = NONE; +- i_mode = 0; ++ i_mode = 0; + break; + case 0xc9: + i_name = "mwait"; + i_size = NONE; + i_mode = 0; + break; ++ case 0xca: ++ i_name = "clac"; ++ i_size = NONE; ++ i_mode = 0; ++ break; ++ case 0xcb: ++ i_name = "stac"; ++ i_size = NONE; ++ i_mode = 0; ++ break; + } + } + if (ip->i_extra == db_Grp15 && f_mod(regmodrm) == 3) { +diff --git a/sys/i386/i386/exception.s b/sys/i386/i386/exception.s +index 39a8828..ff0c25e 100644 +--- a/sys/i386/i386/exception.s ++++ b/sys/i386/i386/exception.s +@@ -162,6 +162,7 @@ alltraps: + pushl %fs + alltraps_with_regs_pushed: + SET_KERNEL_SREGS ++ clac + cld + FAKE_MCOUNT(TF_EIP(%esp)) + calltrap: +diff --git a/sys/i386/i386/identcpu.c b/sys/i386/i386/identcpu.c +index 9a09adb..4cea372 100644 +--- a/sys/i386/i386/identcpu.c ++++ b/sys/i386/i386/identcpu.c +@@ -860,6 +860,47 @@ printcpuinfo(void) + ); + } + ++ if (cpu_stdext_feature != 0) { ++ printf("\n Structured Extended Features=0x%b", ++ cpu_stdext_feature, ++ "\020" ++ /* RDFSBASE/RDGSBASE/WRFSBASE/WRGSBASE */ ++ "\001FSGSBASE" ++ "\002TSCADJ" ++ /* Bit Manipulation Instructions */ ++ "\004BMI1" ++ /* Hardware Lock Elision */ ++ "\005HLE" ++ /* Advanced Vector Instructions 2 */ ++ "\006AVX2" ++ /* Supervisor Mode Execution Prot. */ ++ "\010SMEP" ++ /* Bit Manipulation Instructions */ ++ "\011BMI2" ++ "\012ERMS" ++ /* Invalidate Processor Context ID */ ++ "\013INVPCID" ++ /* Restricted Transactional Memory */ ++ "\014RTM" ++ /* Intel Memory Protection Extensions */ ++ "\017MPX" ++ /* AVX512 Foundation */ ++ "\021AVX512F" ++ /* Enhanced NRBG */ ++ "\023RDSEED" ++ /* ADCX + ADOX */ ++ "\024ADX" ++ /* Supervisor Mode Access Prevention */ ++ "\025SMAP" ++ "\030CLFLUSHOPT" ++ "\032PROCTRACE" ++ "\033AVX512PF" ++ "\034AVX512ER" ++ "\035AVX512CD" ++ "\036SHA" ++ ); ++ } ++ + if (via_feature_rng != 0 || via_feature_xcrypt != 0) + print_via_padlock_info(); + +@@ -1099,7 +1140,7 @@ finishidentcpu(void) + { + int isblue = 0; + u_char ccr3; +- u_int regs[4]; ++ u_int regs[4], cpu_stdext_disable; + + cpu_vendor_id = find_cpu_vendor_id(); + +@@ -1128,6 +1169,25 @@ finishidentcpu(void) + cpu_mon_max_size = regs[1] & CPUID5_MON_MAX_SIZE; + } + ++ if (cpu_high >= 7) { ++ cpuid_count(7, 0, regs); ++ cpu_stdext_feature = regs[1]; ++ ++ /* *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-soc-all@FreeBSD.ORG Thu Aug 14 22:23:58 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 813E5BDD for ; Thu, 14 Aug 2014 22:23:58 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6AA024A8E for ; Thu, 14 Aug 2014 22:23:58 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7EMNwO8011359 for ; Thu, 14 Aug 2014 22:23:58 GMT (envelope-from ghostmansd@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7EMNtDk011325 for svn-soc-all@FreeBSD.org; Thu, 14 Aug 2014 22:23:55 GMT (envelope-from ghostmansd@FreeBSD.org) Date: Thu, 14 Aug 2014 22:23:55 GMT Message-Id: <201408142223.s7EMNtDk011325@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to ghostmansd@FreeBSD.org using -f From: ghostmansd@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272445 - in soc2014/ghostmansd/head: contrib/colldb lib/libc lib/libc/locale lib/libc/string lib/libc/unicode lib/libcolldb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 22:23:58 -0000 Author: ghostmansd Date: Thu Aug 14 22:23:54 2014 New Revision: 272445 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272445 Log: changing fallback behaviour; deprecating _UNICODE_SOURCE Added: soc2014/ghostmansd/head/lib/libcolldb/colldb - copied, changed from r272296, soc2014/ghostmansd/head/contrib/colldb/colldb soc2014/ghostmansd/head/lib/libcolldb/colldb.c - copied unchanged from r272296, soc2014/ghostmansd/head/contrib/colldb/colldb.c soc2014/ghostmansd/head/lib/libcolldb/colldb.h - copied unchanged from r272296, soc2014/ghostmansd/head/contrib/colldb/colldb.h Deleted: soc2014/ghostmansd/head/contrib/colldb/ Modified: soc2014/ghostmansd/head/lib/libc/Makefile soc2014/ghostmansd/head/lib/libc/locale/collate.c soc2014/ghostmansd/head/lib/libc/locale/xlocale.c soc2014/ghostmansd/head/lib/libc/locale/xlocale_private.h soc2014/ghostmansd/head/lib/libc/string/wcscoll.c soc2014/ghostmansd/head/lib/libc/string/wcsxfrm.c soc2014/ghostmansd/head/lib/libc/unicode/ucscoll.c soc2014/ghostmansd/head/lib/libcolldb/Makefile Modified: soc2014/ghostmansd/head/lib/libc/Makefile ============================================================================== --- soc2014/ghostmansd/head/lib/libc/Makefile Thu Aug 14 21:43:20 2014 (r272444) +++ soc2014/ghostmansd/head/lib/libc/Makefile Thu Aug 14 22:23:54 2014 (r272445) @@ -94,10 +94,7 @@ .include "${LIBC_SRCTOP}/stdlib/jemalloc/Makefile.inc" .include "${LIBC_SRCTOP}/stdtime/Makefile.inc" .include "${LIBC_SRCTOP}/string/Makefile.inc" -.ifdef UNICODE -CFLAGS+= -D_UNICODE_SOURCE .include "${LIBC_SRCTOP}/unicode/Makefile.inc" -.endif .include "${LIBC_SRCTOP}/sys/Makefile.inc" .include "${LIBC_SRCTOP}/rpc/Makefile.inc" .include "${LIBC_SRCTOP}/uuid/Makefile.inc" Modified: soc2014/ghostmansd/head/lib/libc/locale/collate.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/locale/collate.c Thu Aug 14 21:43:20 2014 (r272444) +++ soc2014/ghostmansd/head/lib/libc/locale/collate.c Thu Aug 14 22:23:54 2014 (r272445) @@ -41,6 +41,12 @@ #include #include #include + +#include +#include +#include +#include + #include "un-namespace.h" #include "collate.h" @@ -50,39 +56,12 @@ #include "libc_private.h" -#ifdef _UNICODE_SOURCE -#include -#include -#include -#include -#include - - struct __colldb { uint32_t version; void *handle; }; -static void *handle = NULL; -static pthread_once_t once = PTHREAD_ONCE_INIT; - - -static void -__colldb_root_init(void) -{ - handle = __colldb_open("/usr/share/colldb/root.db"); -} - - -void * -__colldb_root_handle(void) -{ - pthread_once(&once, &__colldb_root_init); - return (handle); -} - - void * __colldb_create(const char *path, int mode) { @@ -360,7 +339,6 @@ } return state; } -#endif /* Modified: soc2014/ghostmansd/head/lib/libc/locale/xlocale.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/locale/xlocale.c Thu Aug 14 21:43:20 2014 (r272444) +++ soc2014/ghostmansd/head/lib/libc/locale/xlocale.c Thu Aug 14 22:23:54 2014 (r272445) @@ -36,6 +36,24 @@ #include "libc_private.h" #include "xlocale_private.h" + +/* Collation Database implementation. */ +static void *colldb_root_handle = NULL; +static pthread_once_t colldb_root_once = PTHREAD_ONCE_INIT; + +static void colldb_root_init(void) +{ + colldb_root_handle = + __colldb_open("/usr/share/locale/UTF-8/LC_COLLATE"); +} + +void *__colldb_root_handle(void) +{ + _once(&colldb_root_once, &colldb_root_init); + return (colldb_root_handle); +} + + /** * Each locale loader declares a global component. This is used by setlocale() * and also by xlocale with LC_GLOBAL_LOCALE.. @@ -81,9 +99,7 @@ &__xlocale_global_time, &__xlocale_global_messages }, -#ifdef _UNICODE_SOURCE NULL, -#endif 1, 0, 1, @@ -97,9 +113,7 @@ &__xlocale_C_ctype, 0, 0, 0, 0 }, -#ifdef _UNICODE_SOURCE NULL, -#endif 1, 0, 1, Modified: soc2014/ghostmansd/head/lib/libc/locale/xlocale_private.h ============================================================================== --- soc2014/ghostmansd/head/lib/libc/locale/xlocale_private.h Thu Aug 14 21:43:20 2014 (r272444) +++ soc2014/ghostmansd/head/lib/libc/locale/xlocale_private.h Thu Aug 14 22:23:54 2014 (r272445) @@ -38,12 +38,8 @@ #include #include #include -#include "setlocale.h" - - -#ifdef _UNICODE_SOURCE -#include #include +#include "setlocale.h" /* Unicode canonicalization. */ int __uccclass(uint32_t); @@ -89,7 +85,6 @@ size_t __ucsxfrm(uint32_t*, const uint32_t*, size_t, void*); int __ucscoll(const uint32_t*, const uint32_t*, void*); -#endif enum { @@ -137,10 +132,8 @@ struct xlocale_refcounted header; /** Components for the locale. */ struct xlocale_component *components[XLC_LAST]; -#ifdef _UNICODE_SOURCE /** Collation Database handle. */ void *colldb; -#endif /** Flag indicating if components[XLC_MONETARY] has changed since the * last call to localeconv_l() with this locale. */ int monetary_locale_changed; Modified: soc2014/ghostmansd/head/lib/libc/string/wcscoll.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/string/wcscoll.c Thu Aug 14 21:43:20 2014 (r272444) +++ soc2014/ghostmansd/head/lib/libc/string/wcscoll.c Thu Aug 14 22:23:54 2014 (r272445) @@ -41,7 +41,9 @@ #include #include "collate.h" -#ifndef _UNICODE_SOURCE +#include + + static char * __mbsdup(const wchar_t *ws) { @@ -62,24 +64,24 @@ return (mbs); } -#endif + int wcscoll_l(const wchar_t *ws1, const wchar_t *ws2, locale_t locale) { -#ifdef _UNICODE_SOURCE - const uint32_t *ucs1 = (const uint32_t*)ws1; - const uint32_t *ucs2 = (const uint32_t*)ws2; - - return __ucscoll(ucs1, ucs2, locale->colldb); - -#else /* !_UNICODE_SOURCE */ char *mbs1, *mbs2; int diff, sverrno; FIX_LOCALE(locale); + const int init_error = errno; + const uint32_t *ucs1 = (const uint32_t*)ws1; + const uint32_t *ucs2 = (const uint32_t*)ws2; struct xlocale_collate *table = (struct xlocale_collate*)locale->components[XLC_COLLATE]; + diff = __ucscoll(ucs1, ucs2, locale->colldb); + if (errno == init_error) + return diff; + if (table->__collate_load_error || MB_CUR_MAX > 1) /* * Locale has no special collating order, could not be @@ -108,7 +110,6 @@ errno = sverrno; return (diff); -#endif } int Modified: soc2014/ghostmansd/head/lib/libc/string/wcsxfrm.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/string/wcsxfrm.c Thu Aug 14 21:43:20 2014 (r272444) +++ soc2014/ghostmansd/head/lib/libc/string/wcsxfrm.c Thu Aug 14 22:23:54 2014 (r272445) @@ -47,19 +47,21 @@ size_t wcsxfrm_l(wchar_t * __restrict dest, const wchar_t * __restrict src, size_t len, locale_t locale) { -#ifdef _UNICODE_SOURCE - uint32_t *udst = (uint32_t*)dest; - const uint32_t *usrc = (const uint32_t*)src; - - return __ucsxfrm(udst, usrc, len, locale->colldb); -#else int prim, sec, l; size_t slen; char *mbsrc, *s, *ss; FIX_LOCALE(locale); + uint32_t *udst = NULL; + size_t ulen = 0; + const int init_error = errno; + const uint32_t *usrc = (const uint32_t*)src; struct xlocale_collate *table = (struct xlocale_collate*)locale->components[XLC_COLLATE]; + ulen = __ucsxfrm(udst, usrc, len, locale->colldb); + if (errno == init_errno) + return (ulen); + if (*src == L'\0') { if (len != 0) *dest = L'\0'; @@ -103,7 +105,6 @@ *dest = L'\0'; return (slen); -#endif } size_t Modified: soc2014/ghostmansd/head/lib/libc/unicode/ucscoll.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/unicode/ucscoll.c Thu Aug 14 21:43:20 2014 (r272444) +++ soc2014/ghostmansd/head/lib/libc/unicode/ucscoll.c Thu Aug 14 22:23:54 2014 (r272445) @@ -30,6 +30,8 @@ #include "xlocale_private.h" #include "coll.h" +#include + int __ucscoll(const uint32_t *lstr, const uint32_t *rstr, void *colldb) @@ -48,12 +50,14 @@ struct __colldb_weight weights[2][__COLLDB_WEIGHTS_MAX]; const int init_error = errno; + fprintf(stderr, "ucscoll\n"); if ((lstr == NULL) || (rstr == NULL)) { errno = EINVAL; return (0); } if (colldb == NULL) colldb = __colldb_root; + fprintf(stderr, "root=%p\n", colldb); for (i = 0; i < 2; ++i) { size[i] = __ucsnorm(NULL, str[i], 0, __UC_NFD); norm[i] = malloc(size[i] * sizeof(uint32_t)); Modified: soc2014/ghostmansd/head/lib/libcolldb/Makefile ============================================================================== --- soc2014/ghostmansd/head/lib/libcolldb/Makefile Thu Aug 14 21:43:20 2014 (r272444) +++ soc2014/ghostmansd/head/lib/libcolldb/Makefile Thu Aug 14 22:23:54 2014 (r272445) @@ -1,6 +1,4 @@ -COLLDB= $(.CURDIR}/../../contrib/colldb -.PATH: ${COLLDB} - +SHLIBDIR?= /usr/lib LIB= colldb SRCS= colldb.c INCS= colldb.h Copied and modified: soc2014/ghostmansd/head/lib/libcolldb/colldb (from r272296, soc2014/ghostmansd/head/contrib/colldb/colldb) ============================================================================== --- soc2014/ghostmansd/head/contrib/colldb/colldb Tue Aug 12 17:29:20 2014 (r272296, copy source) +++ soc2014/ghostmansd/head/lib/libcolldb/colldb Thu Aug 14 22:23:54 2014 (r272445) @@ -15,8 +15,7 @@ __maintainer__ = "Dmitry Selyutin" -#_dll_ = ctypes.CDLL("libcolldb.so") -_dll_ = ctypes.CDLL("./colldb.so") +_dll_ = ctypes.CDLL("libcolldb.so") class _CollDB_Weight_(ctypes.Structure): Copied: soc2014/ghostmansd/head/lib/libcolldb/colldb.c (from r272296, soc2014/ghostmansd/head/contrib/colldb/colldb.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/ghostmansd/head/lib/libcolldb/colldb.c Thu Aug 14 22:23:54 2014 (r272445, copy of r272296, soc2014/ghostmansd/head/contrib/colldb/colldb.c) @@ -0,0 +1,345 @@ +/*- + * Copyright (c) 2014 Dmitry Selyutin. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include "colldb.h" + + +struct colldb { + uint32_t version; + void *handle; +}; + + +void * +colldb_create(const char *path, int mode) +{ + DBT key; + DBT value; + DB *db = NULL; + int error = 0; + void *colldb = NULL; + uint32_t version = 0; + int flags = (O_RDWR | O_CREAT | O_TRUNC); + + colldb = calloc(1, sizeof(struct colldb)); + if (colldb == NULL) + { + errno = ENOMEM; + return (NULL); + } + db = dbopen(path, flags, mode, DB_HASH, NULL); + if (db == NULL) + { + error = errno; + free(colldb); + errno = error; + return (NULL); + } + ((struct colldb*)colldb)->version = COLLDB_VERSION; + + key.data = "TYPE"; + value.data = "COLLATION"; + key.size = (strlen("TYPE") + 1); + value.size = (strlen("COLLATION") + 1); + if (db->put(db, &key, &value, 0) == -1) + { + error = errno; + goto failure; + } + + key.data = "VERSION"; + version = htonl(((struct colldb*)colldb)->version); + value.data = &version; + key.size = (strlen("VERSION") + 1); + value.size = sizeof(((struct colldb*)colldb)->version); + if (db->put(db, &key, &value, 0) == -1) + { + error = errno; + goto failure; + } + + ((struct colldb*)colldb)->handle = db; + return (colldb); + +failure: + (void) db->close(db); + free(colldb); + errno = error; + return (NULL); +} + + +void * +colldb_open(const char *path) +{ + DBT key; + DBT value; + DB *db = NULL; + int error = 0; + int state = 0; + void *colldb = NULL; + int flags = O_RDONLY; + + colldb = calloc(1, sizeof(struct colldb)); + if (colldb == NULL) + { + errno = ENOMEM; + return (NULL); + } + db = dbopen(path, flags, 0, DB_HASH, NULL); + if (db == NULL) + { + error = errno; + free(colldb); + errno = error; + return (NULL); + } + + key.data = "TYPE"; + key.size = (strlen("TYPE") + 1); + state = db->get(db, &key, &value, 0); + if (state != 0) + { + if (state < 0) + error = errno; + else + error = EFTYPE; + goto failure; + } + if (strcmp(value.data, "COLLATION") != 0) + { + error = EFTYPE; + goto failure; + } + + key.data = "VERSION"; + key.size = (strlen("VERSION") + 1); + state = db->get(db, &key, &value, 0); + if (state != 0) + { + if (state < 0) + error = errno; + else + error = EFTYPE; + goto failure; + } + ((struct colldb*)colldb)->version = + ntohl(*(const uint32_t*)value.data); + + ((struct colldb*)colldb)->handle = db; + return (colldb); + +failure: + (void) db->close(db); + free(colldb); + errno = error; + return (NULL); +} + + +int +colldb_close(void *colldb) +{ + DB *db = NULL; + int error = 0; + + if (colldb == NULL) + { + errno = EINVAL; + return (-1); + } + db = ((struct colldb*)colldb)->handle; + if (db == NULL) + { + errno = EINVAL; + return (-1); + } + if (db->close(db) == -1) + { + error = errno; + free(colldb); + errno = error; + return (-1); + } + free(colldb); + return (0); +} + + +int +colldb_sync(void *colldb) +{ + DB *db = NULL; + + if (colldb == NULL) + { + errno = EINVAL; + return (-1); + } + db = ((struct colldb*)colldb)->handle; + if (db == NULL) + { + errno = EINVAL; + return (-1); + } + return db->sync(db, 0); +} + + +int +colldb_get(void *colldb, + struct colldb_key *key, + struct colldb_value *value) +{ + DBT dbkey; + DBT dbvalue; + DB *db = NULL; + size_t i = 0; + int state = 0; + uint32_t *keybuf = NULL; + struct colldb_weight *weights = NULL; + + if ((colldb == NULL) || (key == NULL) || (value == NULL)) + { + errno = EINVAL; + return (-1); + } + db = ((struct colldb*)colldb)->handle; + if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) + { + errno = EINVAL; + return (-1); + } + + keybuf = key->chars; + if (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__) + { + keybuf = malloc(key->count * sizeof(*key->chars)); + if (keybuf == NULL) + { + errno = ENOMEM; + return (-1); + } + for (i = 0; i < key->count; ++i) + keybuf[i] = htonl(key->chars[i]); + } + + dbkey.data = keybuf; + dbkey.size = (key->count * sizeof(*key->chars)); + state = db->get(db, &dbkey, &dbvalue, 0); + if (state != 0) + return (state); + + weights = dbvalue.data; + if ((dbvalue.size / sizeof(*weights)) > value->count) + { + if (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__) + free(keybuf); + errno = ERANGE; + return (-1); + } + value->count = (dbvalue.size / sizeof(*weights)); + for (i = 0; i < value->count; ++i) + { + value->weights[i].alternate = weights[i].alternate; + value->weights[i].level1 = ntohl(weights[i].level1); + value->weights[i].level2 = ntohl(weights[i].level2); + value->weights[i].level3 = ntohl(weights[i].level3); + value->weights[i].level4 = ntohl(weights[i].level4); + } + if (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__) + free(keybuf); + return (0); +} + + +int +colldb_put(void *colldb, + struct colldb_key *key, + struct colldb_value *value) +{ + DBT dbkey; + DBT dbvalue; + DB *db = NULL; + size_t i = 0; + int state = 0; + int error = 0; + uint32_t *keybuf = NULL; + struct colldb_weight *valuebuf = NULL; + + if ((colldb == NULL) || (key == NULL) || (value == NULL)) + { + errno = EINVAL; + return (-1); + } + db = ((struct colldb*)colldb)->handle; + if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) + { + errno = EINVAL; + return (-1); + } + + keybuf = key->chars; + valuebuf = value->weights; + if (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__) + { + keybuf = malloc(key->count * sizeof(*key->chars)); + valuebuf = malloc(value->count * sizeof(*value->weights)); + if ((keybuf == NULL) || (valuebuf == NULL)) + { + errno = ENOMEM; + return (-1); + } + for (i = 0; i < key->count; ++i) + keybuf[i] = htonl(key->chars[i]); + for (i = 0; i < value->count; ++i) + { + valuebuf[i].alternate = value->weights[i].alternate; + valuebuf[i].level1 = htonl(value->weights[i].level1); + valuebuf[i].level2 = htonl(value->weights[i].level2); + valuebuf[i].level3 = htonl(value->weights[i].level3); + valuebuf[i].level4 = htonl(value->weights[i].level4); + } + } + + dbkey.data = keybuf; + dbvalue.data = valuebuf; + dbkey.size = (key->count * sizeof(*key->chars)); + dbvalue.size = (value->count * sizeof(*value->weights)); + state = db->put(db, &dbkey, &dbvalue, 0); + if (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__) + { + error = errno; + free(keybuf); + free(valuebuf); + errno = error; + } + return state; +} Copied: soc2014/ghostmansd/head/lib/libcolldb/colldb.h (from r272296, soc2014/ghostmansd/head/contrib/colldb/colldb.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/ghostmansd/head/lib/libcolldb/colldb.h Thu Aug 14 22:23:54 2014 (r272445, copy of r272296, soc2014/ghostmansd/head/contrib/colldb/colldb.h) @@ -0,0 +1,94 @@ +/*- + * Copyright (c) 2014 Dmitry Selyutin. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DECOMPOSITION, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _COLLDB_H_ +#define _COLLDB_H_ + + +/* + * Unicode Collation Database + * Database is a map of struct colldb_key and struct colldb_value pairs, + * where each uint32_t integer is stored in network byte order. Conversion + * between host and network byte order is done implicitly. + * Each database must contain at least "TYPE" and "VERSION" keys, where + * the first one must always be "COLLATION", the last one must be a version + * as unsigned 32-bit integer. When use creates a new collation database, + * these keys are initialized automatically. + * + * colldb_put() accepts database, key and value. If necessary, it converts + * key and value into the network byte order before writing. + * + * colldb_get() accepts database, key and value. Key is converted to network + * byte order if necessary. Fields of struct colldb_value must be already + * correctly initialized, since value from database is written directly to it. + * Usually it is enough to allocate COLLDB_WEIGHTS_MAX weights. However, + * in order to support exotic databases, colldb_get() may return -1 and set + * errno to ERANGE to indicate that struct colldb_value must allocate + * a larger weights buffer. + */ + +#include +#include +#include +#include +#include + + +#define COLLDB_VERSION 0x00000001 +#define COLLDB_WEIGHTS_MAX 10 + +struct colldb_weight { + uint8_t alternate; + uint32_t level1; + uint32_t level2; + uint32_t level3; + uint32_t level4; +}; + +struct colldb_key { + size_t count; + uint32_t *chars; +}; + +struct colldb_value { + size_t count; + struct colldb_weight *weights; +}; + + +void* colldb_create(const char*, int mode); +void* colldb_open(const char*); +int colldb_close(void*); +int colldb_sync(void*); +int colldb_get(void*, + struct colldb_key*, + struct colldb_value*); +int colldb_put(void*, + struct colldb_key*, + struct colldb_value*); + + +#endif From owner-svn-soc-all@FreeBSD.ORG Thu Aug 14 22:32:44 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D4818EEE for ; Thu, 14 Aug 2014 22:32:44 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id BF3F94B8D for ; Thu, 14 Aug 2014 22:32:44 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7EMWi5b036153 for ; Thu, 14 Aug 2014 22:32:44 GMT (envelope-from ghostmansd@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7EMWiZQ035965 for svn-soc-all@FreeBSD.org; Thu, 14 Aug 2014 22:32:44 GMT (envelope-from ghostmansd@FreeBSD.org) Date: Thu, 14 Aug 2014 22:32:44 GMT Message-Id: <201408142232.s7EMWiZQ035965@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to ghostmansd@FreeBSD.org using -f From: ghostmansd@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272446 - soc2014/ghostmansd/head/lib/libc/locale MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 22:32:45 -0000 Author: ghostmansd Date: Thu Aug 14 22:32:43 2014 New Revision: 272446 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272446 Log: source code reorganization due to namespace collision Modified: soc2014/ghostmansd/head/lib/libc/locale/collate.c soc2014/ghostmansd/head/lib/libc/locale/xlocale.c Modified: soc2014/ghostmansd/head/lib/libc/locale/collate.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/locale/collate.c Thu Aug 14 22:23:54 2014 (r272445) +++ soc2014/ghostmansd/head/lib/libc/locale/collate.c Thu Aug 14 22:32:43 2014 (r272446) @@ -42,11 +42,6 @@ #include #include -#include -#include -#include -#include - #include "un-namespace.h" #include "collate.h" @@ -56,291 +51,6 @@ #include "libc_private.h" -struct __colldb { - uint32_t version; - void *handle; -}; - - -void * -__colldb_create(const char *path, int mode) -{ - DBT key; - DBT value; - DB *db = NULL; - int error = 0; - void *colldb = NULL; - uint32_t version = 0; - int flags = (O_RDWR | O_CREAT | O_TRUNC); - - colldb = calloc(1, sizeof(struct __colldb)); - if (colldb == NULL) { - errno = ENOMEM; - return (NULL); - } - db = dbopen(path, flags, mode, DB_HASH, NULL); - if (db == NULL) { - error = errno; - free(colldb); - errno = error; - return (NULL); - } - ((struct __colldb*)colldb)->version = __COLLDB_VERSION; - - key.data = "TYPE"; - value.data = "COLLATION"; - key.size = (strlen("TYPE") + 1); - value.size = (strlen("COLLATION") + 1); - if (db->put(db, &key, &value, 0) == -1) { - error = errno; - goto failure; - } - - key.data = "VERSION"; - version = htonl(((struct __colldb*)colldb)->version); - value.data = &version; - key.size = (strlen("VERSION") + 1); - value.size = sizeof(((struct __colldb*)colldb)->version); - if (db->put(db, &key, &value, 0) == -1) { - error = errno; - goto failure; - } - - ((struct __colldb*)colldb)->handle = db; - return (colldb); - -failure: - (void) db->close(db); - free(colldb); - errno = error; - return (NULL); -} - - -void * -__colldb_open(const char *path) -{ - DBT key; - DBT value; - DB *db = NULL; - int error = 0; - int state = 0; - void *colldb = NULL; - int flags = O_RDONLY; - - colldb = calloc(1, sizeof(struct __colldb)); - if (colldb == NULL) { - errno = ENOMEM; - return (NULL); - } - db = dbopen(path, flags, 0, DB_HASH, NULL); - if (db == NULL) { - error = errno; - free(colldb); - errno = error; - return (NULL); - } - - key.data = "TYPE"; - key.size = (strlen("TYPE") + 1); - state = db->get(db, &key, &value, 0); - if (state != 0) { - if (state < 0) - error = errno; - else - error = EFTYPE; - goto failure; - } - if (strcmp(value.data, "COLLATION") != 0) { - error = EFTYPE; - goto failure; - } - - key.data = "VERSION"; - key.size = (strlen("VERSION") + 1); - state = db->get(db, &key, &value, 0); - if (state != 0) { - if (state < 0) - error = errno; - else - error = EFTYPE; - goto failure; - } - ((struct __colldb*)colldb)->version = - ntohl(*(const uint32_t*)value.data); - - ((struct __colldb*)colldb)->handle = db; - return (colldb); - -failure: - (void) db->close(db); - free(colldb); - errno = error; - return (NULL); -} - - -int -__colldb_close(void *colldb) -{ - DB *db = NULL; - int error = 0; - - if (colldb == NULL) { - errno = EINVAL; - return (-1); - } - db = ((struct __colldb*)colldb)->handle; - if (db == NULL) { - errno = EINVAL; - return (-1); - } - if (db->close(db) == -1) { - error = errno; - free(colldb); - errno = error; - return (-1); - } - free(colldb); - return (0); -} - - -int -__colldb_sync(void *colldb) -{ - DB *db = NULL; - - if (colldb == NULL) { - errno = EINVAL; - return (-1); - } - db = ((struct __colldb*)colldb)->handle; - if (db == NULL) { - errno = EINVAL; - return (-1); - } - return db->sync(db, 0); -} - - -int -__colldb_get(void *colldb, - struct __colldb_key *key, - struct __colldb_value *value) -{ - DBT dbkey; - DBT dbvalue; - DB *db = NULL; - size_t i = 0; - int error = 0; - int state = 0; - uint32_t *keybuf = NULL; - struct __colldb_weight *weights = NULL; - - if ((colldb == NULL) || (key == NULL) || (value == NULL)) { - errno = EINVAL; - return (-1); - } - db = ((struct __colldb*)colldb)->handle; - if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) { - errno = EINVAL; - return (-1); - } - - keybuf = malloc(key->count * sizeof(*key->chars)); - if (keybuf == NULL) { - errno = ENOMEM; - return (-1); - } - for (i = 0; i < key->count; ++i) - keybuf[i] = htonl(key->chars[i]); - - dbkey.data = keybuf; - dbkey.size = (key->count * sizeof(*key->chars)); - state = db->get(db, &dbkey, &dbvalue, 0); - if (state != 0) { - error = errno; - free(keybuf); - errno = error; - return (state); - } - - weights = dbvalue.data; - if ((dbvalue.size / sizeof(*weights)) > value->count) { - free(keybuf); - errno = ERANGE; - return (-1); - } - value->count = (dbvalue.size / sizeof(*weights)); - for (i = 0; i < value->count; ++i) { - value->weights[i].alternate = weights[i].alternate; - value->weights[i].level1 = ntohl(weights[i].level1); - value->weights[i].level2 = ntohl(weights[i].level2); - value->weights[i].level3 = ntohl(weights[i].level3); - value->weights[i].level4 = ntohl(weights[i].level4); - } - free(keybuf); - return (0); -} - - -int -__colldb_put(void *colldb, - struct __colldb_key *key, - struct __colldb_value *value) -{ - DBT dbkey; - DBT dbvalue; - DB *db = NULL; - size_t i = 0; - int state = 0; - int error = 0; - uint32_t *keybuf = NULL; - struct __colldb_weight *valuebuf = NULL; - - if ((colldb == NULL) || (key == NULL) || (value == NULL)) { - errno = EINVAL; - return (-1); - } - db = ((struct __colldb*)colldb)->handle; - if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) { - errno = EINVAL; - return (-1); - } - - valuebuf = value->weights; - keybuf = malloc(key->count * sizeof(*key->chars)); - valuebuf = malloc(value->count * sizeof(*value->weights)); - if ((keybuf == NULL) || (valuebuf == NULL)) { - errno = ENOMEM; - return (-1); - } - for (i = 0; i < key->count; ++i) - keybuf[i] = htonl(key->chars[i]); - for (i = 0; i < value->count; ++i) { - valuebuf[i].alternate = value->weights[i].alternate; - valuebuf[i].level1 = htonl(value->weights[i].level1); - valuebuf[i].level2 = htonl(value->weights[i].level2); - valuebuf[i].level3 = htonl(value->weights[i].level3); - valuebuf[i].level4 = htonl(value->weights[i].level4); - } - - dbkey.data = keybuf; - dbvalue.data = valuebuf; - dbkey.size = (key->count * sizeof(*key->chars)); - dbvalue.size = (value->count * sizeof(*value->weights)); - state = db->put(db, &dbkey, &dbvalue, 0); - if (state != 0) { - error = errno; - free(keybuf); - free(valuebuf); - errno = error; - } - return state; -} - - /* * To avoid modifying the original (single-threaded) code too much, we'll just * define the old globals as fields inside the table. Modified: soc2014/ghostmansd/head/lib/libc/locale/xlocale.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/locale/xlocale.c Thu Aug 14 22:23:54 2014 (r272445) +++ soc2014/ghostmansd/head/lib/libc/locale/xlocale.c Thu Aug 14 22:32:43 2014 (r272446) @@ -33,11 +33,15 @@ #include #include #include +#include +#include +#include +#include #include "libc_private.h" #include "xlocale_private.h" -/* Collation Database implementation. */ +/* Collation Database. */ static void *colldb_root_handle = NULL; static pthread_once_t colldb_root_once = PTHREAD_ONCE_INIT; @@ -53,6 +57,284 @@ return (colldb_root_handle); } +struct __colldb { + uint32_t version; + void *handle; +}; + +void * +__colldb_create(const char *path, int mode) +{ + DBT key; + DBT value; + DB *db = NULL; + int error = 0; + void *colldb = NULL; + uint32_t version = 0; + int flags = (O_RDWR | O_CREAT | O_TRUNC); + + colldb = calloc(1, sizeof(struct __colldb)); + if (colldb == NULL) { + errno = ENOMEM; + return (NULL); + } + db = dbopen(path, flags, mode, DB_HASH, NULL); + if (db == NULL) { + error = errno; + free(colldb); + errno = error; + return (NULL); + } + ((struct __colldb*)colldb)->version = __COLLDB_VERSION; + + key.data = "TYPE"; + value.data = "COLLATION"; + key.size = (strlen("TYPE") + 1); + value.size = (strlen("COLLATION") + 1); + if (db->put(db, &key, &value, 0) == -1) { + error = errno; + goto failure; + } + + key.data = "VERSION"; + version = htonl(((struct __colldb*)colldb)->version); + value.data = &version; + key.size = (strlen("VERSION") + 1); + value.size = sizeof(((struct __colldb*)colldb)->version); + if (db->put(db, &key, &value, 0) == -1) { + error = errno; + goto failure; + } + + ((struct __colldb*)colldb)->handle = db; + return (colldb); + +failure: + (void) db->close(db); + free(colldb); + errno = error; + return (NULL); +} + +void * +__colldb_open(const char *path) +{ + DBT key; + DBT value; + DB *db = NULL; + int error = 0; + int state = 0; + void *colldb = NULL; + int flags = O_RDONLY; + + colldb = calloc(1, sizeof(struct __colldb)); + if (colldb == NULL) { + errno = ENOMEM; + return (NULL); + } + db = dbopen(path, flags, 0, DB_HASH, NULL); + if (db == NULL) { + error = errno; + free(colldb); + errno = error; + return (NULL); + } + + key.data = "TYPE"; + key.size = (strlen("TYPE") + 1); + state = db->get(db, &key, &value, 0); + if (state != 0) { + if (state < 0) + error = errno; + else + error = EFTYPE; + goto failure; + } + if (strcmp(value.data, "COLLATION") != 0) { + error = EFTYPE; + goto failure; + } + + key.data = "VERSION"; + key.size = (strlen("VERSION") + 1); + state = db->get(db, &key, &value, 0); + if (state != 0) { + if (state < 0) + error = errno; + else + error = EFTYPE; + goto failure; + } + ((struct __colldb*)colldb)->version = + ntohl(*(const uint32_t*)value.data); + + ((struct __colldb*)colldb)->handle = db; + return (colldb); + +failure: + (void) db->close(db); + free(colldb); + errno = error; + return (NULL); +} + +int +__colldb_close(void *colldb) +{ + DB *db = NULL; + int error = 0; + + if (colldb == NULL) { + errno = EINVAL; + return (-1); + } + db = ((struct __colldb*)colldb)->handle; + if (db == NULL) { + errno = EINVAL; + return (-1); + } + if (db->close(db) == -1) { + error = errno; + free(colldb); + errno = error; + return (-1); + } + free(colldb); + return (0); +} + +int +__colldb_sync(void *colldb) +{ + DB *db = NULL; + + if (colldb == NULL) { + errno = EINVAL; + return (-1); + } + db = ((struct __colldb*)colldb)->handle; + if (db == NULL) { + errno = EINVAL; + return (-1); + } + return db->sync(db, 0); +} + +int +__colldb_get(void *colldb, + struct __colldb_key *key, + struct __colldb_value *value) +{ + DBT dbkey; + DBT dbvalue; + DB *db = NULL; + size_t i = 0; + int error = 0; + int state = 0; + uint32_t *keybuf = NULL; + struct __colldb_weight *weights = NULL; + + if ((colldb == NULL) || (key == NULL) || (value == NULL)) { + errno = EINVAL; + return (-1); + } + db = ((struct __colldb*)colldb)->handle; + if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) { + errno = EINVAL; + return (-1); + } + + keybuf = malloc(key->count * sizeof(*key->chars)); + if (keybuf == NULL) { + errno = ENOMEM; + return (-1); + } + for (i = 0; i < key->count; ++i) + keybuf[i] = htonl(key->chars[i]); + + dbkey.data = keybuf; + dbkey.size = (key->count * sizeof(*key->chars)); + state = db->get(db, &dbkey, &dbvalue, 0); + if (state != 0) { + error = errno; + free(keybuf); + errno = error; + return (state); + } + + weights = dbvalue.data; + if ((dbvalue.size / sizeof(*weights)) > value->count) { + free(keybuf); + errno = ERANGE; + return (-1); + } + value->count = (dbvalue.size / sizeof(*weights)); + for (i = 0; i < value->count; ++i) { + value->weights[i].alternate = weights[i].alternate; + value->weights[i].level1 = ntohl(weights[i].level1); + value->weights[i].level2 = ntohl(weights[i].level2); + value->weights[i].level3 = ntohl(weights[i].level3); + value->weights[i].level4 = ntohl(weights[i].level4); + } + free(keybuf); + return (0); +} + +int +__colldb_put(void *colldb, + struct __colldb_key *key, + struct __colldb_value *value) +{ + DBT dbkey; + DBT dbvalue; + DB *db = NULL; + size_t i = 0; + int state = 0; + int error = 0; + uint32_t *keybuf = NULL; + struct __colldb_weight *valuebuf = NULL; + + if ((colldb == NULL) || (key == NULL) || (value == NULL)) { + errno = EINVAL; + return (-1); + } + db = ((struct __colldb*)colldb)->handle; + if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) { + errno = EINVAL; + return (-1); + } + + valuebuf = value->weights; + keybuf = malloc(key->count * sizeof(*key->chars)); + valuebuf = malloc(value->count * sizeof(*value->weights)); + if ((keybuf == NULL) || (valuebuf == NULL)) { + errno = ENOMEM; + return (-1); + } + for (i = 0; i < key->count; ++i) + keybuf[i] = htonl(key->chars[i]); + for (i = 0; i < value->count; ++i) { + valuebuf[i].alternate = value->weights[i].alternate; + valuebuf[i].level1 = htonl(value->weights[i].level1); + valuebuf[i].level2 = htonl(value->weights[i].level2); + valuebuf[i].level3 = htonl(value->weights[i].level3); + valuebuf[i].level4 = htonl(value->weights[i].level4); + } + + dbkey.data = keybuf; + dbvalue.data = valuebuf; + dbkey.size = (key->count * sizeof(*key->chars)); + dbvalue.size = (value->count * sizeof(*value->weights)); + state = db->put(db, &dbkey, &dbvalue, 0); + if (state != 0) { + error = errno; + free(keybuf); + free(valuebuf); + errno = error; + } + return state; +} + /** * Each locale loader declares a global component. This is used by setlocale() From owner-svn-soc-all@FreeBSD.ORG Fri Aug 15 06:02:36 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 144F12D5 for ; Fri, 15 Aug 2014 06:02:36 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id F405529BA for ; Fri, 15 Aug 2014 06:02:35 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7F62ZDJ047623 for ; Fri, 15 Aug 2014 06:02:35 GMT (envelope-from shonali@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7F62Zcb047485 for svn-soc-all@FreeBSD.org; Fri, 15 Aug 2014 06:02:35 GMT (envelope-from shonali@FreeBSD.org) Date: Fri, 15 Aug 2014 06:02:35 GMT Message-Id: <201408150602.s7F62Zcb047485@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to shonali@FreeBSD.org using -f From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272454 - soc2014/shonali/head/contrib/bsnmp/snmpd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Aug 2014 06:02:36 -0000 Author: shonali Date: Fri Aug 15 06:02:34 2014 New Revision: 272454 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272454 Log: Adding case SNMP_SYNTAX_IP6ADDRESS and ip6_XX function calls Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/action.c Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/action.c ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/action.c Fri Aug 15 04:35:34 2014 (r272453) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/action.c Fri Aug 15 06:02:34 2014 (r272454) @@ -658,6 +658,8 @@ break; case LEAF_begemotSnmpdTrap1Addr: return (ip_get(value, snmpd.trap1addr)); + case LEAF_begemotSnmpdTrap1Addr6: + return (ip6_get(value, snmpd.trap1addr6)); case LEAF_begemotSnmpdVersionEnable: value->v.uint32 = snmpd.version_enable; break; @@ -699,6 +701,9 @@ case LEAF_begemotSnmpdTrap1Addr: return (ip_save(value, ctx, snmpd.trap1addr)); + + case LEAF_begemotSnmpdTrap1Addr6: + return (ip6_save(value, ctx, snmpd.trap1addr6)); case LEAF_begemotSnmpdVersionEnable: if (community != COMM_INITIALIZE) @@ -727,6 +732,9 @@ case LEAF_begemotSnmpdTrap1Addr: ip_rollback(ctx, snmpd.trap1addr); return (SNMP_ERR_NOERROR); + case LEAF_begemotSnmpdTrap1Addr6: + ip6_rollback(ctx, snmpd.trap1addr6); + return (SNMP_ERR_NOERROR); case LEAF_begemotSnmpdVersionEnable: snmpd.version_enable = ctx->scratch->int1; return (SNMP_ERR_NOERROR); @@ -743,6 +751,9 @@ case LEAF_begemotSnmpdTrap1Addr: ip_commit(ctx); return (SNMP_ERR_NOERROR); + case LEAF_begemotSnmpdTrap1Addr6: + ip6_commit(ctx); + return (SNMP_ERR_NOERROR); case LEAF_begemotSnmpdVersionEnable: return (SNMP_ERR_NOERROR); } From owner-svn-soc-all@FreeBSD.ORG Fri Aug 15 06:03:47 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 230F12FC for ; Fri, 15 Aug 2014 06:03:47 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0F0FD29CA for ; Fri, 15 Aug 2014 06:03:47 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7F63kki063527 for ; Fri, 15 Aug 2014 06:03:46 GMT (envelope-from shonali@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7F63kKd063406 for svn-soc-all@FreeBSD.org; Fri, 15 Aug 2014 06:03:46 GMT (envelope-from shonali@FreeBSD.org) Date: Fri, 15 Aug 2014 06:03:46 GMT Message-Id: <201408150603.s7F63kKd063406@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to shonali@FreeBSD.org using -f From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272455 - soc2014/shonali/head/contrib/bsnmp/snmpd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Aug 2014 06:03:47 -0000 Author: shonali Date: Fri Aug 15 06:03:46 2014 New Revision: 272455 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272455 Log: Adding fixes for ipv6 transport Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/trans_udpv6.c Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/trans_udpv6.c ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/trans_udpv6.c Fri Aug 15 06:02:34 2014 (r272454) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/trans_udpv6.c Fri Aug 15 06:03:46 2014 (r272455) @@ -379,7 +379,7 @@ &value->var, sub); ctx->scratch->int1 = (p != NULL); - if (which != LEAF_begemotSnmpdPortStatus) + if (which != LEAF_begemotSnmpdPortv6Status) abort(); if (!TRUTH_OK(value->v.integer)) return (SNMP_ERR_WRONG_VALUE); @@ -436,7 +436,7 @@ */ switch (which) { - case LEAF_begemotSnmpdPortStatus: + case LEAF_begemotSnmpdPortv6Status: value->v.integer = 1; break; From owner-svn-soc-all@FreeBSD.ORG Fri Aug 15 06:21:17 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 648E5722 for ; Fri, 15 Aug 2014 06:21:17 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4FFE12B82 for ; Fri, 15 Aug 2014 06:21:17 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7F6LHom002187 for ; Fri, 15 Aug 2014 06:21:17 GMT (envelope-from shonali@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7F6LGk5001881 for svn-soc-all@FreeBSD.org; Fri, 15 Aug 2014 06:21:16 GMT (envelope-from shonali@FreeBSD.org) Date: Fri, 15 Aug 2014 06:21:16 GMT Message-Id: <201408150621.s7F6LGk5001881@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to shonali@FreeBSD.org using -f From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272456 - soc2014/shonali/head/contrib/bsnmp/snmpd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Aug 2014 06:21:17 -0000 Author: shonali Date: Fri Aug 15 06:21:15 2014 New Revision: 272456 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272456 Log: Added separate begemotTrapSinkv6Table to BEGEMOT-SNMPD.txt, snmpd.config & tree.def Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/BEGEMOT-SNMPD.txt soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.config soc2014/shonali/head/contrib/bsnmp/snmpd/tree.def Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/BEGEMOT-SNMPD.txt ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/BEGEMOT-SNMPD.txt Fri Aug 15 06:03:46 2014 (r272455) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/BEGEMOT-SNMPD.txt Fri Aug 15 06:21:15 2014 (r272456) @@ -125,11 +125,11 @@ ::= { begemotSnmpdConfig 3 } begemotSnmpdTrap1Addr OBJECT-TYPE - SYNTAX IpAddress + SYNTAX InetAddressIPv4 MAX-ACCESS read-write STATUS current DESCRIPTION - "The trap sink for v1 traps." + "The IPv4 trap sink for v1 traps." ::= { begemotSnmpdConfig 4 } begemotSnmpdVersionEnable OBJECT-TYPE @@ -146,8 +146,16 @@ DEFVAL { 3 } ::= { begemotSnmpdConfig 5 } +begemotSnmpdTrap1Addr6 OBJECT-TYPE + SYNTAX InetAddressIPv6 + MAX-ACCESS read-write + STATUS current + DESCRIPTION + "The IPv6 trap sink for v1 traps." + ::= { begemotSnmpdConfig 6 } + -- --- Trap destinations +-- IPv4 Trap destinations -- begemotTrapSinkTable OBJECT-TYPE SYNTAX SEQUENCE OF BegemotTrapSinkEntry @@ -168,17 +176,17 @@ ::= { begemotTrapSinkTable 1 } BegemotTrapSinkEntry ::= SEQUENCE { - begemotTrapSinkAddr IpAddress, + begemotTrapSinkAddr InetAddressIPv4, begemotTrapSinkPort INTEGER, begemotTrapSinkStatus RowStatus } begemotTrapSinkAddr OBJECT-TYPE - SYNTAX IpAddress + SYNTAX InetAddressIPv4 MAX-ACCESS not-accessible STATUS current DESCRIPTION - "Destination IP address of the manager station where to send + "Destination IPv4 address of the manager station where to send traps." ::= { begemotTrapSinkEntry 1 } @@ -622,4 +630,57 @@ "Set status to 1 to create entry, set it to 2 to delete it." ::= { begemotSnmpdPortv6Entry 3 } +-- +-- IPv6 Trap destinations +-- +begemotTrapSinkv6Table OBJECT-TYPE + SYNTAX SEQUENCE OF BegemotTrapSinkv6Entry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A table with destinations for standard traps." + INDEX { begemotTrapSinkv6Addr, begemotTrapSinkv6Port } + ::= { begemotSnmpdObjects 12 } + +begemotTrapSinkv6Entry OBJECT-TYPE + SYNTAX BegemotTrapSinkv6Entry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Entry describes one trap destination." + INDEX { begemotTrapSinkv6Addr, begemotTrapSinkv6Port } + ::= { begemotTrapSinkv6Table 1 } + +BegemotTrapSinkv6Entry ::= SEQUENCE { + begemotTrapSinkv6Addr InetAddressIPv6, + begemotTrapSinkv6Port INTEGER, + begemotTrapSinkv6Status RowStatus +} + +begemotTrapSinkv6Addr OBJECT-TYPE + SYNTAX InetAddressIPv6 + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Destination IPv6 address of the manager station where to send + traps." + ::= { begemotTrapSinkv6Entry 1 } + +begemotTrapSinkv6Port OBJECT-TYPE + SYNTAX INTEGER (1..65535) + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Destination UDP port of the manager station where to send + traps." + ::= { begemotTrapSinkv6Entry 2 } + +begemotTrapSinkv6Status OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "Used to create/activate/destroy the entry." + ::= { begemotTrapSinkv6Entry 3 } + END Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.config ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.config Fri Aug 15 06:03:46 2014 (r272455) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.config Fri Aug 15 06:21:15 2014 (r272456) @@ -84,6 +84,9 @@ begemotTrapSinkStatus.[$(traphost)].$(trapport) = 4 begemotTrapSinkVersion.[$(traphost)].$(trapport) = 2 begemotTrapSinkComm.[$(traphost)].$(trapport) = $(trap) +begemotTrapSinkv6Status.[$(traphost)].$(trapport) = 4 +begemotTrapSinkv6Version.[$(traphost)].$(trapport) = 2 +begemotTrapSinkv6Comm.[$(traphost)].$(trapport) = $(trap) sysContact = $(contact) sysLocation = $(location) Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/tree.def ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/tree.def Fri Aug 15 06:03:46 2014 (r272455) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/tree.def Fri Aug 15 06:21:15 2014 (r272456) @@ -114,12 +114,13 @@ (1 begemotSnmpdTransmitBuffer INTEGER op_snmpd_config GET SET) (2 begemotSnmpdReceiveBuffer INTEGER op_snmpd_config GET SET) (3 begemotSnmpdCommunityDisable INTEGER op_snmpd_config GET SET) - (4 begemotSnmpdTrap1Addr IPADDRESS op_snmpd_config GET SET) + (4 begemotSnmpdTrap1Addr OCTETSTRING | InetAddressIPv4 op_snmpd_config GET SET) (5 begemotSnmpdVersionEnable UNSIGNED32 op_snmpd_config GET SET) + (6 begemotSnmpdTrap1Addr6 OCTETSTRING | InetAddressIPv6 op_snmpd_config GET SET) ) (2 begemotTrapSinkTable - (1 begemotTrapSinkEntry : IPADDRESS INTEGER op_trapsink - (1 begemotTrapSinkAddr IPADDRESS) + (1 begemotTrapSinkEntry : OCTETSTRING | InetAddressIPv4 INTEGER op_trapsink + (1 begemotTrapSinkAddr OCTETSTRING | InetAddressIPv4) (2 begemotTrapSinkPort INTEGER) (3 begemotTrapSinkStatus INTEGER GET SET) (4 begemotTrapSinkComm OCTETSTRING GET SET) @@ -198,6 +199,15 @@ (2 begemotSnmpdPortv6Port UNSIGNED32) (3 begemotSnmpdPortv6Status INTEGER GET SET) )) + + (12 begemotTrapSinkv6Table + (1 begemotTrapSinkv6Entry : OCTETSTRING | InetAddressIPv6 INTEGER op_trapsink + (1 begemotTrapSinkv6Addr OCTETSTRING | InetAddressIPv6) + (2 begemotTrapSinkv6Port INTEGER) + (3 begemotTrapSinkv6Status INTEGER GET SET) + (4 begemotTrapSinkv6Comm OCTETSTRING GET SET) + (5 begemotTrapSinkv6Version INTEGER GET SET) + )) ) (2 begemotSnmpdDefs (1 begemotSnmpdAgent From owner-svn-soc-all@FreeBSD.ORG Fri Aug 15 16:43:45 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C0E04A29 for ; Fri, 15 Aug 2014 16:43:45 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id ACC3728CD for ; Fri, 15 Aug 2014 16:43:45 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7FGhjl1026278 for ; Fri, 15 Aug 2014 16:43:45 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7FGhjpa026276 for svn-soc-all@FreeBSD.org; Fri, 15 Aug 2014 16:43:45 GMT (envelope-from dpl@FreeBSD.org) Date: Fri, 15 Aug 2014 16:43:45 GMT Message-Id: <201408151643.s7FGhjpa026276@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272471 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Aug 2014 16:43:45 -0000 Author: dpl Date: Fri Aug 15 16:43:44 2014 New Revision: 272471 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272471 Log: Added a crfree() prototype, used by the compiled code. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Fri Aug 15 15:42:58 2014 (r272470) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Fri Aug 15 16:43:44 2014 (r272471) @@ -60,6 +60,7 @@ // Functions used by JIT, external. int printf(const char * restrict format, ...); int ipfw_find_rule(struct ip_fw_chain *chain, uint32_t key, uint32_t id); +void crfree(struct ucred *); static VNET_DEFINE(int, fw_deny_unknown_exthdrs); #define V_fw_deny_unknown_exthdrs VNET(fw_deny_unknown_exthdrs) From owner-svn-soc-all@FreeBSD.ORG Fri Aug 15 17:51:28 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 66F83CD6 for ; Fri, 15 Aug 2014 17:51:28 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5221A229C for ; Fri, 15 Aug 2014 17:51:28 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7FHpSt3068079 for ; Fri, 15 Aug 2014 17:51:28 GMT (envelope-from shonali@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7FHpRjI067829 for svn-soc-all@FreeBSD.org; Fri, 15 Aug 2014 17:51:27 GMT (envelope-from shonali@FreeBSD.org) Date: Fri, 15 Aug 2014 17:51:27 GMT Message-Id: <201408151751.s7FHpRjI067829@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to shonali@FreeBSD.org using -f From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272473 - soc2014/shonali/head/contrib/bsnmp/snmpd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Aug 2014 17:51:28 -0000 Author: shonali Date: Fri Aug 15 17:51:26 2014 New Revision: 272473 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272473 Log: Switched back to the single begemotTrapSinkTable approach Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/BEGEMOT-SNMPD.txt soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.config soc2014/shonali/head/contrib/bsnmp/snmpd/tree.def Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/BEGEMOT-SNMPD.txt ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/BEGEMOT-SNMPD.txt Fri Aug 15 16:08:52 2014 (r272472) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/BEGEMOT-SNMPD.txt Fri Aug 15 17:51:26 2014 (r272473) @@ -155,7 +155,7 @@ ::= { begemotSnmpdConfig 6 } -- --- IPv4 Trap destinations +-- Trap destinations -- begemotTrapSinkTable OBJECT-TYPE SYNTAX SEQUENCE OF BegemotTrapSinkEntry @@ -163,7 +163,7 @@ STATUS current DESCRIPTION "A table with destinations for standard traps." - INDEX { begemotTrapSinkAddr, begemotTrapSinkPort } + INDEX { begemotTrapSinkAddrType begemotTrapSinkAddr, begemotTrapSinkPort } ::= { begemotSnmpdObjects 2 } begemotTrapSinkEntry OBJECT-TYPE @@ -172,24 +172,33 @@ STATUS current DESCRIPTION "Entry describes one trap destination." - INDEX { begemotTrapSinkAddr, begemotTrapSinkPort } + INDEX { begemotTrapSinkAddrType begemotTrapSinkAddr, begemotTrapSinkPort } ::= { begemotTrapSinkTable 1 } BegemotTrapSinkEntry ::= SEQUENCE { - begemotTrapSinkAddr InetAddressIPv4, + begemotTrapSinkAddr InetAddress, + begemotTrapSinkAddrType InetAddressType begemotTrapSinkPort INTEGER, begemotTrapSinkStatus RowStatus } begemotTrapSinkAddr OBJECT-TYPE - SYNTAX InetAddressIPv4 + SYNTAX InetAddress MAX-ACCESS not-accessible STATUS current DESCRIPTION - "Destination IPv4 address of the manager station where to send + "Destination IP address of the manager station where to send traps." ::= { begemotTrapSinkEntry 1 } +begemotTrapSinkAddrType OBJECT-TYPE + SYNTAX InetAddressType + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "The address type of the manager station where to send traps." + ::= { begemotTrapSinkEntry 4 } + begemotTrapSinkPort OBJECT-TYPE SYNTAX INTEGER (1..65535) MAX-ACCESS not-accessible @@ -630,57 +639,4 @@ "Set status to 1 to create entry, set it to 2 to delete it." ::= { begemotSnmpdPortv6Entry 3 } --- --- IPv6 Trap destinations --- -begemotTrapSinkv6Table OBJECT-TYPE - SYNTAX SEQUENCE OF BegemotTrapSinkv6Entry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table with destinations for standard traps." - INDEX { begemotTrapSinkv6Addr, begemotTrapSinkv6Port } - ::= { begemotSnmpdObjects 12 } - -begemotTrapSinkv6Entry OBJECT-TYPE - SYNTAX BegemotTrapSinkv6Entry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Entry describes one trap destination." - INDEX { begemotTrapSinkv6Addr, begemotTrapSinkv6Port } - ::= { begemotTrapSinkv6Table 1 } - -BegemotTrapSinkv6Entry ::= SEQUENCE { - begemotTrapSinkv6Addr InetAddressIPv6, - begemotTrapSinkv6Port INTEGER, - begemotTrapSinkv6Status RowStatus -} - -begemotTrapSinkv6Addr OBJECT-TYPE - SYNTAX InetAddressIPv6 - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Destination IPv6 address of the manager station where to send - traps." - ::= { begemotTrapSinkv6Entry 1 } - -begemotTrapSinkv6Port OBJECT-TYPE - SYNTAX INTEGER (1..65535) - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Destination UDP port of the manager station where to send - traps." - ::= { begemotTrapSinkv6Entry 2 } - -begemotTrapSinkv6Status OBJECT-TYPE - SYNTAX RowStatus - MAX-ACCESS read-create - STATUS current - DESCRIPTION - "Used to create/activate/destroy the entry." - ::= { begemotTrapSinkv6Entry 3 } - END Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.config ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.config Fri Aug 15 16:08:52 2014 (r272472) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.config Fri Aug 15 17:51:26 2014 (r272473) @@ -84,9 +84,7 @@ begemotTrapSinkStatus.[$(traphost)].$(trapport) = 4 begemotTrapSinkVersion.[$(traphost)].$(trapport) = 2 begemotTrapSinkComm.[$(traphost)].$(trapport) = $(trap) -begemotTrapSinkv6Status.[$(traphost)].$(trapport) = 4 -begemotTrapSinkv6Version.[$(traphost)].$(trapport) = 2 -begemotTrapSinkv6Comm.[$(traphost)].$(trapport) = $(trap) +begemotTrapSinkAddrType.[$(traphost)].$(trapport) = 2 sysContact = $(contact) sysLocation = $(location) Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/tree.def ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/tree.def Fri Aug 15 16:08:52 2014 (r272472) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/tree.def Fri Aug 15 17:51:26 2014 (r272473) @@ -119,12 +119,13 @@ (6 begemotSnmpdTrap1Addr6 OCTETSTRING | InetAddressIPv6 op_snmpd_config GET SET) ) (2 begemotTrapSinkTable - (1 begemotTrapSinkEntry : OCTETSTRING | InetAddressIPv4 INTEGER op_trapsink - (1 begemotTrapSinkAddr OCTETSTRING | InetAddressIPv4) + (1 begemotTrapSinkEntry : InetAddressType OCTETSTRING | InetAddress INTEGER op_trapsink + (1 begemotTrapSinkAddr OCTETSTRING | InetAddress) (2 begemotTrapSinkPort INTEGER) (3 begemotTrapSinkStatus INTEGER GET SET) (4 begemotTrapSinkComm OCTETSTRING GET SET) (5 begemotTrapSinkVersion INTEGER GET SET) + (6 begemotTrapSinkAddrType InetAddressType GET SET) ) ) # @@ -199,15 +200,6 @@ (2 begemotSnmpdPortv6Port UNSIGNED32) (3 begemotSnmpdPortv6Status INTEGER GET SET) )) - - (12 begemotTrapSinkv6Table - (1 begemotTrapSinkv6Entry : OCTETSTRING | InetAddressIPv6 INTEGER op_trapsink - (1 begemotTrapSinkv6Addr OCTETSTRING | InetAddressIPv6) - (2 begemotTrapSinkv6Port INTEGER) - (3 begemotTrapSinkv6Status INTEGER GET SET) - (4 begemotTrapSinkv6Comm OCTETSTRING GET SET) - (5 begemotTrapSinkv6Version INTEGER GET SET) - )) ) (2 begemotSnmpdDefs (1 begemotSnmpdAgent From owner-svn-soc-all@FreeBSD.ORG Fri Aug 15 17:55:13 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id DC2FE11B for ; Fri, 15 Aug 2014 17:55:13 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C7BE023F4 for ; Fri, 15 Aug 2014 17:55:13 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7FHtDpT090351 for ; Fri, 15 Aug 2014 17:55:13 GMT (envelope-from dpl@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7FHtD6M090348 for svn-soc-all@FreeBSD.org; Fri, 15 Aug 2014 17:55:13 GMT (envelope-from dpl@FreeBSD.org) Date: Fri, 15 Aug 2014 17:55:13 GMT Message-Id: <201408151755.s7FHtD6M090348@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to dpl@FreeBSD.org using -f From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272474 - soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Aug 2014 17:55:13 -0000 Author: dpl Date: Fri Aug 15 17:55:12 2014 New Revision: 272474 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272474 Log: Corrected struct type used. Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Modified: soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h ============================================================================== --- soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Fri Aug 15 17:51:26 2014 (r272473) +++ soc2014/dpl/netmap-ipfwjit/sys/netpfil/ipfw/ip_fw_rules.h Fri Aug 15 17:55:12 2014 (r272474) @@ -47,7 +47,7 @@ struct ip_fw_args; struct ip_fw_chain; struct ip_fw; -struct ipfw_insn; +struct _ipfw_insn; struct _ipfw_insn_if; struct _ipfw_dyn_rule; From owner-svn-soc-all@FreeBSD.ORG Fri Aug 15 19:26:53 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 177B3171 for ; Fri, 15 Aug 2014 19:26:53 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EB69D2EEF for ; Fri, 15 Aug 2014 19:26:52 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7FJQqZb077809 for ; Fri, 15 Aug 2014 19:26:52 GMT (envelope-from shonali@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7FJQpE2077802 for svn-soc-all@FreeBSD.org; Fri, 15 Aug 2014 19:26:51 GMT (envelope-from shonali@FreeBSD.org) Date: Fri, 15 Aug 2014 19:26:51 GMT Message-Id: <201408151926.s7FJQpE2077802@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to shonali@FreeBSD.org using -f From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272475 - in soc2014/shonali/head/contrib/bsnmp: lib snmpd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Aug 2014 19:26:53 -0000 Author: shonali Date: Fri Aug 15 19:26:50 2014 New Revision: 272475 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272475 Log: Fixes for trap and trap related function calls Modified: soc2014/shonali/head/contrib/bsnmp/lib/snmp.h soc2014/shonali/head/contrib/bsnmp/snmpd/main.c soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.h soc2014/shonali/head/contrib/bsnmp/snmpd/snmpmod.h soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c Modified: soc2014/shonali/head/contrib/bsnmp/lib/snmp.h ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/lib/snmp.h Fri Aug 15 17:55:12 2014 (r272474) +++ soc2014/shonali/head/contrib/bsnmp/lib/snmp.h Fri Aug 15 19:26:50 2014 (r272475) @@ -173,6 +173,7 @@ /* trap only */ struct asn_oid enterprise; u_char agent_addr[4]; + u_char agent_addr6[16]; int32_t generic_trap; int32_t specific_trap; uint32_t time_stamp; Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/main.c ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/main.c Fri Aug 15 17:55:12 2014 (r272474) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/main.c Fri Aug 15 19:26:50 2014 (r272475) @@ -372,7 +372,7 @@ * on the user credentials against the configured User groups & VACM views. */ enum snmp_code -snmp_pdu_auth_access(struct snmp_pdu *pdu, int32_t *ip) +snmp_pdu_auth_access(struct snmp_pdu *pdu, int8_t *ip) { const char *uname; int32_t suboid, smodel; Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.h ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.h Fri Aug 15 17:55:12 2014 (r272474) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.h Fri Aug 15 19:26:50 2014 (r272475) @@ -315,6 +315,7 @@ int socket; u_char comm[SNMP_COMMUNITY_MAXLEN]; int version; + int addrtype; }; enum { TRAPSINK_ACTIVE = 1, @@ -324,6 +325,9 @@ TRAPSINK_V1 = 1, TRAPSINK_V2 = 2, + + TRAPSINK_IPv4 = 1, + TRAPSINK_IPv6 = 2, }; TAILQ_HEAD(trapsink_list, trapsink); extern struct trapsink_list trapsink_list; Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/snmpmod.h ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/snmpmod.h Fri Aug 15 17:55:12 2014 (r272474) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/snmpmod.h Fri Aug 15 19:26:50 2014 (r272475) @@ -599,7 +599,7 @@ void snmp_output(struct snmp_pdu *, u_char *, size_t *, const char *); void snmp_send_port(void *, const struct asn_oid *, struct snmp_pdu *, const struct sockaddr *, socklen_t); -enum snmp_code snmp_pdu_auth_access(struct snmp_pdu *, int32_t *); +enum snmp_code snmp_pdu_auth_access(struct snmp_pdu *, int8_t *); /* sending traps */ void snmp_send_trap(const struct asn_oid *, ...); @@ -619,6 +619,11 @@ void ip_commit(struct snmp_context *); int ip_get(struct snmp_value *, u_char *); +int ip6_save(struct snmp_value *, struct snmp_context *, u_char *); +void ip6_rollback(struct snmp_context *, u_char *); +void ip6_commit(struct snmp_context *); +int ip6_get(struct snmp_value *, u_char *); + int oid_save(struct snmp_value *, struct snmp_context *, struct asn_oid *); void oid_rollback(struct snmp_context *, struct asn_oid *); void oid_commit(struct snmp_context *); Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c Fri Aug 15 17:55:12 2014 (r272474) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c Fri Aug 15 19:26:50 2014 (r272475) @@ -57,8 +57,6 @@ #include "tree.h" #include "oid.h" -#define RowStatus_active 1 - struct trapsink_list trapsink_list = TAILQ_HEAD_INITIALIZER(trapsink_list); @@ -87,15 +85,18 @@ u_int status; u_char comm[SNMP_COMMUNITY_MAXLEN + 1]; u_int version; + u_int addrtype; u_int rb; u_int rb_status; u_int rb_version; + u_int rb_addrtype; u_char rb_comm[SNMP_COMMUNITY_MAXLEN + 1]; }; enum { TDEP_STATUS = 0x0001, TDEP_COMM = 0x0002, TDEP_VERSION = 0x0004, + TDEP_ADDRTYPE = 0x0004, TDEP_CREATE = 0x0001, TDEP_MODIFY = 0x0002, @@ -176,8 +177,6 @@ (void)close(t->socket); free(t); } - - } static void trapsink_create_sockv6(struct trapsink *t) @@ -201,9 +200,6 @@ (void)close(t->socket); free(t); } - - - } static void @@ -220,6 +216,7 @@ { tdep->rb_status = t->status; tdep->rb_version = t->version; + tdep->rb_addrtype = t->addrtype; strcpy(tdep->rb_comm, t->comm); if (tdep->set & TDEP_STATUS) { @@ -233,6 +230,8 @@ if (tdep->set & TDEP_VERSION) t->version = tdep->version; + if (tdep->set & TDEP_ADDRTYPE) + t->addrtype = tdep->addrtype; if (tdep->set & TDEP_COMM) strcpy(t->comm, tdep->comm); @@ -242,6 +241,7 @@ if (t->comm[0] == '\0') { t->status = tdep->rb_status; t->version = tdep->rb_version; + t->addrtype = tdep->rb_addrtype; strcpy(t->comm, tdep->rb_comm); return (SNMP_ERR_INCONS_VALUE); } @@ -259,6 +259,8 @@ t->status = tdep->rb_status; if (tdep->set & TDEP_VERSION) t->version = tdep->rb_version; + if (tdep->set & TDEP_ADDRTYPE) + t->addrtype = tdep->rb_addrtype; if (tdep->set & TDEP_COMM) strcpy(t->comm, tdep->rb_comm); @@ -436,6 +438,16 @@ tdep->version = value->v.integer; tdep->set |= TDEP_VERSION; return (SNMP_ERR_NOERROR); + + case LEAF_begemotTrapSinkAddrType: + if (tdep->set & TDEP_ADDRTYPE) + return (SNMP_ERR_INCONS_VALUE); + if (value->v.integer != TRAPSINK_IPv4 && + value->v.integer != TRAPSINK_IPv6) + return (SNMP_ERR_WRONG_VALUE); + tdep->addrtype = value->v.integer; + tdep->set |= TDEP_ADDRTYPE; + return (SNMP_ERR_NOERROR); } if (t == NULL) return (SNMP_ERR_INCONS_NAME); @@ -461,6 +473,10 @@ value->v.integer = t->version; break; + case LEAF_begemotTrapSinkAddrType: + value->v.integer = t->addrtype; + break; + } return (SNMP_ERR_NOERROR); } @@ -483,6 +499,23 @@ } static void +snmp_create_v1_trapv6(struct snmp_pdu *pdu, char *com, + const struct asn_oid *trap_oid) +{ + memset(pdu, 0, sizeof(*pdu)); + strcpy(pdu->community, com); + + pdu->version = SNMP_V1; + pdu->type = SNMP_PDU_TRAP; + pdu->enterprise = systemg.object_id; + memcpy(pdu->agent_addr6, snmpd.trap1addr6, 16); + pdu->generic_trap = trap_oid->subs[trap_oid->len - 1] - 1; + pdu->specific_trap = 0; + pdu->time_stamp = get_ticks() - start_tick; + pdu->nbindings = 0; +} + +static void snmp_create_v2_trap(struct snmp_pdu *pdu, char *com, const struct asn_oid *trap_oid) { @@ -589,14 +622,18 @@ char *tag; size_t sndlen; ssize_t len; - int32_t ip; + int8_t ip[16]; TAILQ_FOREACH(t, &trapsink_list, link) { if (t->status != TRAPSINK_ACTIVE) continue; - if (t->version == TRAPSINK_V1) - snmp_create_v1_trap(&pdu, t->comm, trap_oid); + if (t->version == TRAPSINK_V1) { + if (t->addrtype == TRAPSINK_IPv4) + snmp_create_v1_trap(&pdu, t->comm, trap_oid); + else if (t->addrtype == TRAPSINK_IPv6) + snmp_create_v1_trapv6(&pdu, t->comm, trap_oid); + } else snmp_create_v2_trap(&pdu, t->comm, trap_oid); @@ -652,7 +689,10 @@ switch (tp->mpmodel) { case SNMP_MPM_SNMP_V1: - snmp_create_v1_trap(&pdu, tp->secname, trap_oid); + if (t->addrtype == TRAPSINK_IPv4) + snmp_create_v1_trap(&pdu, tp->secname, trap_oid); + else if (t->addrtype == TRAPSINK_IPv6) + snmp_create_v1_trapv6(&pdu, tp->secname, trap_oid); break; case SNMP_MPM_SNMP_V2c: From owner-svn-soc-all@FreeBSD.ORG Sat Aug 16 10:47:58 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 37634452 for ; Sat, 16 Aug 2014 10:47:58 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 224C72B45 for ; Sat, 16 Aug 2014 10:47:58 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7GAlwX0089700 for ; Sat, 16 Aug 2014 10:47:58 GMT (envelope-from shonali@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7GAlvJ9089685 for svn-soc-all@FreeBSD.org; Sat, 16 Aug 2014 10:47:57 GMT (envelope-from shonali@FreeBSD.org) Date: Sat, 16 Aug 2014 10:47:57 GMT Message-Id: <201408161047.s7GAlvJ9089685@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to shonali@FreeBSD.org using -f From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272491 - soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 16 Aug 2014 10:47:58 -0000 Author: shonali Date: Sat Aug 16 10:47:56 2014 New Revision: 272491 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272491 Log: Fixes for bsnmptools Modified: soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpmap.c soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Modified: soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c ============================================================================== --- soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c Sat Aug 16 08:38:53 2014 (r272490) +++ soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpimport.c Sat Aug 16 10:47:56 2014 (r272491) @@ -289,6 +289,7 @@ { "UNSIGNED32", TOK_TYPE, SNMP_SYNTAX_GAUGE }, { "OCTETSTRING", TOK_TYPE, SNMP_SYNTAX_OCTETSTRING }, { "IPADDRESS", TOK_TYPE, SNMP_SYNTAX_IPADDRESS }, + { "INETADDRESS", TOK_TYPE, SNMP_SYNTAX_IP6ADDRESS }, { "OID", TOK_TYPE, SNMP_SYNTAX_OID }, { "TIMETICKS", TOK_TYPE, SNMP_SYNTAX_TIMETICKS }, { "COUNTER", TOK_TYPE, SNMP_SYNTAX_COUNTER }, Modified: soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpmap.c ============================================================================== --- soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpmap.c Sat Aug 16 08:38:53 2014 (r272490) +++ soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmpmap.c Sat Aug 16 10:47:56 2014 (r272491) @@ -451,6 +451,8 @@ return (snmp_oid_insert(snmptoolctx, entry)); case SNMP_SYNTAX_IPADDRESS: return (snmp_ip_insert(snmptoolctx, entry)); + case SNMP_SYNTAX_IP6ADDRESS: + return (snmp_ip_insert(snmptoolctx, entry)); case SNMP_SYNTAX_COUNTER: return (snmp_cnt_insert(snmptoolctx, entry)); case SNMP_SYNTAX_GAUGE: @@ -779,6 +781,8 @@ return (snmp_lookup_leaf(&snmptoolctx->snmp_oidlist, s)); case SNMP_SYNTAX_IPADDRESS: return (snmp_lookup_leaf(&snmptoolctx->snmp_iplist, s)); + case SNMP_SYNTAX_IP6ADDRESS: + return (snmp_lookup_leaf(&snmptoolctx->snmp_iplist, s)); case SNMP_SYNTAX_COUNTER: return (snmp_lookup_leaf(&snmptoolctx->snmp_cntlist, s)); case SNMP_SYNTAX_GAUGE: @@ -994,6 +998,9 @@ case SNMP_SYNTAX_IPADDRESS: return (snmp_lookup_oidlist(&snmptoolctx->snmp_iplist, s, oid)); + case SNMP_SYNTAX_IP6ADDRESS: + return (snmp_lookup_oidlist(&snmptoolctx->snmp_iplist, + s, oid)); case SNMP_SYNTAX_COUNTER: return (snmp_lookup_oidlist(&snmptoolctx->snmp_cntlist, s, oid)); Modified: soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c ============================================================================== --- soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Sat Aug 16 08:38:53 2014 (r272490) +++ soc2014/shonali/head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptools.c Sat Aug 16 10:47:56 2014 (r272491) @@ -113,10 +113,10 @@ { "OctetString", SNMP_SYNTAX_OCTETSTRING }, { "OID", SNMP_SYNTAX_OID }, { "IpAddress", SNMP_SYNTAX_IPADDRESS }, + { "InetAddress", SNMP_SYNTAX_IP6ADDRESS }, { "Counter32", SNMP_SYNTAX_COUNTER }, { "Gauge", SNMP_SYNTAX_GAUGE }, { "TimeTicks", SNMP_SYNTAX_TIMETICKS }, - { "IPv6Address", SNMP_SYNTAX_IP6ADDRESS }, { "Counter64", SNMP_SYNTAX_COUNTER64 }, { "Unknown", SNMP_SYNTAX_UNKNOWN }, }; @@ -1775,7 +1775,7 @@ if (GET_OUTPUT(snmptoolctx) == OUTPUT_VERBOSE) fprintf(stdout, "%s : ", syntax_strings[SNMP_SYNTAX_IP6ADDRESS].str); - fprintf(stdout, "%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u.%u", + fprintf(stdout, "%u%u:%u%u:%u%u:%u%u:%u%u:%u%u:%u%u:%u%u", ip[0], ip[1], ip[2], ip[3], ip[4], ip[5], ip[6], ip[7], ip[8], ip[9], ip[10], ip[11], ip[12], ip[13], ip[14], ip[15]); } From owner-svn-soc-all@FreeBSD.ORG Sat Aug 16 11:05:48 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4EAB971A for ; Sat, 16 Aug 2014 11:05:48 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3975E2D4D for ; Sat, 16 Aug 2014 11:05:48 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7GB5m0O035371 for ; Sat, 16 Aug 2014 11:05:48 GMT (envelope-from seiya@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7GB5lte035367 for svn-soc-all@FreeBSD.org; Sat, 16 Aug 2014 11:05:47 GMT (envelope-from seiya@FreeBSD.org) Date: Sat, 16 Aug 2014 11:05:47 GMT Message-Id: <201408161105.s7GB5lte035367@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to seiya@FreeBSD.org using -f From: seiya@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272493 - in soc2014/seiya/bootsplash: etc sys/boot/forth sys/dev/fb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 16 Aug 2014 11:05:48 -0000 Author: seiya Date: Sat Aug 16 11:05:46 2014 New Revision: 272493 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272493 Log: scrub code Modified: soc2014/seiya/bootsplash/etc/rc soc2014/seiya/bootsplash/sys/boot/forth/loader.conf soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c Modified: soc2014/seiya/bootsplash/etc/rc ============================================================================== --- soc2014/seiya/bootsplash/etc/rc Sat Aug 16 10:47:24 2014 (r272492) +++ soc2014/seiya/bootsplash/etc/rc Sat Aug 16 11:05:46 2014 (r272493) @@ -126,13 +126,13 @@ files=`rcorder ${skip} ${skip_firstboot} /etc/rc.d/* ${local_rc} 2>/dev/null` files_num=`echo "$files" | wc -l` files_num_per_10=`expr $files_num / 10` # FIXME +boot_progress=0 i=0 -BOOT_PROGRESS=0 for _rc_elem in ${files}; do i=`expr $i + 1` if [ $files_num_per_10 -eq $i ]; then - BOOT_PROGRESS=`expr $BOOT_PROGRESS + 10` - kenv BOOT_PROGRESS=$BOOT_PROGRESS > /dev/null + boot_progress=`expr $boot_progress + 10` + kenv boot_progress=$boot_progress > /dev/null i=0 fi @@ -153,7 +153,7 @@ fi # terminate boot splash -kenv BOOT_PROGRESS=100 > /dev/null +kenv boot_progress=100 > /dev/null echo '' date Modified: soc2014/seiya/bootsplash/sys/boot/forth/loader.conf ============================================================================== --- soc2014/seiya/bootsplash/sys/boot/forth/loader.conf Sat Aug 16 10:47:24 2014 (r272492) +++ soc2014/seiya/bootsplash/sys/boot/forth/loader.conf Sat Aug 16 11:05:46 2014 (r272493) @@ -40,7 +40,7 @@ bsplash_load="NO" # Set this to YES to enable enhanced bootsplash! bsplash_image_load="NO" bsplash_image_type="bsplash_image" - +boot_progress="0" ############################################################## ### Random number generator configuration ################### Modified: soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c ============================================================================== --- soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c Sat Aug 16 10:47:24 2014 (r272492) +++ soc2014/seiya/bootsplash/sys/dev/fb/bsplash.c Sat Aug 16 11:05:46 2014 (r272493) @@ -49,7 +49,7 @@ static int bsplash_init (void); static void bsplash_exit (void); -static void update_animation(void *unused); +static void update_animation_thread(void *unused); static int load_bmp(BMP_INFO *bmp, void* data); static int draw_bmp(BMP_INFO *bmp, int iy, int sy, int sx, int width, int height); @@ -76,7 +76,9 @@ bsplash_stop = _bsplash_stop; } - +/* + * Displays a prompt screen. Note that characters are not echoed. + */ int bsplash_prompt_user(const char *tag) { @@ -103,6 +105,9 @@ } +/* + * Displays a failure screen for a few seconds + */ int bsplash_prompt_failure(const char *tag) { @@ -120,13 +125,15 @@ return 1; } - /* display a failure screen for a few seconds */ pause("bsplash", 2*hz); return 0; } +/* + * Clears prompt screen and displays boot splash screen. + */ int bsplash_prompt_success(const char *tag) { @@ -150,6 +157,7 @@ } } + static int bsplash_init(void) { @@ -256,63 +264,86 @@ return 1; } - if (kthread_add(update_animation, NULL, NULL, NULL, 0, 0, "bsplash") != 0){ + if (kthread_add(update_animation_thread, NULL, NULL, NULL, 0, 0, "bsplash") != 0){ bsplash_exit(); - printf("bsplash: failed to start kernel thread 'update_animation()'\n"); + printf("bsplash: failed to start kernel thread 'update_animation_thread()'\n"); return 1; } return 0; } + static void -update_animation(void *unused) +update_animation (int *iy) { - static int count = 0; - static int iy; - char *s; - int progress = 0; - int stop_animation = 0; + static int stop = 0; - iy = animation_y_origin; - for (;;){ - // update animation - if(!in_prompt){ - if(!stop_animation){ - if (draw_bmp(&bmp_info, iy, animation_y, animation_x, - animation_width, animation_height) == 0){ - iy += animation_height; - } else { - if (!repeat_animation){ - stop_animation = 1; - } else { - iy = animation_y_origin; - // try again - if (draw_bmp(&bmp_info, iy, animation_y, animation_x, - animation_width, animation_height) == 0) - iy += animation_height; - } - } - } + if (stop) + return; + + if (draw_bmp(&bmp_info, *iy, animation_y, animation_x, + animation_width, animation_height) == 0){ + *iy += animation_height; + } else { + /* It failed to draw. */ + + if (!repeat_animation){ + stop = 1; + } else { + // re-start from the origin + *iy = animation_y_origin; + // try again + if (draw_bmp(&bmp_info, *iy, animation_y, animation_x, + animation_width, animation_height) == 0) + *iy += animation_height; + } + } +} + + +static void +update_progress_bar (void) +{ + static int progress; + + // get the progress of boot + if (!getenv_int("boot_progress", &progress)) + progress = 100; // abort bootsplash + + if (progress >= 100 /* boot has finished */){ + // terminate boot splash + bsplash_exit(); + kthread_exit(); + } + + // update the progress bar + draw_bmp(&bmp_info, progress_bar_y_origin + ((progress / 10) * progress_bar_height), + progress_bar_y, progress_bar_x, progress_bar_width, progress_bar_height); +} - // get the progress of boot - if ((s = getenv("BOOT_PROGRESS")) != NULL){ - progress = strtol(s, NULL, 10); - freeenv(s); - } - // update the progress bar - draw_bmp(&bmp_info, progress_bar_y_origin + ((progress / 10) * progress_bar_height), - progress_bar_y, progress_bar_x, progress_bar_width, progress_bar_height); +static void +update_animation_thread(void *unused) +{ + static int count = 0; + static int iy; + + iy = animation_y_origin; + for (;;){ + if (!in_prompt){ + update_animation(&iy); + update_progress_bar(); + count++; - if (progress >= 100 /* boot has finished */ || count > 50 /* FIX 50 /* boot takes too long times */){ + // terminate boot splash bsplash_exit(); kthread_exit(); } } - count++; - pause("bsplash", 3*hz /* FIXME: this is because draw_bmp() takes too long time */); + + pause("bsplash", 3 * hz); } } @@ -336,6 +367,8 @@ static int draw_bmp(BMP_INFO *bmp, int iy, int sy, int sx, int width, int height) { + if (adp == NULL) + return 1; if (bmp_draw(adp, bmp, iy, sy, sx, width, height) != 0) return 1; From owner-svn-soc-all@FreeBSD.ORG Sat Aug 16 13:11:23 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D862A2DA for ; Sat, 16 Aug 2014 13:11:23 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A9F2B29BC for ; Sat, 16 Aug 2014 13:11:23 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7GDBNxL020666 for ; Sat, 16 Aug 2014 13:11:23 GMT (envelope-from shonali@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7GDBM3p020403 for svn-soc-all@FreeBSD.org; Sat, 16 Aug 2014 13:11:22 GMT (envelope-from shonali@FreeBSD.org) Date: Sat, 16 Aug 2014 13:11:22 GMT Message-Id: <201408161311.s7GDBM3p020403@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to shonali@FreeBSD.org using -f From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272495 - soc2014/shonali/head/contrib/bsnmp/snmpd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 16 Aug 2014 13:11:23 -0000 Author: shonali Date: Sat Aug 16 13:11:22 2014 New Revision: 272495 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272495 Log: Fixes for compile warnings Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/main.c soc2014/shonali/head/contrib/bsnmp/snmpd/snmpmod.h soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/main.c ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/main.c Sat Aug 16 12:59:47 2014 (r272494) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/main.c Sat Aug 16 13:11:22 2014 (r272495) @@ -372,7 +372,7 @@ * on the user credentials against the configured User groups & VACM views. */ enum snmp_code -snmp_pdu_auth_access(struct snmp_pdu *pdu, int8_t *ip) +snmp_pdu_auth_access(struct snmp_pdu *pdu, int32_t *ip) { const char *uname; int32_t suboid, smodel; Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/snmpmod.h ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/snmpmod.h Sat Aug 16 12:59:47 2014 (r272494) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/snmpmod.h Sat Aug 16 13:11:22 2014 (r272495) @@ -599,7 +599,7 @@ void snmp_output(struct snmp_pdu *, u_char *, size_t *, const char *); void snmp_send_port(void *, const struct asn_oid *, struct snmp_pdu *, const struct sockaddr *, socklen_t); -enum snmp_code snmp_pdu_auth_access(struct snmp_pdu *, int8_t *); +enum snmp_code snmp_pdu_auth_access(struct snmp_pdu *, int32_t *); /* sending traps */ void snmp_send_trap(const struct asn_oid *, ...); Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c Sat Aug 16 12:59:47 2014 (r272494) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c Sat Aug 16 13:11:22 2014 (r272495) @@ -126,7 +126,7 @@ break; default: - return (NULL); + return (SNMP_ERR_WRONG_LENGTH); } if (tdep->set & TDEP_VERSION) @@ -622,7 +622,7 @@ char *tag; size_t sndlen; ssize_t len; - int8_t ip[16]; + int32_t ip[4]; TAILQ_FOREACH(t, &trapsink_list, link) { if (t->status != TRAPSINK_ACTIVE) @@ -858,7 +858,7 @@ break; default: - return (NULL); + return (SNMP_ERR_BADVALUE); }