comparison src/context.cpp @ 392:ea458101de9b

start parsing spf txt records
author Carl Byington <carl@five-ten-sg.com>
date Mon, 06 Mar 2017 18:06:24 -0800
parents 88ef2b4e6f1e
children dffedbdc8566
comparison
equal deleted inserted replaced
391:88ef2b4e6f1e 392:ea458101de9b
1123 } 1123 }
1124 1124
1125 1125
1126 bool CONTEXT::resolve_spf(const char *from, uint32_t ip, mlfiPriv *priv, int level) 1126 bool CONTEXT::resolve_spf(const char *from, uint32_t ip, mlfiPriv *priv, int level)
1127 { 1127 {
1128 ip = ntohl(ip);
1128 char buf[maxlen]; 1129 char buf[maxlen];
1129 log(priv->queueid, "looking for %s txt record", from); 1130 log(priv->queueid, "looking for %s txt record", from);
1130 dns_interface(*priv, from, ns_t_txt, false, NULL, buf, maxlen); 1131 dns_interface(*priv, from, ns_t_txt, false, NULL, buf, maxlen);
1131 if (*buf) { 1132 if (*buf) {
1132 log(priv->queueid, "found txt record %s", buf); 1133 log(priv->queueid, "found txt record %s", buf);
1138 if (b) *b = '\0'; 1139 if (b) *b = '\0';
1139 char *s = strchr(p, '/'); 1140 char *s = strchr(p, '/');
1140 if (s) *s = '\0'; 1141 if (s) *s = '\0';
1141 in_addr ipx; 1142 in_addr ipx;
1142 if (inet_aton(p, &ipx)) { 1143 if (inet_aton(p, &ipx)) {
1143 uint32_t ipy = htonl(ipx.s_addr); 1144 uint32_t ipy = ntohl(ipx.s_addr);
1144 int mask = (s) ? atoi(s+1) : 32; 1145 int mask = (s) ? atoi(s+1) : 32;
1145 if ((mask >= 16) && (mask <= 32)) { 1146 if ((mask >= 16) && (mask <= 32)) {
1146 uint32_t low = (1 << (32-mask)) - 1; 1147 uint32_t low = (1 << (32-mask)) - 1;
1147 ipy &= low ^ 0xffffffff; 1148 ipy &= low ^ 0xffffffff;
1148 if ((ipy <= ip) && (ip <= ipy + low)) { 1149 if ((ipy <= ip) && (ip <= ipy + low)) {