View | Details | Raw Unified | Return to bug 38554 | Differences between
and this patch

Collapse All | Expand All

(-)/home/bms/fp4/nethead/sys/netinet/in.c (+5 lines)
Lines 459-464 Link Here
459
		 * a routing process they will come back.
459
		 * a routing process they will come back.
460
		 */
460
		 */
461
		in_ifadown(&ia->ia_ifa, 1);
461
		in_ifadown(&ia->ia_ifa, 1);
462
		/*
463
		 * Mark the interface address as no longer valid.
464
		 * Sockets that are bound to it should notice.
465
		 */
466
		ia->ia_ifa.ifa_flags |= RTF_REJECT;
462
		EVENTHANDLER_INVOKE(ifaddr_event, ifp);
467
		EVENTHANDLER_INVOKE(ifaddr_event, ifp);
463
		error = 0;
468
		error = 0;
464
		break;
469
		break;
(-)/home/bms/fp4/nethead/sys/netinet/in_pcb.c (-8 / +26 lines)
Lines 238-251 Link Here
238
	anonport = inp->inp_lport == 0 && (nam == NULL ||
238
	anonport = inp->inp_lport == 0 && (nam == NULL ||
239
	    ((struct sockaddr_in *)nam)->sin_port == 0);
239
	    ((struct sockaddr_in *)nam)->sin_port == 0);
240
	error = in_pcbbind_setup(inp, nam, &inp->inp_laddr.s_addr,
240
	error = in_pcbbind_setup(inp, nam, &inp->inp_laddr.s_addr,
241
	    &inp->inp_lport, cred);
241
	    &inp->inp_lport, &inp->inp_locia, cred);
242
	if (error)
242
	if (error)
243
		return (error);
243
		return (error);
244
	if (in_pcbinshash(inp) != 0) {
244
	if (in_pcbinshash(inp) != 0) {
245
		inp->inp_laddr.s_addr = INADDR_ANY;
245
		inp->inp_laddr.s_addr = INADDR_ANY;
246
		inp->inp_lport = 0;
246
		inp->inp_lport = 0;
247
		inp->inp_locia = NULL;
247
		return (EAGAIN);
248
		return (EAGAIN);
248
	}
249
	}
250
	if (inp->inp_locia != NULL)
251
		IFAREF(&inp->inp_locia->ia_ifa);
249
	if (anonport)
252
	if (anonport)
250
		inp->inp_flags |= INP_ANONPORT;
253
		inp->inp_flags |= INP_ANONPORT;
251
	return (0);
254
	return (0);
Lines 262-273 Link Here
262
 */
265
 */
263
int
266
int
264
in_pcbbind_setup(struct inpcb *inp, struct sockaddr *nam, in_addr_t *laddrp,
267
in_pcbbind_setup(struct inpcb *inp, struct sockaddr *nam, in_addr_t *laddrp,
265
    u_short *lportp, struct ucred *cred)
268
    u_short *lportp, struct in_ifaddr **iap, struct ucred *cred)
266
{
269
{
267
	struct socket *so = inp->inp_socket;
270
	struct socket *so = inp->inp_socket;
268
	unsigned short *lastport;
271
	unsigned short *lastport;
269
	struct sockaddr_in *sin;
272
	struct sockaddr_in *sin;
270
	struct inpcbinfo *pcbinfo = inp->inp_pcbinfo;
273
	struct inpcbinfo *pcbinfo = inp->inp_pcbinfo;
274
	struct in_ifaddr *ia = NULL;
271
	struct in_addr laddr;
275
	struct in_addr laddr;
272
	u_short lport = 0;
276
	u_short lport = 0;
273
	int wild = 0, reuseport = (so->so_options & SO_REUSEPORT);
277
	int wild = 0, reuseport = (so->so_options & SO_REUSEPORT);
Lines 319-325 Link Here
319
		} else if (sin->sin_addr.s_addr != INADDR_ANY) {
323
		} else if (sin->sin_addr.s_addr != INADDR_ANY) {
320
			sin->sin_port = 0;		/* yech... */
324
			sin->sin_port = 0;		/* yech... */
321
			bzero(&sin->sin_zero, sizeof(sin->sin_zero));
325
			bzero(&sin->sin_zero, sizeof(sin->sin_zero));
322
			if (ifa_ifwithaddr((struct sockaddr *)sin) == 0)
326
			if ((ia = (struct in_ifaddr *)ifa_ifwithaddr(
327
			    (struct sockaddr *)sin)) == 0)
323
				return (EADDRNOTAVAIL);
328
				return (EADDRNOTAVAIL);
324
		}
329
		}
