/* * Get NFS server address. */ static int __init root_nfs_addr(void) { if ((servaddr = root_server_addr) == INADDR_NONE) { printk(KERN_ERR "Root-NFS: No NFS server available, giving up.\n"); return -1; } snprintf(nfs_data.hostname, sizeof(nfs_data.hostname), "%u.%u.%u.%u", NIPQUAD(servaddr)); return 0; }
/* Try to route the packet according to the routing keys specified in * route_info. Keys are : * - ifindex : * 0 if no oif preferred, * otherwise set to the index of the desired oif * - route_info->gw : * 0 if no gateway specified, * otherwise set to the next host to which the pkt must be routed * If success, skb->dev is the output device to which the packet must * be sent and skb->dst is not NULL * * RETURN: -1 if an error occured * 1 if the packet was succesfully routed to the * destination desired * 0 if the kernel routing table could not route the packet * according to the keys specified */ static int route(struct sk_buff *skb, unsigned int ifindex, const struct ipt_route_target_info *route_info) { int err; struct rtable *rt; struct iphdr *iph =ip_hdr(skb); struct flowi fl = { .oif = ifindex, .nl_u = { .ip4_u = { .daddr = iph->daddr, .saddr = 0, .tos = RT_TOS(iph->tos), .scope = RT_SCOPE_UNIVERSE, } } }; /* The destination address may be overloaded by the target */ if (route_info->gw) fl.fl4_dst = route_info->gw; /* Trying to route the packet using the standard routing table. */ // if ((err = ip_route_output_key(dev_net(dev),,&rt, &fl))) { if ((err = ip_route_output_key(&init_net,&rt, &fl))) { if (net_ratelimit()) DEBUGP("ipt_ROUTE: couldn't route pkt (err: %i)",err); return -1; } /* Drop old route. */ dst_release(skb->dst); skb->dst = NULL; /* Success if no oif specified or if the oif correspond to the * one desired */ if (!ifindex || rt->u.dst.dev->ifindex == ifindex) { skb->dst = &rt->u.dst; skb->dev = skb->dst->dev; skb->protocol = htons(ETH_P_IP); return 1; } /* The interface selected by the routing table is not the one * specified by the user. This may happen because the dst address * is one of our own addresses. */ if (net_ratelimit()) DEBUGP("ipt_ROUTE: failed to route as desired gw=%u.%u.%u.%u oif=%i (got oif=%i)\n", NIPQUAD(route_info->gw), ifindex, rt->u.dst.dev->ifindex); return 0; }
static int rxrpc_call_seq_show(struct seq_file *seq, void *v) { struct rxrpc_transport *trans; struct rxrpc_call *call; char lbuff[4 + 4 + 4 + 4 + 5 + 1], rbuff[4 + 4 + 4 + 4 + 5 + 1]; if (v == &rxrpc_calls) { seq_puts(seq, "Proto Local Remote " " SvID ConnID CallID End Use State Abort " " UserID\n"); return 0; } call = list_entry(v, struct rxrpc_call, link); trans = call->conn->trans; sprintf(lbuff, NIPQUAD_FMT":%u", NIPQUAD(trans->local->srx.transport.sin.sin_addr), ntohs(trans->local->srx.transport.sin.sin_port)); sprintf(rbuff, NIPQUAD_FMT":%u", NIPQUAD(trans->peer->srx.transport.sin.sin_addr), ntohs(trans->peer->srx.transport.sin.sin_port)); seq_printf(seq, "UDP %-22.22s %-22.22s %4x %08x %08x %s %3u" " %-8.8s %08x %lx\n", lbuff, rbuff, ntohs(call->conn->service_id), ntohl(call->conn->cid), ntohl(call->call_id), call->conn->in_clientflag ? "Svc" : "Clt", atomic_read(&call->usage), rxrpc_call_states[call->state], call->abort_code, call->user_call_ID); return 0; }
static int delip_kernel(struct ip_set *set, const struct sk_buff *skb, ip_set_ip_t *hash_ip, const u_int32_t *flags, unsigned char index) { ip_set_ip_t port; if (flags[index+1] == 0) return -EINVAL; port = get_port(skb, flags[index+1]); DP("flag: %s src: %u.%u.%u.%u dst: %u.%u.%u.%u", flags[index] & IPSET_SRC ? "SRC" : "DST", #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) NIPQUAD(ip_hdr(skb)->saddr), NIPQUAD(ip_hdr(skb)->daddr)); #else NIPQUAD(skb->nh.iph->saddr), NIPQUAD(skb->nh.iph->daddr)); #endif DP("flag %s port %u", flags[index+1] & IPSET_SRC ? "SRC" : "DST", port); if (port == INVALID_PORT) return -EINVAL; return __delip(set, ntohl(flags[index] & IPSET_SRC #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) ? ip_hdr(skb)->saddr : ip_hdr(skb)->daddr), #else ? skb->nh.iph->saddr : skb->nh.iph->daddr), #endif port, hash_ip); }
static int nat_t120(struct sk_buff *skb, struct nf_conn *ct, enum ip_conntrack_info ctinfo, unsigned char **data, int dataoff, H245_TransportAddress *taddr, __be16 port, struct nf_conntrack_expect *exp) { int dir = CTINFO2DIR(ctinfo); u_int16_t nated_port = ntohs(port); /* Set expectations for NAT */ exp->saved_proto.tcp.port = exp->tuple.dst.u.tcp.port; exp->expectfn = nf_nat_follow_master; exp->dir = !dir; /* Try to get same port: if not, try to change it. */ for (; nated_port != 0; nated_port++) { exp->tuple.dst.u.tcp.port = htons(nated_port); if (nf_conntrack_expect_related(exp) == 0) break; } if (nated_port == 0) { /* No port available */ if (net_ratelimit()) printk("nf_nat_h323: out of TCP ports\n"); return 0; } /* Modify signal */ if (set_h245_addr(skb, data, dataoff, taddr, &ct->tuplehash[!dir].tuple.dst.u3, htons(nated_port)) < 0) { nf_conntrack_unexpect_related(exp); return -1; } DEBUGP("nf_nat_h323: expect T.120 %u.%u.%u.%u:%hu->%u.%u.%u.%u:%hu\n", NIPQUAD(exp->tuple.src.ip), ntohs(exp->tuple.src.u.tcp.port), NIPQUAD(exp->tuple.dst.ip), ntohs(exp->tuple.dst.u.tcp.port)); return 0; }
/* this is buggered - we need locking for qos_head */ void atm_mpoa_disp_qos(struct seq_file *m) { unsigned char *ip; char ipaddr[16]; struct atm_mpoa_qos *qos; qos = qos_head; seq_printf(m, "QoS entries for shortcuts:\n"); seq_printf(m, "IP address\n TX:max_pcr pcr min_pcr max_cdv max_sdu\n RX:max_pcr pcr min_pcr max_cdv max_sdu\n"); ipaddr[sizeof(ipaddr)-1] = '\0'; while (qos != NULL) { ip = (unsigned char *)&qos->ipaddr; sprintf(ipaddr, "%u.%u.%u.%u", NIPQUAD(ip)); seq_printf(m, "%u.%u.%u.%u\n %-7d %-7d %-7d %-7d %-7d\n %-7d %-7d %-7d %-7d %-7d\n", NIPQUAD(ipaddr), qos->qos.txtp.max_pcr, qos->qos.txtp.pcr, qos->qos.txtp.min_pcr, qos->qos.txtp.max_cdv, qos->qos.txtp.max_sdu, qos->qos.rxtp.max_pcr, qos->qos.rxtp.pcr, qos->qos.rxtp.min_pcr, qos->qos.rxtp.max_cdv, qos->qos.rxtp.max_sdu); qos = qos->next; } }
void rds_connect_complete(struct rds_connection *conn) { if (!rds_conn_transition(conn, RDS_CONN_CONNECTING, RDS_CONN_UP)) { printk(KERN_WARNING "%s: Cannot transition to state UP, " "current state is %d\n", __func__, atomic_read(&conn->c_state)); atomic_set(&conn->c_state, RDS_CONN_ERROR); queue_work(rds_wq, &conn->c_down_w); return; } rdstrace(RDS_CONNECTION, RDS_MINIMAL, "conn %p for %u.%u.%u.%u to %u.%u.%u.%u complete\n", conn, NIPQUAD(conn->c_laddr),NIPQUAD(conn->c_faddr)); conn->c_reconnect_jiffies = 0; set_bit(0, &conn->c_map_queued); queue_delayed_work(rds_wq, &conn->c_send_w, 0); queue_delayed_work(rds_wq, &conn->c_recv_w, 0); }
static bool iprange_mt_v0(const struct sk_buff *skb, const struct xt_match_param *par) { const struct ipt_iprange_info *info = par->matchinfo; const struct iphdr *iph = ip_hdr(skb); if (info->flags & IPRANGE_SRC) { if ((ntohl(iph->saddr) < ntohl(info->src.min_ip) || ntohl(iph->saddr) > ntohl(info->src.max_ip)) ^ !!(info->flags & IPRANGE_SRC_INV)) { pr_debug("src IP %u.%u.%u.%u NOT in range %s" "%u.%u.%u.%u-%u.%u.%u.%u\n", NIPQUAD(iph->saddr), info->flags & IPRANGE_SRC_INV ? "(INV) " : "", NIPQUAD(info->src.min_ip), NIPQUAD(info->src.max_ip)); return false; } } if (info->flags & IPRANGE_DST) { if ((ntohl(iph->daddr) < ntohl(info->dst.min_ip) || ntohl(iph->daddr) > ntohl(info->dst.max_ip)) ^ !!(info->flags & IPRANGE_DST_INV)) { pr_debug("dst IP %u.%u.%u.%u NOT in range %s" "%u.%u.%u.%u-%u.%u.%u.%u\n", NIPQUAD(iph->daddr), info->flags & IPRANGE_DST_INV ? "(INV) " : "", NIPQUAD(info->dst.min_ip), NIPQUAD(info->dst.max_ip)); return false; } } return true; }
static unsigned int mms_nat_expected(struct sk_buff **pskb, unsigned int hooknum, struct ip_conntrack *ct, struct ip_nat_info *info) { struct ip_nat_multi_range mr; u_int32_t newdstip, newsrcip, newip; struct ip_conntrack *master = master_ct(ct); IP_NF_ASSERT(info); IP_NF_ASSERT(master); IP_NF_ASSERT(!(info->initialized & (1 << HOOK2MANIP(hooknum)))); DEBUGP("ip_nat_mms: mms_nat_expected: We have a connection!\n"); newdstip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip; newsrcip = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip; DEBUGP("ip_nat_mms: mms_nat_expected: hook %s: newsrc->newdst %u.%u.%u.%u->%u.%u.%u.%u\n", hooknum == NF_IP_POST_ROUTING ? "POSTROUTING" : hooknum == NF_IP_PRE_ROUTING ? "PREROUTING" : hooknum == NF_IP_LOCAL_OUT ? "OUTPUT" : "???", NIPQUAD(newsrcip), NIPQUAD(newdstip)); if (HOOK2MANIP(hooknum) == IP_NAT_MANIP_SRC) newip = newsrcip; else newip = newdstip; DEBUGP("ip_nat_mms: mms_nat_expected: IP to %u.%u.%u.%u\n", NIPQUAD(newip)); mr.rangesize = 1; /* We don't want to manip the per-protocol, just the IPs. */ mr.range[0].flags = IP_NAT_RANGE_MAP_IPS; mr.range[0].min_ip = mr.range[0].max_ip = newip; return ip_nat_setup_info(ct, &mr, hooknum); }
int cifs_resolve_server_name_to_ip(const char *unc, struct in_addr *ip_addr) { int rc = -EAGAIN; struct key *rkey; char *name; int len; if ((!ip_addr) || (!unc)) { return -EINVAL; } /* search for server name delimiter */ len = strlen( unc); if (len < 3) { cFYI(1, ("%s: unc is too short: %s", __FUNCTION__, unc )); return -EINVAL; } len -= 2; name = memchr(unc+2, '\\', len); if (!name) { cFYI(1, ("%s: probably server name is whole unc: %s", __FUNCTION__, unc )); } else { len = (name - unc) - 2/* leading // */; } name = kmalloc( len+1, GFP_KERNEL); if (name == NULL) { rc = -ENOMEM; return rc; } memcpy( name, unc+2, len); name[len] = 0; rkey = request_key(&key_type_cifs_resolver, name, ""); if (!IS_ERR(rkey)) { ip_addr->s_addr = rkey->payload.value; cFYI(1, ("%s: resolved: %s to %u.%u.%u.%u", __FUNCTION__, rkey->description, NIPQUAD(ip_addr->s_addr) )); key_put(rkey); rc = 0; } else { cERROR(1, ("%s: unable to resolve: %s", __FUNCTION__, name)); } kfree(name); return rc; }
/* get weighted least-connection node in the destination set */ static inline struct ip_vs_dest *ip_vs_dest_set_min(struct ip_vs_dest_set *set) { register struct ip_vs_dest_list *e; struct ip_vs_dest *dest, *least; int loh, doh; if (set == NULL) return NULL; read_lock(&set->lock); /* select the first destination server, whose weight > 0 */ for (e=set->list; e!=NULL; e=e->next) { least = e->dest; if (least->flags & IP_VS_DEST_F_OVERLOAD) continue; if ((atomic_read(&least->weight) > 0) && (least->flags & IP_VS_DEST_F_AVAILABLE)) { loh = atomic_read(&least->activeconns) * 50 + atomic_read(&least->inactconns); goto nextstage; } } read_unlock(&set->lock); return NULL; /* find the destination with the weighted least load */ nextstage: for (e=e->next; e!=NULL; e=e->next) { dest = e->dest; if (dest->flags & IP_VS_DEST_F_OVERLOAD) continue; doh = atomic_read(&dest->activeconns) * 50 + atomic_read(&dest->inactconns); if ((loh * atomic_read(&dest->weight) > doh * atomic_read(&least->weight)) && (dest->flags & IP_VS_DEST_F_AVAILABLE)) { least = dest; loh = doh; } } read_unlock(&set->lock); IP_VS_DBG(6, "ip_vs_dest_set_min: server %d.%d.%d.%d:%d " "activeconns %d refcnt %d weight %d overhead %d\n", NIPQUAD(least->addr), ntohs(least->port), atomic_read(&least->activeconns), atomic_read(&least->refcnt), atomic_read(&least->weight), loh); return least; }
static void ipmr_destroy_unres(struct mfc_cache *c) { struct sk_buff *skb; atomic_dec(&cache_resolve_queue_len); DBPRINT ("ipmr_destroy_unres - group: %u.%u.%u.%u \n", NIPQUAD(c->mfc_mcastgrp)); while((skb=skb_dequeue(&c->mfc_un.unres.unresolved))) { if (skb->nh.iph->version == 0) { struct nlmsghdr *nlh = (struct nlmsghdr *)skb_pull(skb, sizeof(struct iphdr)); nlh->nlmsg_type = NLMSG_ERROR; nlh->nlmsg_len = NLMSG_LENGTH(sizeof(struct nlmsgerr)); skb_trim(skb, nlh->nlmsg_len); ((struct nlmsgerr*)NLMSG_DATA(nlh))->error = -ETIMEDOUT; netlink_unicast(rtnl, skb, NETLINK_CB(skb).dst_pid, MSG_DONTWAIT); } else kfree_skb(skb); } DBPRINT ("ipmr_destroy_unres - calling kmem_cache_free, group: %u.%u.%u.%u \n", NIPQUAD(c->mfc_mcastgrp)); kmem_cache_free(mrt_cachep, c); }
static int gr_log_start(int audit) { char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT; char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt; char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf; if (audit == GR_DO_AUDIT) goto set_fmt; if (!grsec_alert_wtime || jiffies - grsec_alert_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) { grsec_alert_wtime = jiffies; grsec_alert_fyet = 0; } else if ((jiffies - grsec_alert_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) { grsec_alert_fyet++; } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) { grsec_alert_wtime = jiffies; grsec_alert_fyet++; printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME); return FLOODING; } else return FLOODING; set_fmt: memset(buf, 0, PAGE_SIZE); if (current->signal->curr_ip && gr_acl_is_enabled()) { sprintf(fmt, "%s%s", loglevel, "grsec: From %u.%u.%u.%u: (%.64s:%c:%.950s) "); snprintf(buf, PAGE_SIZE - 1, fmt, NIPQUAD(current->signal->curr_ip), current->role->rolename, gr_roletype_to_char(), current->acl->filename); } else if (current->signal->curr_ip) { sprintf(fmt, "%s%s", loglevel, "grsec: From %u.%u.%u.%u: "); snprintf(buf, PAGE_SIZE - 1, fmt, NIPQUAD(current->signal->curr_ip)); } else if (gr_acl_is_enabled()) { sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) "); snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename); } else { sprintf(fmt, "%s%s", loglevel, "grsec: "); strcpy(buf, fmt); } return NO_FLOODING; }
/* Convert an IPv4 subnet to human-readable a.b.c.d/e format. */ static int ipv4_subnet_to_string(char *buffer, int size, const struct ipv4_subnet *net) { int mask_len; if (net->mask == 0) { mask_len = 0; } else { /* count trailing zeroes */ mask_len = 32 - __builtin_ctz(be32_to_cpu(net->mask)); } return snprintf(buffer, size, "%u.%u.%u.%u/%d", NIPQUAD(net->ip), mask_len); }
static void rds_recv_route(struct rds_connection *conn, struct rds_incoming *inc, gfp_t gfp) { struct rds_connection *nconn; struct rds_nf_hdr *dst, *org; /* pull out the rds header */ dst = rds_nf_hdr_dst(inc->i_skb); org = rds_nf_hdr_org(inc->i_skb); /* special case where we are swapping the message back on the same connection */ if (dst->saddr == org->daddr && dst->daddr == org->saddr) { nconn = conn; } else { /* reroute to a new conn structure, possibly the same one */ nconn = rds_conn_find(dst->saddr, dst->daddr, conn->c_trans, conn->c_tos); } /* cannot find a matching connection so drop the request */ if (NULL == nconn) { printk(KERN_ALERT "cannot find matching conn for inc %p, %u.%u.%u.%u -> %u.%u.%u.%u\n", inc, NIPQUAD(dst->saddr), NIPQUAD(dst->daddr)); rdsdebug("cannot find matching conn for inc %p, %u.%u.%u.%u -> %u.%u.%u.%u", inc, NIPQUAD(dst->saddr), NIPQUAD(dst->daddr)); rds_recv_drop(conn, dst->saddr, dst->daddr, inc, gfp); } /* this is a request for our local node, but potentially a different source * either way we process it locally */ else if (conn->c_trans->skb_local(inc->i_skb)) { rds_recv_local(nconn, dst->saddr, dst->daddr, inc, gfp); } /* looks like this request is going out to another node */ else { rds_recv_forward(nconn, inc, gfp); } }
/** Create a socket. * The flags can include values from enum VsockFlag. * * @param socktype socket type * @param saddr address * @param port port * @param flags flags * @param val return value for the socket connection * @return 0 on success, error code otherwise */ int create_socket(int socktype, uint32_t saddr, uint32_t port, int flags, int *val){ int err = 0; int sock; struct sockaddr_in addr_in; struct sockaddr *addr = (struct sockaddr *)&addr_in; int addr_n = sizeof(addr_in); int sockproto = 0; //dprintf(">\n"); addr_in.sin_family = AF_INET; addr_in.sin_addr.s_addr = saddr; addr_in.sin_port = port; dprintf("> flags=%s addr=%u.%u.%u.%u port=%d\n", socket_flags(flags), NIPQUAD(saddr), ntohs(port)); switch(socktype){ case SOCK_DGRAM: sockproto = IPPROTO_UDP; break; case SOCK_STREAM: sockproto = IPPROTO_TCP; break; } sock = socket(AF_INET, socktype, sockproto); if(sock < 0) goto exit; if(flags & VSOCK_REUSE){ err = setsock_reuse(sock, 1); if(err < 0) goto exit; } if(flags & VSOCK_BROADCAST){ err = setsock_broadcast(sock, 1); if(err < 0) goto exit; } if(flags & VSOCK_MULTICAST){ err = setsock_multicast(sock, saddr); if(err < 0) goto exit; } if(flags & VSOCK_CONNECT){ err = connect(sock, addr, addr_n); if(err < 0) goto exit; } if(flags & VSOCK_BIND){ err = bind(sock, addr, addr_n); if(err < 0) goto exit; } if(flags & VSOCK_NONBLOCK){ err = fcntl(sock, F_SETFL, O_NONBLOCK); if(err < 0) goto exit; } exit: *val = (err ? -1 : sock); if(err) eprintf("> err=%d errno=%d\n", err, errno); return err; }
/* * This is the callback from the RPC layer when the NLM_GRANTED_MSG * RPC call has succeeded or timed out. * Like all RPC callbacks, it is invoked by the rpciod process, so it * better not sleep. Therefore, we put the blocked lock on the nlm_blocked * chain once more in order to have it removed by lockd itself (which can * then sleep on the file semaphore without disrupting e.g. the nfs client). */ static void nlmsvc_grant_callback(struct rpc_task *task) { struct nlm_rqst *call = (struct nlm_rqst *) task->tk_calldata; struct nlm_block *block; unsigned long timeout; struct sockaddr_in *peer_addr = RPC_PEERADDR(task->tk_client); dprintk("lockd: GRANT_MSG RPC callback\n"); dprintk("callback: looking for cookie %s, host %u.%u.%u.%u\n", nlmdbg_cookie2a(&call->a_args.cookie), NIPQUAD(peer_addr->sin_addr.s_addr)); if (!(block = nlmsvc_find_block(&call->a_args.cookie, peer_addr))) { dprintk("lockd: no block for cookie %s, host %u.%u.%u.%u\n", nlmdbg_cookie2a(&call->a_args.cookie), NIPQUAD(peer_addr->sin_addr.s_addr)); return; } /* Technically, we should down the file semaphore here. Since we * move the block towards the head of the queue only, no harm * can be done, though. */ if (task->tk_status < 0) { /* RPC error: Re-insert for retransmission */ timeout = 10 * HZ; } else if (block->b_done) { /* Block already removed, kill it for real */ timeout = 0; } else { /* Call was successful, now wait for client callback */ timeout = 60 * HZ; } nlmsvc_insert_block(block, timeout); svc_wake_up(block->b_daemon); block->b_incall = 0; nlm_release_host(call->a_host); }
static struct ip_vs_conn * ah_conn_in_get(const struct sk_buff *skb, struct ip_vs_protocol *pp, const struct iphdr *iph, unsigned int proto_off, int inverse) { struct ip_vs_conn *cp; if (likely(!inverse)) { cp = ip_vs_conn_in_get(IPPROTO_UDP, iph->saddr, htons(PORT_ISAKMP), iph->daddr, htons(PORT_ISAKMP)); } else { cp = ip_vs_conn_in_get(IPPROTO_UDP, iph->daddr, htons(PORT_ISAKMP), iph->saddr, htons(PORT_ISAKMP)); } if (!cp) { /* * We are not sure if the packet is from our * service, so our conn_schedule hook should return NF_ACCEPT */ IP_VS_DBG(12, "Unknown ISAKMP entry for outin packet " "%s%s %u.%u.%u.%u->%u.%u.%u.%u\n", inverse ? "ICMP+" : "", pp->name, NIPQUAD(iph->saddr), NIPQUAD(iph->daddr)); } return cp; }
void rds_connect_worker(struct work_struct *work) { struct rds_connection *conn = container_of(work, struct rds_connection, c_conn_w.work); int ret; clear_bit(RDS_RECONNECT_PENDING, &conn->c_flags); if (rds_conn_transition(conn, RDS_CONN_DOWN, RDS_CONN_CONNECTING)) { ret = conn->c_trans->conn_connect(conn); rdsdebug("connect conn %p for %u.%u.%u.%u -> %u.%u.%u.%u " "ret %d\n", conn, NIPQUAD(conn->c_laddr), NIPQUAD(conn->c_faddr), ret); rdstrace(RDS_CONNECTION, RDS_MINIMAL, "conn %p for %u.%u.%u.%u to %u.%u.%u.%u dispatched, ret %d\n", conn, NIPQUAD(conn->c_laddr), NIPQUAD(conn->c_faddr), ret); if (ret) { if (rds_conn_transition(conn, RDS_CONN_CONNECTING, RDS_CONN_DOWN)) rds_queue_reconnect(conn); else rds_conn_error(conn, "RDS: connect failed\n"); } } }
/* Parses and executes the command using, if necessary, omega_interrupt */ int execute_command2(fd_set *dset) { char command[100]; char cmd; unsigned int gid; int candidate, notif_type; unsigned int TdU, TmU, TmrL; struct omega_proc_struct leader; int retval = 0; scanf("%s", command); switch(command[0]) { case 'b' : scanf("%c", &cmd); retval = omega_unregister(omega_interrupt); if (retval >= 0) { FD_CLR(omega_interrupt, dset); omega_interrupt = 0; } return retval; case 'c' : scanf("%c %u %d %d %u %u %u", &cmd, &gid, &candidate, ¬if_type, &TdU, &TmU, &TmrL); candidate = ((candidate == 1) ? CANDIDATE : NOT_CANDIDATE); notif_type = ((notif_type == 1) ? OMEGA_INTERRUPT_ANY_CHANGE : OMEGA_INTERRUPT_NONE); retval = omega_startOmega(omega_interrupt, gid, candidate, notif_type, TdU, TmU, TmrL); return retval; case 'd' : scanf("%c %u", &cmd, &gid); retval = omega_stopOmega(omega_interrupt, gid); return retval; case 'e' : scanf("%c %u", &cmd, &gid); retval = omega_getleader(omega_interrupt, gid, &leader); if (retval >= 0) printf("Current leader of group: %u is pid: %u address:" " %u.%u.%u.%u\n", leader.gid, leader.pid, NIPQUAD(&leader.addr)); return retval; case 'f' : scanf("%c %u", &cmd, &gid); retval = omega_interrupt_any_change(omega_interrupt, gid); return retval; case 'g' : scanf("%c %u", &cmd, &gid); retval = omega_interrupt_none(omega_interrupt, gid); return retval; case 'h' : exit(0); break; default: return -1; } }
/* * Least Connection scheduling */ static struct ip_vs_dest * ip_vs_lc_schedule(struct ip_vs_service *svc, struct iphdr *iph) { struct list_head *l, *e; struct ip_vs_dest *dest, *least; unsigned int loh, doh; IP_VS_DBG(6, "ip_vs_lc_schedule(): Scheduling...\n"); /* * Simply select the server with the least number of * (activeconns<<5) + inactconns * Except whose weight is equal to zero. * If the weight is equal to zero, it means that the server is * quiesced, the existing connections to the server still get * served, but no new connection is assigned to the server. */ l = &svc->destinations; for (e=l->next; e!=l; e=e->next) { least = list_entry (e, struct ip_vs_dest, n_list); if (atomic_read(&least->weight) > 0) { loh = ip_vs_lc_dest_overhead(least); goto nextstage; } } return NULL; /* * Find the destination with the least load. */ nextstage: for (e=e->next; e!=l; e=e->next) { dest = list_entry(e, struct ip_vs_dest, n_list); if (atomic_read(&dest->weight) == 0) continue; doh = ip_vs_lc_dest_overhead(dest); if (doh < loh) { least = dest; loh = doh; } } IP_VS_DBG(6, "LC: server %u.%u.%u.%u:%u activeconns %d inactconns %d\n", NIPQUAD(least->addr), ntohs(least->port), atomic_read(&least->activeconns), atomic_read(&least->inactconns)); return least; }
static int pptp_proc_read(char *page, char **start, off_t off, int count, int *eof, void *data) { char *out = page; struct list_head *l, *e; struct tuple_table *tt; struct ip_conntrack_tuple *t; int len; out += sprintf (out, "GRE tuple list\n"); l = &gre_list; for (e=l->next; e!=l; e=e->next) { tt = list_entry(e, struct tuple_table, list); t = &tt->tuple; out += sprintf(out, "tuple %p: %u %u.%u.%u.%u CID:%hu -> %u.%u.%u.%u. PCID=%hu, Master=%p\n", t, t->dst.protonum, NIPQUAD(t->src.ip), ntohs(t->src.u.all), NIPQUAD(t->dst.ip), ntohs(t->dst.u.gre.peer_call_id), tt->master); } len = out - page; len -= off; if (len < count) { *eof = 1; if (len <= 0) return 0; } else len = count; *start = page + off; return len; }
void zc_handle(unsigned char *user, const struct pcap_pkthdr *h, const unsigned char *bytes) { struct ether_header *eth; struct iphdr *iph; struct tcphdr *th; const unsigned char *p = bytes; __u16 sport, dport; eth = (struct ether_header*)p; g_count ++; dump_skb("test", bytes, h->caplen); printf("\npacket:%d, snaplen:%d\n", g_count, h->caplen); #if 1 if (eth->ether_type == ntohs(ETHERTYPE_IP)){ iph = (struct iphdr *)(eth + 1); sport = ((__u16 *)(((void *)iph) + (iph->ihl<<2)))[0]; dport = ((__u16 *)(((void *)iph) + (iph->ihl<<2)))[1]; printf("packet length: %d %u.%u.%u.%u -> %u.%u.%u.%u, protocal: l3 %x, l4 %u\n", h->len, NIPQUAD(iph->saddr), NIPQUAD(iph->daddr), ntohs(eth->ether_type), iph->protocol); printf("==================================================================\n"); if(iph->protocol == IPPROTO_TCP) { //printf(" port %u -> %u", ntohs(sport), ntohs(dport)); th = (struct tcphdr *)(((void *)iph) + (iph->ihl<<2)); //printf("seq: %u, ack: %u, ", ntohl(th->seq), ntohl(th->ack_seq)); } if(iph->protocol == IPPROTO_UDP) { //printf(" port %u -> %u", ntohs(sport), ntohs(dport)); } } //printf("\n"); #endif return; }
static int rt_host_route_read_proc(char *buf, char **start, off_t offset, int count, int *eof, void *data) { RTNET_PROC_PRINT_VARS; struct host_route *entry_ptr; struct dest_route dest_host; unsigned int key; unsigned int index; unsigned int i; unsigned long flags; RTNET_PROC_PRINT("Hash\tDestination\tHW Address\t\tDevice\n"); for (key = 0; key < HOST_HASH_TBL_SIZE; key++) { index = 0; while (1) { rtos_spin_lock_irqsave(&host_table_lock, flags); entry_ptr = host_table[key]; for (i = 0; (i < index) && (entry_ptr != NULL); i++) entry_ptr = entry_ptr->next; if (entry_ptr == NULL) { rtos_spin_unlock_irqrestore(&host_table_lock, flags); break; } memcpy(&dest_host, &entry_ptr->dest_host, sizeof(struct dest_route)); rtdev_reference(dest_host.rtdev); rtos_spin_unlock_irqrestore(&host_table_lock, flags); RTNET_PROC_PRINT("%02X\t%u.%u.%u.%-3u\t" "%02X:%02X:%02X:%02X:%02X:%02X\t%s\n", key, NIPQUAD(dest_host.ip), dest_host.dev_addr[0], dest_host.dev_addr[1], dest_host.dev_addr[2], dest_host.dev_addr[3], dest_host.dev_addr[4], dest_host.dev_addr[5], dest_host.rtdev->name); rtdev_dereference(dest_host.rtdev); index++; } } RTNET_PROC_PRINT_DONE; }
int main(int argc,char *argv[]) { struct mrtt_rx_packet rx_packet; int cmd0; struct stats *stats; memset(stations, 0, sizeof(stations)); signal (SIGINT, endme); if ((cmd0 = open("/dev/rtf0", O_RDONLY)) < 0) { if ((cmd0 = open("/dev/rtf/0", O_RDONLY)) < 0) { fprintf(stderr, "Error opening /dev/rtf/0 and /dev/rtf0\n"); exit(1); } } initscr(); /* initialize the curses library */ keypad(stdscr, TRUE); /* enable keyboard mapping */ nonl(); /* tell curses not to do NL->CR/NL on output */ cbreak(); /* take input chars one at a time, no wait for \n */ move(0,0); addstr("Showtime:"); while(!end) { read (cmd0, &rx_packet, sizeof(struct mrtt_rx_packet)); stats = lookup(rx_packet.ip_addr); if (!stats) continue; stats->rtt = (rx_packet.rx - rx_packet.tx)/1000; if (stats->rtt < stats->min) stats->min = stats->rtt; if (stats->rtt > stats->max) stats->max = stats->rtt; stats->count++; move(stats - stations + 1, 0); printw("%u.%u.%u.%u\t%dus, min=%dus, max=%dus, count=%d", NIPQUAD(stats->ip), stats->rtt, stats->min, stats->max, stats->count); refresh(); } close(cmd0); endwin(); return 0; }
static void ingress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc) { __be32 dst_ip = msg->content.in_info.in_dst_ip; __be32 mask = msg->ip_mask; in_cache_entry *entry = mpc->in_ops->get_with_mask(dst_ip, mpc, mask); if(entry == NULL){ printk("mpoa: (%s) ingress_purge_rcvd: purge for a non-existing entry, ", mpc->dev->name); printk("ip = %u.%u.%u.%u\n", NIPQUAD(dst_ip)); return; } do { dprintk("mpoa: (%s) ingress_purge_rcvd: removing an ingress entry, ip = %u.%u.%u.%u\n" , mpc->dev->name, NIPQUAD(dst_ip)); write_lock_bh(&mpc->ingress_lock); mpc->in_ops->remove_entry(entry, mpc); write_unlock_bh(&mpc->ingress_lock); mpc->in_ops->put(entry); entry = mpc->in_ops->get_with_mask(dst_ip, mpc, mask); } while (entry != NULL); return; }
static void addr_map_init(struct nf_conn *ct, struct addr_map *map) { struct nf_conntrack_tuple *t; enum ip_conntrack_dir dir; unsigned int n; for (dir = 0; dir < IP_CT_DIR_MAX; dir++) { t = &ct->tuplehash[dir].tuple; n = sprintf(map->addr[dir].src, "%u.%u.%u.%u", NIPQUAD(t->src.u3.ip)); map->addr[dir].srciplen = n; n += sprintf(map->addr[dir].src + n, ":%u", ntohs(t->src.u.udp.port)); map->addr[dir].srclen = n; n = sprintf(map->addr[dir].dst, "%u.%u.%u.%u", NIPQUAD(t->dst.u3.ip)); map->addr[dir].dstiplen = n; n += sprintf(map->addr[dir].dst + n, ":%u", ntohs(t->dst.u.udp.port)); map->addr[dir].dstlen = n; } }
void send_accusation(struct sockaddr_in *raddr, u_int gid) { char msg[OMEGA_UDP_MSG_LEN], *ptr; int bytes; #ifdef OMEGA_OUTPUT fprintf(stdout, "Sending accusation to: %u.%u.%u.%u for gid: %u\n", NIPQUAD(raddr), gid); #endif #ifdef OMEGA_LOG fprintf(omega_log, "Sending accusation to: %u.%u.%u.%u for gid: %u\n", NIPQUAD(raddr), gid); #endif ptr = msg_omega_build_accusation(msg, gid); (*raddr).sin_family = AF_INET; (*raddr).sin_port = htons(OMEGA_UDP_PORT); bytes = sendto(omega_udp_socket, msg, ptr-msg, 0, (struct sockaddr *) raddr, sizeof(*raddr)); if(bytes < 0) perror("omega: send_accusation(), cannot send data\n"); }
int main(void) { struct sockaddr_in oaddr, saddr; socklen_t len; int fd, clifd; fd = sock_tcpsvr(0, 8000, 0); if (fd < 0) { ERR("create socket error\n"); return -1; } len = sizeof(saddr); while (1) { clifd = accept(fd, (struct sockaddr *)&saddr, &len); if (clifd > 0) { if (nf_origin_dst(clifd, &oaddr)) { ERR("get origin address error\n"); // close(clifd); // break; } printf("client(%d) %u.%u.%u.%u:%u->%u.%u.%u.%u:%u connect\n", clifd, NIPQUAD(saddr.sin_addr), ntohs(saddr.sin_port), NIPQUAD(oaddr.sin_addr), ntohs(oaddr.sin_port)); close(clifd); } else break; } close(fd); return 0; }
bool validate_ipv4_address(const char *ip) { #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) __be32 result_; return (in4_pton(ip, strlen(ip), (__u8 *) &result_, '\0', NULL) == 1); #else char src_ip_[50]; __be32 result_ = in_aton(ip); sprintf(src_ip_, "%d.%d.%d.%d", NIPQUAD(result_)); src_ip_[strlen(ip)] = '\0'; return strcmp(ip, src_ip_) == 0; #endif }