]> err.no Git - linux-2.6/blobdiff - net/core/utils.c
Merge branch 'x86-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6] / net / core / utils.c
index d93fe64f6693b3e23624c27741e1d0ffa167663e..72e0ebe964a08d03be218b8c17aa061818579f2f 100644 (file)
 #include <linux/random.h>
 #include <linux/percpu.h>
 #include <linux/init.h>
+#include <net/sock.h>
 
 #include <asm/byteorder.h>
 #include <asm/system.h>
 #include <asm/uaccess.h>
 
-int net_msg_cost = 5*HZ;
-int net_msg_burst = 10;
+int net_msg_warn __read_mostly = 1;
+EXPORT_SYMBOL(net_msg_warn);
 
-/* 
+DEFINE_RATELIMIT_STATE(net_ratelimit_state, 5 * HZ, 10);
+/*
  * All net warning printk()s should be guarded by this function.
- */ 
+ */
 int net_ratelimit(void)
 {
-       return __printk_ratelimit(net_msg_cost, net_msg_burst);
+       return __ratelimit(&net_ratelimit_state);
 }
 EXPORT_SYMBOL(net_ratelimit);
 
@@ -88,18 +90,7 @@ EXPORT_SYMBOL(in_aton);
 #define IN6PTON_NULL           0x20000000      /* first/tail */
 #define IN6PTON_UNKNOWN                0x40000000
 
-static inline int digit2bin(char c, char delim)
-{
-       if (c == delim || c == '\0')
-               return IN6PTON_DELIM;
-       if (c == '.')
-               return IN6PTON_DOT;
-       if (c >= '0' && c <= '9')
-               return (IN6PTON_DIGIT | (c - '0'));
-       return IN6PTON_UNKNOWN;
-}
-
-static inline int xdigit2bin(char c, char delim)
+static inline int xdigit2bin(char c, int delim)
 {
        if (c == delim || c == '\0')
                return IN6PTON_DELIM;
@@ -113,12 +104,14 @@ static inline int xdigit2bin(char c, char delim)
                return (IN6PTON_XDIGIT | (c - 'a' + 10));
        if (c >= 'A' && c <= 'F')
                return (IN6PTON_XDIGIT | (c - 'A' + 10));
+       if (delim == -1)
+               return IN6PTON_DELIM;
        return IN6PTON_UNKNOWN;
 }
 
 int in4_pton(const char *src, int srclen,
             u8 *dst,
-            char delim, const char **end)
+            int delim, const char **end)
 {
        const char *s;
        u8 *d;
@@ -135,16 +128,16 @@ int in4_pton(const char *src, int srclen,
        while(1) {
                int c;
                c = xdigit2bin(srclen > 0 ? *s : '\0', delim);
-               if (!(c & (IN6PTON_DIGIT | IN6PTON_DOT | IN6PTON_DELIM))) {
+               if (!(c & (IN6PTON_DIGIT | IN6PTON_DOT | IN6PTON_DELIM | IN6PTON_COLON_MASK))) {
                        goto out;
                }
-               if (c & (IN6PTON_DOT | IN6PTON_DELIM)) {
+               if (c & (IN6PTON_DOT | IN6PTON_DELIM | IN6PTON_COLON_MASK)) {
                        if (w == 0)
                                goto out;
                        *d++ = w & 0xff;
                        w = 0;
                        i++;
-                       if (c & IN6PTON_DELIM) {
+                       if (c & (IN6PTON_DELIM | IN6PTON_COLON_MASK)) {
                                if (i != 4)
                                        goto out;
                                break;
@@ -173,7 +166,7 @@ EXPORT_SYMBOL(in4_pton);
 
 int in6_pton(const char *src, int srclen,
             u8 *dst,
-            char delim, const char **end)
+            int delim, const char **end)
 {
        const char *s, *tok = NULL;
        u8 *d, *dc = NULL;
@@ -288,3 +281,19 @@ out:
 }
 
 EXPORT_SYMBOL(in6_pton);
+
+void inet_proto_csum_replace4(__sum16 *sum, struct sk_buff *skb,
+                             __be32 from, __be32 to, int pseudohdr)
+{
+       __be32 diff[] = { ~from, to };
+       if (skb->ip_summed != CHECKSUM_PARTIAL) {
+               *sum = csum_fold(csum_partial(diff, sizeof(diff),
+                               ~csum_unfold(*sum)));
+               if (skb->ip_summed == CHECKSUM_COMPLETE && pseudohdr)
+                       skb->csum = ~csum_partial(diff, sizeof(diff),
+                                               ~skb->csum);
+       } else if (pseudohdr)
+               *sum = ~csum_fold(csum_partial(diff, sizeof(diff),
+                               csum_unfold(*sum)));
+}
+EXPORT_SYMBOL(inet_proto_csum_replace4);