325
		laddr = sin->sin_addr;
330
		laddr = sin->sin_addr;
Lines 478-483 Link Here
478
		return (EINVAL);
483
		return (EINVAL);
479
	*laddrp = laddr.s_addr;
484
	*laddrp = laddr.s_addr;
480
	*lportp = lport;
485
	*lportp = lport;
486
	if (iap != NULL)
487
		*iap = ia;
481
	return (0);
488
	return (0);
482
}
489
}
483
490
Lines 490-495 Link Here
490
int
497
int
491
in_pcbconnect(struct inpcb *inp, struct sockaddr *nam, struct ucred *cred)
498
in_pcbconnect(struct inpcb *inp, struct sockaddr *nam, struct ucred *cred)
492
{
499
{
500
	struct in_ifaddr *locia;
493
	u_short lport, fport;
501
	u_short lport, fport;
494
	in_addr_t laddr, faddr;
502
	in_addr_t laddr, faddr;
495
	int anonport, error;
503
	int anonport, error;
Lines 501-507 Link Here
501
	laddr = inp->inp_laddr.s_addr;
509
	laddr = inp->inp_laddr.s_addr;
502
	anonport = (lport == 0);
510
	anonport = (lport == 0);
503
	error = in_pcbconnect_setup(inp, nam, &laddr, &lport, &faddr, &fport,
511
	error = in_pcbconnect_setup(inp, nam, &laddr, &lport, &faddr, &fport,
504
	    NULL, cred);
512
	    NULL, &locia, cred);
505
	if (error)
513
	if (error)
506
		return (error);
514
		return (error);
507
515
Lines 519-524 Link Here
519
	/* Commit the remaining changes. */
527
	/* Commit the remaining changes. */
520
	inp->inp_lport = lport;
528
	inp->inp_lport = lport;
521
	inp->inp_laddr.s_addr = laddr;
529
	inp->inp_laddr.s_addr = laddr;
530
	inp->inp_locia = locia;
531
	if (inp->inp_locia != NULL)
532
		IFAREF(&inp->inp_locia->ia_ifa);
522
	inp->inp_faddr.s_addr = faddr;
533
	inp->inp_faddr.s_addr = faddr;
523
	inp->inp_fport = fport;
534
	inp->inp_fport = fport;
524
	in_pcbrehash(inp);
535
	in_pcbrehash(inp);
Lines 536-542 Link Here
536
 * On entry, *laddrp and *lportp should contain the current local
547
 * On entry, *laddrp and *lportp should contain the current local
537
 * address and port for the PCB; these are updated to the values
548
 * address and port for the PCB; these are updated to the values
538
 * that should be placed in inp_laddr and inp_lport to complete
549
 * that should be placed in inp_laddr and inp_lport to complete
539
 * the connect.
550
 * the connect. If iap is not NULL, *iap is set to the interface
551
 * address corresponding to *laddrp, if any, but no new reference
552
 * to it has been added.
540
 *
553
 *
541
 * On success, *faddrp and *fportp will be set to the remote address
554
 * On success, *faddrp and *fportp will be set to the remote address
542
 * and port. These are not updated in the error case.
555
 * and port. These are not updated in the error case.
Lines 549-555 Link Here
549
int
562
int
550
in_pcbconnect_setup(struct inpcb *inp, struct sockaddr *nam,
563
in_pcbconnect_setup(struct inpcb *inp, struct sockaddr *nam,
551
    in_addr_t *laddrp, u_short *lportp, in_addr_t *faddrp, u_short *fportp,
564
    in_addr_t *laddrp, u_short *lportp, in_addr_t *faddrp, u_short *fportp,
552
    struct inpcb **oinpp, struct ucred *cred)
565
    struct inpcb **oinpp, struct in_ifaddr **iap, struct ucred *cred)
553
{
566
{
554
	struct sockaddr_in *sin = (struct sockaddr_in *)nam;
567
	struct sockaddr_in *sin = (struct sockaddr_in *)nam;
555
	struct in_ifaddr *ia;
568
	struct in_ifaddr *ia;
Lines 560-565 Link Here
560
	u_short lport, fport;
573
	u_short lport, fport;
561
	int error;
574
	int error;
562
575
576
	ia = NULL;
563
	INP_INFO_WLOCK_ASSERT(inp->inp_pcbinfo);
577
	INP_INFO_WLOCK_ASSERT(inp->inp_pcbinfo);
564
	INP_LOCK_ASSERT(inp);
578
	INP_LOCK_ASSERT(inp);
565
579
Lines 582-588 Link Here
582
		sa.sin_len = sizeof(sa);
596
		sa.sin_len = sizeof(sa);
583
		sa.sin_family = AF_INET;
597
		sa.sin_family = AF_INET;
584
		error = in_pcbbind_setup(inp, (struct sockaddr *)&sa,
598
		error = in_pcbbind_setup(inp, (struct sockaddr *)&sa,
585
		    &laddr.s_addr, &lport, cred);
599
		    &laddr.s_addr, &lport, &ia, cred);
586
		if (error)
600
		if (error)
587
			return (error);
601
			return (error);
588
	}
602
	}
Lines 664-670 Link Here
664
	}
678
	}
665
	if (lport == 0) {
679
	if (lport == 0) {
666
		error = in_pcbbind_setup(inp, NULL, &laddr.s_addr, &lport,
680
		error = in_pcbbind_setup(inp, NULL, &laddr.s_addr, &lport,
667
		    cred);
681
		    &ia, cred);
668
		if (error)
682
		if (error)
669
			return (error);
683
			return (error);
670
	}
684
	}
Lines 672-677 Link Here
672
	*lportp = lport;
686
	*lportp = lport;
673
	*faddrp = faddr.s_addr;
687
	*faddrp = faddr.s_addr;
674
	*fportp = fport;
688
	*fportp = fport;
689
	if (iap != NULL)
690
		*iap = ia;
675
	return (0);
691
	return (0);
676
}
692
}
677
693
Lines 720-725 Link Here
720
#endif /*IPSEC*/
736
#endif /*IPSEC*/
721
	inp->inp_gencnt = ++ipi->ipi_gencnt;
737
	inp->inp_gencnt = ++ipi->ipi_gencnt;
722
	in_pcbremlists(inp);
738
	in_pcbremlists(inp);
739
	if (inp->inp_locia != NULL)
740
		IFAFREE(&inp->inp_locia->ia_ifa);
723
	if (inp->inp_options)
741
	if (inp->inp_options)
724
		(void)m_free(inp->inp_options);
742
		(void)m_free(inp->inp_options);
725
	ip_freemoptions(inp->inp_moptions);
743
	ip_freemoptions(inp->inp_moptions);
(-)/home/bms/fp4/nethead/sys/netinet/in_pcb.h (-2 / +7 lines)
Lines 71-76 Link Here
71
struct in_endpoints {
71
struct in_endpoints {
72
	u_int16_t	ie_fport;		/* foreign port */
72
	u_int16_t	ie_fport;		/* foreign port */
73
	u_int16_t	ie_lport;		/* local port */
73
	u_int16_t	ie_lport;		/* local port */
74
	struct in_ifaddr *ie_locia;		/* locally bound address */
74
	/* protocol dependent part, local and foreign addr */
75
	/* protocol dependent part, local and foreign addr */
75
	union {
76
	union {
76
		/* foreign host table entry */
77
		/* foreign host table entry */
Lines 102-107 Link Here
102
#define inc_isipv6	inc_flags	/* temp compatability */
103
#define inc_isipv6	inc_flags	/* temp compatability */
103
#define	inc_fport	inc_ie.ie_fport
104
#define	inc_fport	inc_ie.ie_fport
104
#define	inc_lport	inc_ie.ie_lport
105
#define	inc_lport	inc_ie.ie_lport
106
#define	inc_locia	inc_ie.ie_locia
105
#define	inc_faddr	inc_ie.ie_faddr
107
#define	inc_faddr	inc_ie.ie_faddr
106
#define	inc_laddr	inc_ie.ie_laddr
108
#define	inc_laddr	inc_ie.ie_laddr
107
#define	inc6_faddr	inc_ie.ie6_faddr
109
#define	inc6_faddr	inc_ie.ie6_faddr
Lines 145-150 Link Here
145
	} inp_depend4;
147
	} inp_depend4;
146
#define	inp_fport	inp_inc.inc_fport
148
#define	inp_fport	inp_inc.inc_fport
147
#define	inp_lport	inp_inc.inc_lport
149
#define	inp_lport	inp_inc.inc_lport
150
#define	inp_locia	inp_inc.inc_locia
148
#define	inp_faddr	inp_inc.inc_faddr
151
#define	inp_faddr	inp_inc.inc_faddr
149
#define	inp_laddr	inp_inc.inc_laddr
152
#define	inp_laddr	inp_inc.inc_laddr
150
#define	inp_ip_tos	inp_depend4.inp4_ip_tos
153
#define	inp_ip_tos	inp_depend4.inp4_ip_tos
Lines 332-337 Link Here
332
#define	INP_CHECK_SOCKAF(so, af)	(INP_SOCKAF(so) == af)
335
#define	INP_CHECK_SOCKAF(so, af)	(INP_SOCKAF(so) == af)
333
336
334
#ifdef _KERNEL
337
#ifdef _KERNEL
338
struct in_ifaddr;
339
335
extern int	ipport_reservedhigh;
340
extern int	ipport_reservedhigh;
336
extern int	ipport_reservedlow;
341
extern int	ipport_reservedlow;
337
extern int	ipport_lowfirstauto;
342
extern int	ipport_lowfirstauto;
Lines 346-356 Link Here
346
int	in_pcballoc(struct socket *, struct inpcbinfo *);
351
int	in_pcballoc(struct socket *, struct inpcbinfo *);
347
int	in_pcbbind(struct inpcb *, struct sockaddr *, struct ucred *);
352
int	in_pcbbind(struct inpcb *, struct sockaddr *, struct ucred *);
348
int	in_pcbbind_setup(struct inpcb *, struct sockaddr *, in_addr_t *,
353
int	in_pcbbind_setup(struct inpcb *, struct sockaddr *, in_addr_t *,
349
	    u_short *, struct ucred *);
354
	    u_short *, struct in_ifaddr **, struct ucred *);
350
int	in_pcbconnect(struct inpcb *, struct sockaddr *, struct ucred *);
355
int	in_pcbconnect(struct inpcb *, struct sockaddr *, struct ucred *);
351
int	in_pcbconnect_setup(struct inpcb *, struct sockaddr *, in_addr_t *,
356
int	in_pcbconnect_setup(struct inpcb *, struct sockaddr *, in_addr_t *,
352
	    u_short *, in_addr_t *, u_short *, struct inpcb **,
357
	    u_short *, in_addr_t *, u_short *, struct inpcb **,
353
	    struct ucred *);
358
	    struct in_ifaddr **, struct ucred *);
354
void	in_pcbdetach(struct inpcb *);
359
void	in_pcbdetach(struct inpcb *);
355
void	in_pcbdisconnect(struct inpcb *);
360
void	in_pcbdisconnect(struct inpcb *);
356
void	in_pcbdrop(struct inpcb *);
361
void	in_pcbdrop(struct inpcb *);
(-)/home/bms/fp4/nethead/sys/netinet/tcp_output.c (+13 lines)
Lines 51-62 Link Here
51
#include <sys/sysctl.h>
51
#include <sys/sysctl.h>
52
52
53
#include <net/route.h>
53
#include <net/route.h>
54
#include <net/if.h>
55
#include <net/if_var.h>
54
56
55
#include <netinet/in.h>
57
#include <netinet/in.h>
56
#include <netinet/in_systm.h>
58
#include <netinet/in_systm.h>
57
#include <netinet/ip.h>
59
#include <netinet/ip.h>
58
#include <netinet/in_pcb.h>
60
#include <netinet/in_pcb.h>
59
#include <netinet/ip_var.h>
61
#include <netinet/ip_var.h>
62
#include <netinet/in_var.h>
60
#include <netinet/ip_options.h>
63
#include <netinet/ip_options.h>
61
#ifdef INET6
64
#ifdef INET6
62
#include <netinet6/in6_pcb.h>
65
#include <netinet6/in6_pcb.h>
Lines 872-877 Link Here
872
		ipov = (struct ipovly *)ip;
875
		ipov = (struct ipovly *)ip;
873
		th = (struct tcphdr *)(ip + 1);
876
		th = (struct tcphdr *)(ip + 1);
874
		tcpip_fillheaders(tp->t_inpcb, ip, th);
877
		tcpip_fillheaders(tp->t_inpcb, ip, th);
878
	}
879
880
	/*
881
	 * Check that our local (source) IP address is still valid.
882
	 */
883
	if (tp->t_inpcb->inp_locia != NULL
884
	    && (tp->t_inpcb->inp_locia->ia_ifa.ifa_flags & RTF_REJECT) != 0) {
885
		error = EADDRNOTAVAIL;
886
		m_freem(m);
887
		goto out;
875
	}
888
	}
876
889
877
	/*
890
	/*
(-)/home/bms/fp4/nethead/sys/netinet/tcp_usrreq.c (-1 / +9 lines)
Lines 1102-1107 Link Here
1102
{
1102
{
1103
	struct inpcb *inp = tp->t_inpcb, *oinp;
1103
	struct inpcb *inp = tp->t_inpcb, *oinp;
1104
	struct socket *so = inp->inp_socket;
1104
	struct socket *so = inp->inp_socket;
1105
	struct in_ifaddr *locia;
1105
	struct in_addr laddr;
1106
	struct in_addr laddr;
1106
	u_short lport;
1107
	u_short lport;
1107
	int error;
1108
	int error;
Lines 1122-1134 Link Here
1122
	 */
1123
	 */
1123
	laddr = inp->inp_laddr;
1124
	laddr = inp->inp_laddr;
1124
	lport = inp->inp_lport;
1125
	lport = inp->inp_lport;
1126
	locia = inp->inp_locia;
1125
	error = in_pcbconnect_setup(inp, nam, &laddr.s_addr, &lport,
1127
	error = in_pcbconnect_setup(inp, nam, &laddr.s_addr, &lport,
1126
	    &inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, td->td_ucred);
1128
	    &inp->inp_faddr.s_addr, &inp->inp_fport, &oinp, &locia,
1129
	    td->td_ucred);
1127
	if (error && oinp == NULL)
1130
	if (error && oinp == NULL)
1128
		return error;
1131
		return error;
1129
	if (oinp)
1132
	if (oinp)
1130
		return EADDRINUSE;
1133
		return EADDRINUSE;
1131
	inp->inp_laddr = laddr;
1134
	inp->inp_laddr = laddr;
1135
	if (inp->inp_locia != NULL)
1136
		IFAFREE(&inp->inp_locia->ia_ifa);
1137
	inp->inp_locia = locia;
1138
	if (inp->inp_locia != NULL)
1139
		IFAREF(&inp->inp_locia->ia_ifa);
1132
	in_pcbrehash(inp);
1140
	in_pcbrehash(inp);
1133
1141
1134
	/* Compute window scaling to request.  */
1142
	/* Compute window scaling to request.  */
(-)/home/bms/fp4/nethead/sys/netinet/udp_usrreq.c (-2 / +16 lines)
Lines 724-729 Link Here
724
{
724
{
725
	register struct udpiphdr *ui;
725
	register struct udpiphdr *ui;
726
	register int len = m->m_pkthdr.len;
726
	register int len = m->m_pkthdr.len;
727
	struct in_ifaddr *locia;
727
	struct in_addr faddr, laddr;
728
	struct in_addr faddr, laddr;
728
	struct cmsghdr *cm;
729
	struct cmsghdr *cm;
729
	struct sockaddr_in *sin, src;
730
	struct sockaddr_in *sin, src;
Lines 809-821 Link Here
809
810
810
	laddr = inp->inp_laddr;
811
	laddr = inp->inp_laddr;
811
	lport = inp->inp_lport;
812
	lport = inp->inp_lport;
813
	locia = inp->inp_locia;
812
	if (src.sin_addr.s_addr != INADDR_ANY) {
814
	if (src.sin_addr.s_addr != INADDR_ANY) {
813
		if (lport == 0) {
815
		if (lport == 0) {
814
			error = EINVAL;
816
			error = EINVAL;
815
			goto release;
817
			goto release;
816
		}
818
		}
817
		error = in_pcbbind_setup(inp, (struct sockaddr *)&src,
819
		error = in_pcbbind_setup(inp, (struct sockaddr *)&src,
818
		    &laddr.s_addr, &lport, td->td_ucred);
820
		    &laddr.s_addr, &lport, &locia, td->td_ucred);
819
		if (error)
821
		if (error)
820
			goto release;
822
			goto release;
821
	}
823
	}
Lines 829-835 Link Here
829
			goto release;
831
			goto release;
830
		}
832
		}
831
		error = in_pcbconnect_setup(inp, addr, &laddr.s_addr, &lport,
833
		error = in_pcbconnect_setup(inp, addr, &laddr.s_addr, &lport,
832
		    &faddr.s_addr, &fport, NULL, td->td_ucred);
834
		    &faddr.s_addr, &fport, NULL, &locia, td->td_ucred);
833
		if (error)
835
		if (error)
834
			goto release;
836
			goto release;
835
837
Lines 859-864 Link Here
859
	}
861
	}
860
862
861
	/*
863
	/*
864
	 * Check that the local (source) IP address is valid.
865
	 */
866
	if (locia != NULL && (locia->ia_ifa.ifa_flags & RTF_REJECT) != 0) {
867
		error = EADDRNOTAVAIL;
868
		goto release;
869
	}
870
871
	/*
862
	 * Calculate data length and get a mbuf for UDP, IP, and possible
872
	 * Calculate data length and get a mbuf for UDP, IP, and possible
863
	 * link-layer headers.  Immediate slide the data pointer back forward
873
	 * link-layer headers.  Immediate slide the data pointer back forward
864
	 * since we won't use that space at this layer.
874
	 * since we won't use that space at this layer.
Lines 1088-1093 Link Here
1088
1098
1089
	in_pcbdisconnect(inp);
1099
	in_pcbdisconnect(inp);
1090
	inp->inp_laddr.s_addr = INADDR_ANY;
1100
	inp->inp_laddr.s_addr = INADDR_ANY;
1101
	if (inp->inp_locia != NULL) {
1102
		IFAFREE(&inp->inp_locia->ia_ifa);
1103
		inp->inp_locia = NULL;
1104
	}
1091
	SOCK_LOCK(so);
1105
	SOCK_LOCK(so);
1092
	so->so_state &= ~SS_ISCONNECTED;		/* XXX */
1106
	so->so_state &= ~SS_ISCONNECTED;		/* XXX */
1093
	SOCK_UNLOCK(so);
1107
	SOCK_UNLOCK(so);

Return to bug 38554